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.



20166
20167
20168
20169
20170
20171
20172
20173
20174
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 20166

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :destination, :deliveries, :selections], '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.new(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))
end

Instance Attribute Details

#delivered_dutyObject (readonly)

Returns the value of attribute delivered_duty.



20164
20165
20166
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 20164

def delivered_duty
  @delivered_duty
end

#deliveriesObject (readonly)

Returns the value of attribute deliveries.



20164
20165
20166
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 20164

def deliveries
  @deliveries
end

#destinationObject (readonly)

Returns the value of attribute destination.



20164
20165
20166
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 20164

def destination
  @destination
end

#idObject (readonly)

Returns the value of attribute id.



20164
20165
20166
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 20164

def id
  @id
end

#selectionsObject (readonly)

Returns the value of attribute selections.



20164
20165
20166
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 20164

def selections
  @selections
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



20180
20181
20182
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 20180

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

#to_hashObject



20184
20185
20186
20187
20188
20189
20190
20191
20192
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 20184

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
  }
end

#to_jsonObject



20176
20177
20178
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 20176

def to_json
  JSON.dump(to_hash)
end