Class: NewStoreApi::RoutingOptionsRequest

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

Overview

Call to get a list of routing options. Also, colloquially known as 'soft routing'.

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(delivery_destination = nil, line_items = nil, routing_strategy = SKIP) ⇒ RoutingOptionsRequest

Returns a new instance of RoutingOptionsRequest.



47
48
49
50
51
52
# File 'lib/new_store_api/models/routing_options_request.rb', line 47

def initialize(delivery_destination = nil, line_items = nil,
               routing_strategy = SKIP)
  @delivery_destination = delivery_destination
  @line_items = line_items
  @routing_strategy = routing_strategy unless routing_strategy == SKIP
end

Instance Attribute Details

#delivery_destinationDeliveryDestination

Destination country and the zip code where the ordered products are to be delivered.

Returns:



16
17
18
# File 'lib/new_store_api/models/routing_options_request.rb', line 16

def delivery_destination
  @delivery_destination
end

#line_itemsArray[LineItem21]

List of line items to be routed.

Returns:



20
21
22
# File 'lib/new_store_api/models/routing_options_request.rb', line 20

def line_items
  @line_items
end

#routing_strategyObject

List of line items to be routed.

Returns:

  • (Object)


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

def routing_strategy
  @routing_strategy
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/new_store_api/models/routing_options_request.rb', line 55

def self.from_hash(hash)
  return nil unless hash

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

  line_items = nil unless hash.key?('line_items')
  routing_strategy = hash.key?('routing_strategy') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:RoutingOptionsRequestRoutingStrategy), hash['routing_strategy']
  ) : SKIP

  # Create object from extracted values.
  RoutingOptionsRequest.new(delivery_destination,
                            line_items,
                            routing_strategy)
end

.namesObject

A mapping from model property names to API property names.



27
28
29
30
31
32
33
# File 'lib/new_store_api/models/routing_options_request.rb', line 27

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['delivery_destination'] = 'delivery_destination'
  @_hash['line_items'] = 'line_items'
  @_hash['routing_strategy'] = 'routing_strategy'
  @_hash
end

.nullablesObject

An array for nullable fields



43
44
45
# File 'lib/new_store_api/models/routing_options_request.rb', line 43

def self.nullables
  []
end

.optionalsObject

An array for optional fields



36
37
38
39
40
# File 'lib/new_store_api/models/routing_options_request.rb', line 36

def self.optionals
  %w[
    routing_strategy
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/new_store_api/models/routing_options_request.rb', line 83

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.delivery_destination,
                            ->(val) { DeliveryDestination.validate(val) },
                            is_model_hash: true) and
        APIHelper.valid_type?(value.line_items,
                              ->(val) { LineItem21.validate(val) },
                              is_model_hash: true,
                              is_inner_model_hash: true)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['delivery_destination'],
                          ->(val) { DeliveryDestination.validate(val) },
                          is_model_hash: true) and
      APIHelper.valid_type?(value['line_items'],
                            ->(val) { LineItem21.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.



117
118
119
120
121
# File 'lib/new_store_api/models/routing_options_request.rb', line 117

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

#to_sObject

Provides a human-readable string representation of the object.



110
111
112
113
114
# File 'lib/new_store_api/models/routing_options_request.rb', line 110

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