Class: Io::Flow::V0::Models::OrderForm

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

Overview

The order form is used to create an open 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 = {}) ⇒ OrderForm

Returns a new instance of OrderForm.



12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12992

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:number, :customer, :destination, :items], 'OrderForm')
  @number = HttpClient::Preconditions.assert_class('number', opts.delete(:number), String)
  @customer = (x = opts.delete(:customer); x.is_a?(::Io::Flow::V0::Models::Customer) ? x : ::Io::Flow::V0::Models::Customer.new(x))
  @destination = (x = opts.delete(:destination); x.is_a?(::Io::Flow::V0::Models::Address) ? x : ::Io::Flow::V0::Models::Address.new(x))
  @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)) }
  @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

#attributesObject (readonly)

Returns the value of attribute attributes.



12990
12991
12992
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12990

def attributes
  @attributes
end

#customerObject (readonly)

Returns the value of attribute customer.



12990
12991
12992
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12990

def customer
  @customer
end

#destinationObject (readonly)

Returns the value of attribute destination.



12990
12991
12992
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12990

def destination
  @destination
end

#discountObject (readonly)

Returns the value of attribute discount.



12990
12991
12992
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12990

def discount
  @discount
end

#itemsObject (readonly)

Returns the value of attribute items.



12990
12991
12992
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12990

def items
  @items
end

#numberObject (readonly)

Returns the value of attribute number.



12990
12991
12992
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 12990

def number
  @number
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



13007
13008
13009
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 13007

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

#to_hashObject



13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 13011

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

#to_jsonObject



13003
13004
13005
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 13003

def to_json
  JSON.dump(to_hash)
end