Class: Io::Flow::V0::Models::Delivery

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

Overview

Represents a collection of items, the available delivery option tier for that collection of items, and metadata about those options

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Delivery

Returns a new instance of Delivery.



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

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :items, :options], 'Delivery')
  @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
  @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)) }
  @options = HttpClient::Preconditions.assert_class('options', opts.delete(:options), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::DeliveryOption) ? x : ::Io::Flow::V0::Models::DeliveryOption.new(x)) }
end

Instance Attribute Details

#id ⇒ Object (readonly)

Returns the value of attribute id.



11465
11466
11467
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11465

def id
  @id
end

#items ⇒ Object (readonly)

Returns the value of attribute items.



11465
11466
11467
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11465

def items
  @items
end

#options ⇒ Object (readonly)

Returns the value of attribute options.



11465
11466
11467
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11465

def options
  @options
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



11479
11480
11481
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11479

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

#to_hash ⇒ Object



11483
11484
11485
11486
11487
11488
11489
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11483

def to_hash
  {
    :id => id,
    :items => items.map { |o| o.to_hash },
    :options => options.map { |o| o.to_hash }
  }
end

#to_json ⇒ Object



11475
11476
11477
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11475

def to_json
  JSON.dump(to_hash)
end