Class: Io::Flow::V0::Models::OrderPutForm

Inherits:
Object
  • Object
show all
Defined in:
lib/flow_commerce/flow_api_v0_client.rb

Overview

The order put form is used to upsert an order, providing the details on pricing and delivery options for destination and items/quantities specified.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ OrderPutForm

Returns a new instance of OrderPutForm.



17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17147

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:items], 'OrderPutForm')
  @items = HttpClient::Preconditions.assert_class('items', opts.delete(:items), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::LineItemForm) ? x : ::Io::Flow::V0::Models::LineItemForm.new(x)) }
  @customer = (x = opts.delete(:customer); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::Customer) ? x : ::Io::Flow::V0::Models::Customer.new(x)))
  @selections = (x = opts.delete(:selections); x.nil? ? nil : HttpClient::Preconditions.assert_class('selections', x, Array).map { |v| HttpClient::Preconditions.assert_class('selections', v, String) })
  @destination = (x = opts.delete(:destination); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::OrderAddress) ? x : ::Io::Flow::V0::Models::OrderAddress.new(x)))
  @discount = (x = opts.delete(:discount); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::Money) ? x : ::Io::Flow::V0::Models::Money.new(x)))
  @attributes = (x = opts.delete(:attributes); x.nil? ? nil : HttpClient::Preconditions.assert_class('attributes', x, Hash).inject({}) { |h, d| h[d[0]] = HttpClient::Preconditions.assert_class('attributes', d[1], String); h })
end

Instance Attribute Details

#attributes ⇒ Object (readonly)

Returns the value of attribute attributes.



17145
17146
17147
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17145

def attributes
  @attributes
end

#customer ⇒ Object (readonly)

Returns the value of attribute customer.



17145
17146
17147
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17145

def customer
  @customer
end

#destination ⇒ Object (readonly)

Returns the value of attribute destination.



17145
17146
17147
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17145

def destination
  @destination
end

#discount ⇒ Object (readonly)

Returns the value of attribute discount.



17145
17146
17147
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17145

def discount
  @discount
end

#items ⇒ Object (readonly)

Returns the value of attribute items.



17145
17146
17147
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17145

def items
  @items
end

#selections ⇒ Object (readonly)

Returns the value of attribute selections.



17145
17146
17147
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17145

def selections
  @selections
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



17162
17163
17164
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17162

def copy(incoming={})
  OrderPutForm.new(to_hash.merge(HttpClient::Helper.symbolize_keys(incoming)))
end

#to_hash ⇒ Object



17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17166

def to_hash
  {
    :items => items.map { |o| o.to_hash },
    :customer => customer.nil? ? nil : customer.to_hash,
    :selections => selections.nil? ? nil : selections,
    :destination => destination.nil? ? nil : destination.to_hash,
    :discount => discount.nil? ? nil : discount.to_hash,
    :attributes => attributes.nil? ? nil : attributes
  }
end

#to_json ⇒ Object



17158
17159
17160
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 17158

def to_json
  JSON.dump(to_hash)
end