Class: Io::Flow::V0::Models::Quote

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

Overview

Represents a collection of deliveries and available options for fulfillment of that delivery

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Quote

Returns a new instance of Quote.



56673
56674
56675
56676
56677
56678
56679
56680
56681
56682
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56673

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :destination, :deliveries, :selections, :delivered_duties], 'Quote')
  @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
  @destination = (x = opts.delete(:destination); x.is_a?(::Io::Flow::V0::Models::ShippingAddress) ? x : ::Io::Flow::V0::Models::ShippingAddress.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)) }
  @selections = HttpClient::Preconditions.assert_class('selections', opts.delete(:selections), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::DeliveryOptionReference) ? x : ::Io::Flow::V0::Models::DeliveryOptionReference.new(x)) }
  @delivered_duty = (x = (x = opts.delete(:delivered_duty); x.nil? ? "paid" : x); x.is_a?(::Io::Flow::V0::Models::DeliveredDuty) ? x : ::Io::Flow::V0::Models::DeliveredDuty.apply(x))
  @delivered_duties = HttpClient::Preconditions.assert_class('delivered_duties', opts.delete(:delivered_duties), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::DeliveredDuty) ? x : ::Io::Flow::V0::Models::DeliveredDuty.apply(x)) }
end

Instance Attribute Details

#delivered_dutiesObject (readonly)

Returns the value of attribute delivered_duties.



56671
56672
56673
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56671

def delivered_duties
  @delivered_duties
end

#delivered_dutyObject (readonly)

Returns the value of attribute delivered_duty.



56671
56672
56673
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56671

def delivered_duty
  @delivered_duty
end

#deliveriesObject (readonly)

Returns the value of attribute deliveries.



56671
56672
56673
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56671

def deliveries
  @deliveries
end

#destinationObject (readonly)

Returns the value of attribute destination.



56671
56672
56673
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56671

def destination
  @destination
end

#idObject (readonly)

Returns the value of attribute id.



56671
56672
56673
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56671

def id
  @id
end

#selectionsObject (readonly)

Returns the value of attribute selections.



56671
56672
56673
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56671

def selections
  @selections
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



56688
56689
56690
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56688

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

#to_hashObject



56692
56693
56694
56695
56696
56697
56698
56699
56700
56701
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56692

def to_hash
  {
    :id => id,
    :destination => destination.to_hash,
    :deliveries => deliveries.map { |o| o.to_hash },
    :selections => selections.map { |o| o.to_hash },
    :delivered_duty => delivered_duty.value,
    :delivered_duties => delivered_duties.map { |o| o.value }
  }
end

#to_jsonObject



56684
56685
56686
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 56684

def to_json
  JSON.dump(to_hash)
end