Class: Io::Flow::V0::Models::OrderQuoteLine

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

Overview

Same interface as experience order_summary_line_item with additional attributes needed by order_quote

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ OrderQuoteLine

Returns a new instance of OrderQuoteLine.



47138
47139
47140
47141
47142
47143
47144
47145
47146
47147
47148
47149
47150
47151
47152
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47138

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :item, :quantity, :unit_price, :total, :price_attributes, :attributes], 'OrderQuoteLine')
  @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
  @item = (x = opts.delete(:item); x.is_a?(::Io::Flow::V0::Models::OrderSummaryItem) ? x : ::Io::Flow::V0::Models::OrderSummaryItem.new(x))
  @errors = (x = opts.delete(:errors); x.nil? ? nil : HttpClient::Preconditions.assert_class('errors', x, Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::OrderQuoteLineError) ? x : ::Io::Flow::V0::Models::OrderQuoteLineError.new(x)) })
  @quantity = HttpClient::Preconditions.assert_class('quantity', opts.delete(:quantity), Integer)
  @discount = (x = opts.delete(:discount); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::OrderQuoteLineDiscount) ? x : ::Io::Flow::V0::Models::OrderQuoteLineDiscount.new(x)))
  @tax = (x = opts.delete(:tax); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::OrderQuoteSummaryTax) ? x : ::Io::Flow::V0::Models::OrderQuoteSummaryTax.new(x)))
  @duty = (x = opts.delete(:duty); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::OrderQuoteSummaryDuty) ? x : ::Io::Flow::V0::Models::OrderQuoteSummaryDuty.new(x)))
  @unit_price = (x = opts.delete(:unit_price); x.is_a?(::Io::Flow::V0::Models::OrderQuotePrice) ? x : ::Io::Flow::V0::Models::OrderQuotePrice.from_json(x))
  @total = (x = opts.delete(:total); x.is_a?(::Io::Flow::V0::Models::OrderQuotePrice) ? x : ::Io::Flow::V0::Models::OrderQuotePrice.from_json(x))
  @price_attributes = HttpClient::Preconditions.assert_class('price_attributes', opts.delete(:price_attributes), Hash).inject({}) { |h, d| h[d[0]] = (x = d[1]; x.is_a?(::Io::Flow::V0::Models::OrderQuotePriceStandard) ? x : ::Io::Flow::V0::Models::OrderQuotePriceStandard.new(x)); h }
  @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.



47136
47137
47138
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47136

def attributes
  @attributes
end

#discountObject (readonly)

Returns the value of attribute discount.



47136
47137
47138
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47136

def discount
  @discount
end

#dutyObject (readonly)

Returns the value of attribute duty.



47136
47137
47138
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47136

def duty
  @duty
end

#errorsObject (readonly)

Returns the value of attribute errors.



47136
47137
47138
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47136

def errors
  @errors
end

#idObject (readonly)

Returns the value of attribute id.



47136
47137
47138
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47136

def id
  @id
end

#itemObject (readonly)

Returns the value of attribute item.



47136
47137
47138
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47136

def item
  @item
end

#price_attributesObject (readonly)

Returns the value of attribute price_attributes.



47136
47137
47138
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47136

def price_attributes
  @price_attributes
end

#quantityObject (readonly)

Returns the value of attribute quantity.



47136
47137
47138
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47136

def quantity
  @quantity
end

#taxObject (readonly)

Returns the value of attribute tax.



47136
47137
47138
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47136

def tax
  @tax
end

#totalObject (readonly)

Returns the value of attribute total.



47136
47137
47138
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47136

def total
  @total
end

#unit_priceObject (readonly)

Returns the value of attribute unit_price.



47136
47137
47138
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47136

def unit_price
  @unit_price
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



47158
47159
47160
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47158

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

#to_hashObject



47162
47163
47164
47165
47166
47167
47168
47169
47170
47171
47172
47173
47174
47175
47176
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47162

def to_hash
  {
    :id => id,
    :item => item.to_hash,
    :errors => errors.nil? ? nil : errors.map { |o| o.to_hash },
    :quantity => quantity,
    :discount => discount.nil? ? nil : discount.to_hash,
    :tax => tax.nil? ? nil : tax.to_hash,
    :duty => duty.nil? ? nil : duty.to_hash,
    :unit_price => unit_price.to_hash,
    :total => total.to_hash,
    :price_attributes => price_attributes.inject({}) { |hash, o| hash[o[0]] = o[1].nil? ? nil : o[1].to_hash; hash },
    :attributes => attributes
  }
end

#to_jsonObject



47154
47155
47156
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 47154

def to_json
  JSON.dump(to_hash)
end