Class: Fedex::Parcel

Inherits:
Object
  • Object
show all
Defined in:
lib/fedex_parcels_tracker.rb

Defined Under Namespace

Classes: Configuration

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeParcel

Returns a new instance of Parcel.



30
31
32
33
34
35
# 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

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



9
10
11
# File 'lib/fedex_parcels_tracker.rb', line 9

def configuration
  @configuration
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



6
7
8
# File 'lib/fedex_parcels_tracker.rb', line 6

def client
  @client
end

Class Method Details

.assign_tracking_code(tracking_code) ⇒ Object



56
57
58
59
60
61
# 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) ⇒ Object



63
64
65
# 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| ... } ⇒ Object

Yields:



12
13
14
15
# File 'lib/fedex_parcels_tracker.rb', line 12

def self.configure
  self.configuration ||= Configuration.new
  yield(configuration)
end

.track(tracking_code) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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