class Fedex::Parcel
Attributes
configuration[RW]
client[RW]
Public Class Methods
assign_tracking_code(tracking_code)
click to toggle source
# File lib/fedex_parcels_tracker.rb, line 56 def self.assign_tracking_code(tracking_code) tracking_in_data = Fedex::Parcel.configuration.tracking_in_data data = Fedex::Parcel.configuration.data data[tracking_in_data.to_sym] = tracking_code data end
body_contents(body)
click to toggle source
# File lib/fedex_parcels_tracker.rb, line 63 def self.body_contents(body) body[(Fedex::Parcel.configuration.method.to_s + '_response').to_sym] end
configure() { |configuration| ... }
click to toggle source
# File lib/fedex_parcels_tracker.rb, line 12 def self.configure self.configuration ||= Configuration.new yield(configuration) end
new()
click to toggle source
# File lib/fedex_parcels_tracker.rb, line 30 def initialize @client = Savon.client( wsdl: Fedex::Parcel.configuration.wsdl, ssl_version: Fedex::Parcel.configuration.ssl_version ) end
track(tracking_code)
click to toggle source
# File lib/fedex_parcels_tracker.rb, line 37 def self.track(tracking_code) raise 'No configuration credentials provided !' if Fedex::Parcel.configuration.blank? raise 'Tracking code cannot be blank' if tracking_code.blank? raise 'Invalid tracking code provided' unless (12..14).cover? tracking_code.length resp = self.new.client.call( Fedex::Parcel.configuration.method, message: self.assign_tracking_code(tracking_code) ) body = resp.body result = self.body_contents(body) if resp.http.code == 200 && result.to_s.length < 90 return { error: 'Tracking code provided no longer found' } else result end end