Class: Io::Flow::V0::Models::LineItem

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

Overview

Line items represent the items a consumer is purchasing, including additional information to complete the transaction. Note that you may pass in as many line items as you like - including repeating item numbers across line items.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ LineItem

Returns a new instance of LineItem.



36175
36176
36177
36178
36179
36180
36181
36182
36183
36184
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 36175

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:number, :quantity, :price, :attributes], 'LineItem')
  @number = HttpClient::Preconditions.assert_class('number', opts.delete(:number), String)
  @quantity = HttpClient::Preconditions.assert_class('quantity', opts.delete(:quantity), Integer)
  @price = (x = opts.delete(:price); x.is_a?(::Io::Flow::V0::Models::Money) ? x : ::Io::Flow::V0::Models::Money.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 }
  @center = (x = opts.delete(:center); x.nil? ? nil : HttpClient::Preconditions.assert_class('center', x, 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

#attributesObject (readonly)

Returns the value of attribute attributes.



36173
36174
36175
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 36173

def attributes
  @attributes
end

#centerObject (readonly)

Returns the value of attribute center.



36173
36174
36175
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 36173

def center
  @center
end

#discountObject (readonly)

Returns the value of attribute discount.



36173
36174
36175
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 36173

def discount
  @discount
end

#numberObject (readonly)

Returns the value of attribute number.



36173
36174
36175
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 36173

def number
  @number
end

#priceObject (readonly)

Returns the value of attribute price.



36173
36174
36175
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 36173

def price
  @price
end

#quantityObject (readonly)

Returns the value of attribute quantity.



36173
36174
36175
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 36173

def quantity
  @quantity
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



36190
36191
36192
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 36190

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

#to_hashObject



36194
36195
36196
36197
36198
36199
36200
36201
36202
36203
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 36194

def to_hash
  {
    :number => number,
    :quantity => quantity,
    :price => price.to_hash,
    :attributes => attributes,
    :center => center,
    :discount => discount.nil? ? nil : discount.to_hash
  }
end

#to_jsonObject



36186
36187
36188
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 36186

def to_json
  JSON.dump(to_hash)
end