Class: Io::Flow::V0::Models::DeliveryOption

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

Overview

Represents a way to fulfill a delivery, including an estimates for the date range and cost

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ DeliveryOption

Returns a new instance of DeliveryOption.



11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11531

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:id, :cost, :delivered_duty, :price, :service, :tier, :window], 'DeliveryOption')
  @id = HttpClient::Preconditions.assert_class('id', opts.delete(:id), String)
  @cost = (x = opts.delete(:cost); x.is_a?(::Io::Flow::V0::Models::PriceWithBase) ? x : ::Io::Flow::V0::Models::PriceWithBase.new(x))
  @delivered_duty = (x = opts.delete(:delivered_duty); x.is_a?(::Io::Flow::V0::Models::DeliveredDuty) ? x : ::Io::Flow::V0::Models::DeliveredDuty.apply(x))
  @price = (x = opts.delete(:price); x.is_a?(::Io::Flow::V0::Models::PriceWithBase) ? x : ::Io::Flow::V0::Models::PriceWithBase.new(x))
  @service = (x = opts.delete(:service); x.is_a?(::Io::Flow::V0::Models::ServiceSummary) ? x : ::Io::Flow::V0::Models::ServiceSummary.new(x))
  @tier = (x = opts.delete(:tier); x.is_a?(::Io::Flow::V0::Models::TierSummary) ? x : ::Io::Flow::V0::Models::TierSummary.new(x))
  @window = (x = opts.delete(:window); x.is_a?(::Io::Flow::V0::Models::DatetimeRange) ? x : ::Io::Flow::V0::Models::DatetimeRange.new(x))
  @weight = (x = opts.delete(:weight); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::OptionWeightEstimates) ? x : ::Io::Flow::V0::Models::OptionWeightEstimates.new(x)))
end

Instance Attribute Details

#cost ⇒ Object (readonly)

Returns the value of attribute cost.



11529
11530
11531
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11529

def cost
  @cost
end

#delivered_duty ⇒ Object (readonly)

Returns the value of attribute delivered_duty.



11529
11530
11531
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11529

def delivered_duty
  @delivered_duty
end

#id ⇒ Object (readonly)

Returns the value of attribute id.



11529
11530
11531
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11529

def id
  @id
end

#price ⇒ Object (readonly)

Returns the value of attribute price.



11529
11530
11531
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11529

def price
  @price
end

#service ⇒ Object (readonly)

Returns the value of attribute service.



11529
11530
11531
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11529

def service
  @service
end

#tier ⇒ Object (readonly)

Returns the value of attribute tier.



11529
11530
11531
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11529

def tier
  @tier
end

#weight ⇒ Object (readonly)

Returns the value of attribute weight.



11529
11530
11531
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11529

def weight
  @weight
end

#window ⇒ Object (readonly)

Returns the value of attribute window.



11529
11530
11531
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11529

def window
  @window
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



11548
11549
11550
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11548

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

#to_hash ⇒ Object



11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11552

def to_hash
  {
    :id => id,
    :cost => cost.to_hash,
    :delivered_duty => delivered_duty.value,
    :price => price.to_hash,
    :service => service.to_hash,
    :tier => tier.to_hash,
    :window => window.to_hash,
    :weight => weight.nil? ? nil : weight.to_hash
  }
end

#to_json ⇒ Object



11544
11545
11546
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 11544

def to_json
  JSON.dump(to_hash)
end