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.



11448
11449
11450
11451
11452
11453
11454
11455
11456
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11448

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:customer, :destination, :items], 'OrderPutForm')
  @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::LineItem) ? x : ::Io::Flow::V0::Models::LineItem.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) })
  @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)))
end

Instance Attribute Details

#customerObject (readonly)

Returns the value of attribute customer.



11446
11447
11448
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11446

def customer
  @customer
end

#destinationObject (readonly)

Returns the value of attribute destination.



11446
11447
11448
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11446

def destination
  @destination
end

#discountObject (readonly)

Returns the value of attribute discount.



11446
11447
11448
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11446

def discount
  @discount
end

#itemsObject (readonly)

Returns the value of attribute items.



11446
11447
11448
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11446

def items
  @items
end

#selectionsObject (readonly)

Returns the value of attribute selections.



11446
11447
11448
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11446

def selections
  @selections
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



11462
11463
11464
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11462

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

#to_hashObject



11466
11467
11468
11469
11470
11471
11472
11473
11474
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11466

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

#to_jsonObject



11458
11459
11460
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11458

def to_json
  JSON.dump(to_hash)
end