Class: Io::Flow::V0::Models::OrderEstimate

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

Overview

Lightweight estimate for a group of items without any customer-related information. This will contain available estimates on shipping, taxes, and duties.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ OrderEstimate

Returns a new instance of OrderEstimate.



51792
51793
51794
51795
51796
51797
51798
51799
51800
51801
51802
51803
51804
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 51792

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :items, :destination, :deliveries, :prices, :selections, :total], 'OrderEstimate')
  @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::LocalizedLineItem) ? x : ::Io::Flow::V0::Models::LocalizedLineItem.new(x)) }
  @destination = (x = opts.delete(:destination); x.is_a?(::Io::Flow::V0::Models::OrderAddress) ? x : ::Io::Flow::V0::Models::OrderAddress.new(x))
  @deliveries = HttpClient::Preconditions.assert_class('deliveries', opts.delete(:deliveries), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::Delivery) ? x : ::Io::Flow::V0::Models::Delivery.from_json(x)) }
  @prices = HttpClient::Preconditions.assert_class('prices', opts.delete(:prices), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::OrderPriceDetail) ? x : ::Io::Flow::V0::Models::OrderPriceDetail.new(x)) }
  @selections = HttpClient::Preconditions.assert_class('selections', opts.delete(:selections), Array).map { |v| HttpClient::Preconditions.assert_class('selections', v, String) }
  @total = (x = opts.delete(:total); x.is_a?(::Io::Flow::V0::Models::LocalizedTotal) ? x : ::Io::Flow::V0::Models::LocalizedTotal.new(x))
  @lines = (x = opts.delete(:lines); x.nil? ? nil : HttpClient::Preconditions.assert_class('lines', x, Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::Line) ? x : ::Io::Flow::V0::Models::Line.new(x)) })
  @promotions = (x = opts.delete(:promotions); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::Promotions) ? x : ::Io::Flow::V0::Models::Promotions.new(x)))
end

Instance Attribute Details

#deliveriesObject (readonly)

Returns the value of attribute deliveries.



51790
51791
51792
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 51790

def deliveries
  @deliveries
end

#destinationObject (readonly)

Returns the value of attribute destination.



51790
51791
51792
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 51790

def destination
  @destination
end

#idObject (readonly)

Returns the value of attribute id.



51790
51791
51792
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 51790

def id
  @id
end

#itemsObject (readonly)

Returns the value of attribute items.



51790
51791
51792
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 51790

def items
  @items
end

#linesObject (readonly)

Returns the value of attribute lines.



51790
51791
51792
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 51790

def lines
  @lines
end

#pricesObject (readonly)

Returns the value of attribute prices.



51790
51791
51792
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 51790

def prices
  @prices
end

#promotionsObject (readonly)

Returns the value of attribute promotions.



51790
51791
51792
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 51790

def promotions
  @promotions
end

#selectionsObject (readonly)

Returns the value of attribute selections.



51790
51791
51792
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 51790

def selections
  @selections
end

#totalObject (readonly)

Returns the value of attribute total.



51790
51791
51792
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 51790

def total
  @total
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



51810
51811
51812
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 51810

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

#to_hashObject



51814
51815
51816
51817
51818
51819
51820
51821
51822
51823
51824
51825
51826
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 51814

def to_hash
  {
    :id => id,
    :items => items.map { |o| o.to_hash },
    :destination => destination.to_hash,
    :deliveries => deliveries.map { |o| o.to_hash },
    :prices => prices.map { |o| o.to_hash },
    :selections => selections,
    :total => total.to_hash,
    :lines => lines.nil? ? nil : lines.map { |o| o.to_hash },
    :promotions => promotions.nil? ? nil : promotions.to_hash
  }
end

#to_jsonObject



51806
51807
51808
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 51806

def to_json
  JSON.dump(to_hash)
end