Class: WalmartApIs::Rate

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

Overview

Rate 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(rate_id:, carrier:, service:, total_charge:, billed_weight: SKIP, expiration_time: SKIP, promise: SKIP, supported_document_specifications: SKIP, available_value_added_services: SKIP, additional_properties: nil) ⇒ Rate

Returns a new instance of Rate.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/walmart_ap_is/models/rate.rb', line 86

def initialize(rate_id:, carrier:, service:, total_charge:,
               billed_weight: SKIP, expiration_time: SKIP, promise: SKIP,
               supported_document_specifications: SKIP,
               available_value_added_services: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @rate_id = rate_id
  @carrier = carrier
  @service = service
  @total_charge = total_charge
  @billed_weight = billed_weight unless billed_weight == SKIP
  @expiration_time = expiration_time unless expiration_time == SKIP
  @promise = promise unless promise == SKIP
  unless supported_document_specifications == SKIP
    @supported_document_specifications =
      supported_document_specifications
  end
  unless available_value_added_services == SKIP
    @available_value_added_services =
      available_value_added_services
  end
  @additional_properties = additional_properties
end

Instance Attribute Details

#available_value_added_servicesArray[Object]

Value-added services available for purchase at this rate (signature, COD, dangerous goods, etc). Compressed shape; full fidelity tracked in a follow-up PR.

Returns:

  • (Array[Object])


52
53
54
# File 'lib/walmart_ap_is/models/rate.rb', line 52

def available_value_added_services
  @available_value_added_services
end

#billed_weightWeight

TODO: Write general description for this method

Returns:



31
32
33
# File 'lib/walmart_ap_is/models/rate.rb', line 31

def billed_weight
  @billed_weight
end

#carrierCarrier

TODO: Write general description for this method

Returns:



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

def carrier
  @carrier
end

#expiration_timeDateTime

TODO: Write general description for this method

Returns:

  • (DateTime)


35
36
37
# File 'lib/walmart_ap_is/models/rate.rb', line 35

def expiration_time
  @expiration_time
end

#promisePromise

TODO: Write general description for this method

Returns:



39
40
41
# File 'lib/walmart_ap_is/models/rate.rb', line 39

def promise
  @promise
end

#rate_idString

TODO: Write general description for this method

Returns:

  • (String)


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

def rate_id
  @rate_id
end

#serviceService

TODO: Write general description for this method

Returns:



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

def service
  @service
end

#supported_document_specificationsArray[Object]

List of label/document formats supported by this rate. Each entry shape matches industry-standard SupportedDocumentSpecification; tier-1 fidelity is sufficient for v4 — see TODO at top of file.

Returns:

  • (Array[Object])


46
47
48
# File 'lib/walmart_ap_is/models/rate.rb', line 46

def supported_document_specifications
  @supported_document_specifications
end

#total_chargeMoney

TODO: Write general description for this method

Returns:



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

def total_charge
  @total_charge
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/walmart_ap_is/models/rate.rb', line 113

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  rate_id = hash.key?('rateId') ? hash['rateId'] : nil
  carrier = Carrier.from_hash(hash['carrier']) if hash['carrier']
  service = Service.from_hash(hash['service']) if hash['service']
  total_charge = Money.from_hash(hash['totalCharge']) if hash['totalCharge']
  billed_weight = Weight.from_hash(hash['billedWeight']) if hash['billedWeight']
  expiration_time = if hash.key?('expirationTime')
                      (DateTimeHelper.from_rfc3339(hash['expirationTime']) if hash['expirationTime'])
                    else
                      SKIP
                    end
  promise = Promise.from_hash(hash['promise']) if hash['promise']
  supported_document_specifications =
    hash.key?('supportedDocumentSpecifications') ? hash['supportedDocumentSpecifications'] : SKIP
  available_value_added_services =
    hash.key?('availableValueAddedServices') ? hash['availableValueAddedServices'] : 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.
  Rate.new(rate_id: rate_id,
           carrier: carrier,
           service: service,
           total_charge: total_charge,
           billed_weight: billed_weight,
           expiration_time: expiration_time,
           promise: promise,
           supported_document_specifications: supported_document_specifications,
           available_value_added_services: available_value_added_services,
           additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/walmart_ap_is/models/rate.rb', line 55

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['rate_id'] = 'rateId'
  @_hash['carrier'] = 'carrier'
  @_hash['service'] = 'service'
  @_hash['total_charge'] = 'totalCharge'
  @_hash['billed_weight'] = 'billedWeight'
  @_hash['expiration_time'] = 'expirationTime'
  @_hash['promise'] = 'promise'
  @_hash['supported_document_specifications'] =
    'supportedDocumentSpecifications'
  @_hash['available_value_added_services'] = 'availableValueAddedServices'
  @_hash
end

.nullablesObject

An array for nullable fields



82
83
84
# File 'lib/walmart_ap_is/models/rate.rb', line 82

def self.nullables
  []
end

.optionalsObject

An array for optional fields



71
72
73
74
75
76
77
78
79
# File 'lib/walmart_ap_is/models/rate.rb', line 71

def self.optionals
  %w[
    billed_weight
    expiration_time
    promise
    supported_document_specifications
    available_value_added_services
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



168
169
170
171
172
173
174
175
176
177
# File 'lib/walmart_ap_is/models/rate.rb', line 168

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} rate_id: #{@rate_id.inspect}, carrier: #{@carrier.inspect}, service:"\
  " #{@service.inspect}, total_charge: #{@total_charge.inspect}, billed_weight:"\
  " #{@billed_weight.inspect}, expiration_time: #{@expiration_time.inspect}, promise:"\
  " #{@promise.inspect}, supported_document_specifications:"\
  " #{@supported_document_specifications.inspect}, available_value_added_services:"\
  " #{@available_value_added_services.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_custom_expiration_timeObject



153
154
155
# File 'lib/walmart_ap_is/models/rate.rb', line 153

def to_custom_expiration_time
  DateTimeHelper.to_rfc3339(expiration_time)
end

#to_sObject

Provides a human-readable string representation of the object.



158
159
160
161
162
163
164
165
# File 'lib/walmart_ap_is/models/rate.rb', line 158

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} rate_id: #{@rate_id}, carrier: #{@carrier}, service: #{@service},"\
  " total_charge: #{@total_charge}, billed_weight: #{@billed_weight}, expiration_time:"\
  " #{@expiration_time}, promise: #{@promise}, supported_document_specifications:"\
  " #{@supported_document_specifications}, available_value_added_services:"\
  " #{@available_value_added_services}, additional_properties: #{@additional_properties}>"
end