Class: WalmartApIs::TrackingInfo

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/walmart_ap_is/models/tracking_info.rb

Overview

TrackingInfo Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(carrier:, tracking_number:, shipped_date:, method_code: SKIP, additional_properties: nil) ⇒ TrackingInfo

Returns a new instance of TrackingInfo.



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/walmart_ap_is/models/tracking_info.rb', line 51

def initialize(carrier:, tracking_number:, shipped_date:, method_code: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @carrier = carrier
  @tracking_number = tracking_number
  @shipped_date = shipped_date
  @method_code = method_code unless method_code == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#carrierCarrierName

TODO: Write general description for this method

Returns:



15
16
17
# File 'lib/walmart_ap_is/models/tracking_info.rb', line 15

def carrier
  @carrier
end

#method_codeMethodCode

TODO: Write general description for this method

Returns:



27
28
29
# File 'lib/walmart_ap_is/models/tracking_info.rb', line 27

def method_code
  @method_code
end

#shipped_dateDateTime

TODO: Write general description for this method

Returns:

  • (DateTime)


23
24
25
# File 'lib/walmart_ap_is/models/tracking_info.rb', line 23

def shipped_date
  @shipped_date
end

#tracking_numberString

TODO: Write general description for this method

Returns:

  • (String)


19
20
21
# File 'lib/walmart_ap_is/models/tracking_info.rb', line 19

def tracking_number
  @tracking_number
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/walmart_ap_is/models/tracking_info.rb', line 64

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  carrier = hash.key?('carrier') ? hash['carrier'] : nil
  tracking_number =
    hash.key?('trackingNumber') ? hash['trackingNumber'] : nil
  shipped_date = if hash.key?('shippedDate')
                   (DateTimeHelper.from_rfc3339(hash['shippedDate']) if hash['shippedDate'])
                 end
  method_code = hash.key?('methodCode') ? hash['methodCode'] : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  TrackingInfo.new(carrier: carrier,
                   tracking_number: tracking_number,
                   shipped_date: shipped_date,
                   method_code: method_code,
                   additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



30
31
32
33
34
35
36
37
# File 'lib/walmart_ap_is/models/tracking_info.rb', line 30

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['carrier'] = 'carrier'
  @_hash['tracking_number'] = 'trackingNumber'
  @_hash['shipped_date'] = 'shippedDate'
  @_hash['method_code'] = 'methodCode'
  @_hash
end

.nullablesObject

An array for nullable fields



47
48
49
# File 'lib/walmart_ap_is/models/tracking_info.rb', line 47

def self.nullables
  []
end

.optionalsObject

An array for optional fields



40
41
42
43
44
# File 'lib/walmart_ap_is/models/tracking_info.rb', line 40

def self.optionals
  %w[
    method_code
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



104
105
106
107
108
109
# File 'lib/walmart_ap_is/models/tracking_info.rb', line 104

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} carrier: #{@carrier.inspect}, tracking_number: #{@tracking_number.inspect},"\
  " shipped_date: #{@shipped_date.inspect}, method_code: #{@method_code.inspect},"\
  " additional_properties: #{@additional_properties}>"
end

#to_custom_shipped_dateObject



91
92
93
# File 'lib/walmart_ap_is/models/tracking_info.rb', line 91

def to_custom_shipped_date
  DateTimeHelper.to_rfc3339(shipped_date)
end

#to_sObject

Provides a human-readable string representation of the object.



96
97
98
99
100
101
# File 'lib/walmart_ap_is/models/tracking_info.rb', line 96

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} carrier: #{@carrier}, tracking_number: #{@tracking_number}, shipped_date:"\
  " #{@shipped_date}, method_code: #{@method_code}, additional_properties:"\
  " #{@additional_properties}>"
end