Class: NewStoreApi::HistoricalOrderShipment

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/new_store_api/models/historical_order_shipment.rb

Overview

Shipment of a historical order that has already been shipped from a fulfillment location. A historical order represents an already completed order that was imported from an external system, into NewStore.

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(historical_shipping_option = nil, items = nil, shipped_at = SKIP) ⇒ HistoricalOrderShipment

Returns a new instance of HistoricalOrderShipment.



50
51
52
53
54
55
# File 'lib/new_store_api/models/historical_order_shipment.rb', line 50

def initialize(historical_shipping_option = nil, items = nil,
               shipped_at = SKIP)
  @historical_shipping_option = historical_shipping_option
  @items = items
  @shipped_at = shipped_at unless shipped_at == SKIP
end

Instance Attribute Details

#historical_shipping_optionHistoricalShippingOption

TODO: Write general description for this method



17
18
19
# File 'lib/new_store_api/models/historical_order_shipment.rb', line 17

def historical_shipping_option
  @historical_shipping_option
end

#itemsArray[InjectedOrderShipmentItem]

TODO: Write general description for this method

Returns:



21
22
23
# File 'lib/new_store_api/models/historical_order_shipment.rb', line 21

def items
  @items
end

#shipped_atDateTime

Date representation of when the shipment was shipped, containing date, time and timezone as defined by https://tools.ietf.org/html/rfc3339 (ISO 8601). In case not provided, is set to placed_at.

Returns:

  • (DateTime)


27
28
29
# File 'lib/new_store_api/models/historical_order_shipment.rb', line 27

def shipped_at
  @shipped_at
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/new_store_api/models/historical_order_shipment.rb', line 58

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  if hash['historical_shipping_option']
    historical_shipping_option = HistoricalShippingOption.from_hash(hash['historical_shipping_option'])
  end
  # Parameter is an array, so we need to iterate through it
  items = nil
  unless hash['items'].nil?
    items = []
    hash['items'].each do |structure|
      items << (InjectedOrderShipmentItem.from_hash(structure) if structure)
    end
  end

  items = nil unless hash.key?('items')
  shipped_at = if hash.key?('shipped_at')
                 (DateTimeHelper.from_rfc3339(hash['shipped_at']) if hash['shipped_at'])
               else
                 SKIP
               end

  # Create object from extracted values.
  HistoricalOrderShipment.new(historical_shipping_option,
                              items,
                              shipped_at)
end

.namesObject

A mapping from model property names to API property names.



30
31
32
33
34
35
36
# File 'lib/new_store_api/models/historical_order_shipment.rb', line 30

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['historical_shipping_option'] = 'historical_shipping_option'
  @_hash['items'] = 'items'
  @_hash['shipped_at'] = 'shipped_at'
  @_hash
end

.nullablesObject

An array for nullable fields



46
47
48
# File 'lib/new_store_api/models/historical_order_shipment.rb', line 46

def self.nullables
  []
end

.optionalsObject

An array for optional fields



39
40
41
42
43
# File 'lib/new_store_api/models/historical_order_shipment.rb', line 39

def self.optionals
  %w[
    shipped_at
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/new_store_api/models/historical_order_shipment.rb', line 93

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.historical_shipping_option,
                            ->(val) { HistoricalShippingOption.validate(val) },
                            is_model_hash: true) and
        APIHelper.valid_type?(value.items,
                              ->(val) { InjectedOrderShipmentItem.validate(val) },
                              is_model_hash: true,
                              is_inner_model_hash: true)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['historical_shipping_option'],
                          ->(val) { HistoricalShippingOption.validate(val) },
                          is_model_hash: true) and
      APIHelper.valid_type?(value['items'],
                            ->(val) { InjectedOrderShipmentItem.validate(val) },
                            is_model_hash: true,
                            is_inner_model_hash: true)
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



127
128
129
130
131
# File 'lib/new_store_api/models/historical_order_shipment.rb', line 127

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} historical_shipping_option: #{@historical_shipping_option.inspect}, items:"\
  " #{@items.inspect}, shipped_at: #{@shipped_at.inspect}>"
end

#to_custom_shipped_atObject



87
88
89
# File 'lib/new_store_api/models/historical_order_shipment.rb', line 87

def to_custom_shipped_at
  DateTimeHelper.to_rfc3339(shipped_at)
end

#to_sObject

Provides a human-readable string representation of the object.



120
121
122
123
124
# File 'lib/new_store_api/models/historical_order_shipment.rb', line 120

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} historical_shipping_option: #{@historical_shipping_option}, items:"\
  " #{@items}, shipped_at: #{@shipped_at}>"
end