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.



19931
19932
19933
19934
19935
19936
19937
19938
19939
19940
19941
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19931

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

#attributesObject (readonly)

Returns the value of attribute attributes.



19929
19930
19931
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19929

def attributes
  @attributes
end

#customerObject (readonly)

Returns the value of attribute customer.



19929
19930
19931
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19929

def customer
  @customer
end

#delivered_dutyObject (readonly)

Returns the value of attribute delivered_duty.



19929
19930
19931
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19929

def delivered_duty
  @delivered_duty
end

#destinationObject (readonly)

Returns the value of attribute destination.



19929
19930
19931
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19929

def destination
  @destination
end

#discountObject (readonly)

Returns the value of attribute discount.



19929
19930
19931
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19929

def discount
  @discount
end

#itemsObject (readonly)

Returns the value of attribute items.



19929
19930
19931
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19929

def items
  @items
end

#numberObject (readonly)

Returns the value of attribute number.



19929
19930
19931
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19929

def number
  @number
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



19947
19948
19949
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19947

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

#to_hashObject



19951
19952
19953
19954
19955
19956
19957
19958
19959
19960
19961
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19951

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

#to_jsonObject



19943
19944
19945
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19943

def to_json
  JSON.dump(to_hash)
end