Class: NewStoreApi::RequestCreateBookings

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

Overview

RequestCreateBookings 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(external_order_id = nil, location_id = nil, option_id = nil, packages = nil, recipient_address = nil, book_outbound = true, book_return = false) ⇒ RequestCreateBookings

Returns a new instance of RequestCreateBookings.



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/new_store_api/models/request_create_bookings.rb', line 74

def initialize(external_order_id = nil, location_id = nil, option_id = nil,
               packages = nil, recipient_address = nil,
               book_outbound = true, book_return = false)
  @book_outbound = book_outbound unless book_outbound == SKIP
  @book_return = book_return unless book_return == SKIP
  @external_order_id = external_order_id
  @location_id = location_id
  @option_id = option_id
  @packages = packages
  @recipient_address = recipient_address
end

Instance Attribute Details

#book_outboundTrueClass | FalseClass

default true. book outbound shipment using location's sender address.

Returns:

  • (TrueClass | FalseClass)


14
15
16
# File 'lib/new_store_api/models/request_create_bookings.rb', line 14

def book_outbound
  @book_outbound
end

#book_returnTrueClass | FalseClass

default false. if true, will use the recipient address as sender and the location's address as recipient.

Returns:

  • (TrueClass | FalseClass)


19
20
21
# File 'lib/new_store_api/models/request_create_bookings.rb', line 19

def book_return
  @book_return
end

#external_order_idString

default false. if true, will use the recipient address as sender and the location's address as recipient.

Returns:

  • (String)


24
25
26
# File 'lib/new_store_api/models/request_create_bookings.rb', line 24

def external_order_id
  @external_order_id
end

#location_idString

the location sending the shipment, or receiving it from customer if booking a return.

Returns:

  • (String)


29
30
31
# File 'lib/new_store_api/models/request_create_bookings.rb', line 29

def location_id
  @location_id
end

#option_idUUID | String

the location sending the shipment, or receiving it from customer if booking a return.

Returns:

  • (UUID | String)


34
35
36
# File 'lib/new_store_api/models/request_create_bookings.rb', line 34

def option_id
  @option_id
end

#packagesArray[RequestPackage]

the location sending the shipment, or receiving it from customer if booking a return.

Returns:



39
40
41
# File 'lib/new_store_api/models/request_create_bookings.rb', line 39

def packages
  @packages
end

#recipient_addressRequestRecipientAddress

Address the shipment is sent to. In case of a return shipment, this address will be used as the sender even though it says recipient. Recipient is meant as the address used by the initial shipment that shipped goods initially.



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

def recipient_address
  @recipient_address
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



87
88
89
90
91
92
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
118
# File 'lib/new_store_api/models/request_create_bookings.rb', line 87

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  external_order_id =
    hash.key?('external_order_id') ? hash['external_order_id'] : nil
  location_id = hash.key?('location_id') ? hash['location_id'] : nil
  option_id = hash.key?('option_id') ? hash['option_id'] : nil
  # Parameter is an array, so we need to iterate through it
  packages = nil
  unless hash['packages'].nil?
    packages = []
    hash['packages'].each do |structure|
      packages << (RequestPackage.from_hash(structure) if structure)
    end
  end

  packages = nil unless hash.key?('packages')
  recipient_address = RequestRecipientAddress.from_hash(hash['recipient_address']) if
    hash['recipient_address']
  book_outbound = hash['book_outbound'] ||= true
  book_return = hash['book_return'] ||= false

  # Create object from extracted values.
  RequestCreateBookings.new(external_order_id,
                            location_id,
                            option_id,
                            packages,
                            recipient_address,
                            book_outbound,
                            book_return)
end

.namesObject

A mapping from model property names to API property names.



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/new_store_api/models/request_create_bookings.rb', line 49

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['book_outbound'] = 'book_outbound'
  @_hash['book_return'] = 'book_return'
  @_hash['external_order_id'] = 'external_order_id'
  @_hash['location_id'] = 'location_id'
  @_hash['option_id'] = 'option_id'
  @_hash['packages'] = 'packages'
  @_hash['recipient_address'] = 'recipient_address'
  @_hash
end

.nullablesObject

An array for nullable fields



70
71
72
# File 'lib/new_store_api/models/request_create_bookings.rb', line 70

def self.nullables
  []
end

.optionalsObject

An array for optional fields



62
63
64
65
66
67
# File 'lib/new_store_api/models/request_create_bookings.rb', line 62

def self.optionals
  %w[
    book_outbound
    book_return
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



129
130
131
132
133
134
135
# File 'lib/new_store_api/models/request_create_bookings.rb', line 129

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} book_outbound: #{@book_outbound.inspect}, book_return:"\
  " #{@book_return.inspect}, external_order_id: #{@external_order_id.inspect}, location_id:"\
  " #{@location_id.inspect}, option_id: #{@option_id.inspect}, packages: #{@packages.inspect},"\
  " recipient_address: #{@recipient_address.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



121
122
123
124
125
126
# File 'lib/new_store_api/models/request_create_bookings.rb', line 121

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} book_outbound: #{@book_outbound}, book_return: #{@book_return},"\
  " external_order_id: #{@external_order_id}, location_id: #{@location_id}, option_id:"\
  " #{@option_id}, packages: #{@packages}, recipient_address: #{@recipient_address}>"
end