Module: Shippinglogic::Validation

Included in:
Service
Defined in:
lib/shippinglogic/validation.rb

Overview

This module is more for application integration, so you can do something like:

tracking = fedex.tracking
if tracking.valid?
  # render a successful response
else
  # do something with the errors: fedex.errors
end

Instance Method Summary collapse

Instance Method Details

#errorsObject

Just an array of errors that were encounted if valid? returns false.



14
15
16
# File 'lib/shippinglogic/validation.rb', line 14

def errors
  @errors ||= []
end

#valid?Boolean

Allows you to determine if the request is valid or not. All validation is delegated to the API services, so what this does is make a call to the API and rescue any errors, then it puts those errors into the ‘errors’ array.

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
30
# File 'lib/shippinglogic/validation.rb', line 21

def valid?
  begin
    target
    true
  rescue Error => e
    errors.clear
    self.errors << e.message
    false
  end
end