Class: Io::Flow::V0::Models::ConsumerInvoice

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

Overview

The consumer invoice represents the details of a set of items from a given order. This may represent either the full order or a partial fulfillment.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ ConsumerInvoice

Returns a new instance of ConsumerInvoice.



19018
19019
19020
19021
19022
19023
19024
19025
19026
19027
19028
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19018

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :date, :key, :order, :items, :documents, :attributes], 'ConsumerInvoice')
  @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
  @date = HttpClient::Preconditions.assert_class('date', HttpClient::Helper.to_date_time_iso8601(opts.delete(:date)), DateTime)
  @key = HttpClient::Preconditions.assert_class('key', opts.delete(:key), String)
  @order = (x = opts.delete(:order); x.is_a?(::Io::Flow::V0::Models::OrderReference) ? x : ::Io::Flow::V0::Models::OrderReference.new(x))
  @items = HttpClient::Preconditions.assert_class('items', opts.delete(:items), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::ConsumerInvoiceItem) ? x : ::Io::Flow::V0::Models::ConsumerInvoiceItem.new(x)) }
  @documents = HttpClient::Preconditions.assert_class('documents', opts.delete(:documents), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::ConsumerInvoiceDocument) ? x : ::Io::Flow::V0::Models::ConsumerInvoiceDocument.new(x)) }
  @attributes = HttpClient::Preconditions.assert_class('attributes', opts.delete(:attributes), 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.



19016
19017
19018
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19016

def attributes
  @attributes
end

#dateObject (readonly)

Returns the value of attribute date.



19016
19017
19018
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19016

def date
  @date
end

#documentsObject (readonly)

Returns the value of attribute documents.



19016
19017
19018
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19016

def documents
  @documents
end

#idObject (readonly)

Returns the value of attribute id.



19016
19017
19018
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19016

def id
  @id
end

#itemsObject (readonly)

Returns the value of attribute items.



19016
19017
19018
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19016

def items
  @items
end

#keyObject (readonly)

Returns the value of attribute key.



19016
19017
19018
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19016

def key
  @key
end

#orderObject (readonly)

Returns the value of attribute order.



19016
19017
19018
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19016

def order
  @order
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



19034
19035
19036
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19034

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

#to_hashObject



19038
19039
19040
19041
19042
19043
19044
19045
19046
19047
19048
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19038

def to_hash
  {
    :id => id,
    :date => date,
    :key => key,
    :order => order.to_hash,
    :items => items.map { |o| o.to_hash },
    :documents => documents.map { |o| o.to_hash },
    :attributes => attributes
  }
end

#to_jsonObject



19030
19031
19032
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 19030

def to_json
  JSON.dump(to_hash)
end