Class: Io::Flow::V0::Models::HopEstimate

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ HopEstimate

Returns a new instance of HopEstimate.



32085
32086
32087
32088
32089
32090
32091
32092
32093
32094
32095
32096
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32085

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:origin_address, :destination_address, :service, :shipment_window, :currency, :amount, :fees, :total], 'HopEstimate')
  @origin_address = (x = opts.delete(:origin_address); x.is_a?(::Io::Flow::V0::Models::ShippingAddress) ? x : ::Io::Flow::V0::Models::ShippingAddress.new(x))
  @destination_address = (x = opts.delete(:destination_address); x.is_a?(::Io::Flow::V0::Models::ShippingAddress) ? x : ::Io::Flow::V0::Models::ShippingAddress.new(x))
  @service = (x = opts.delete(:service); x.is_a?(::Io::Flow::V0::Models::RatecardServiceSummary) ? x : ::Io::Flow::V0::Models::RatecardServiceSummary.new(x))
  @shipment_window = (x = opts.delete(:shipment_window); x.is_a?(::Io::Flow::V0::Models::ShipmentWindow) ? x : ::Io::Flow::V0::Models::ShipmentWindow.new(x))
  @currency = HttpClient::Preconditions.assert_class('currency', opts.delete(:currency), String)
  @amount = HttpClient::Preconditions.assert_class('amount', opts.delete(:amount), Numeric)
  @fees = HttpClient::Preconditions.assert_class('fees', opts.delete(:fees), Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::RatecardFee) ? x : ::Io::Flow::V0::Models::RatecardFee.from_json(x)) }
  @total = HttpClient::Preconditions.assert_class('total', opts.delete(:total), Numeric)
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



32083
32084
32085
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32083

def amount
  @amount
end

#currencyObject (readonly)

Returns the value of attribute currency.



32083
32084
32085
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32083

def currency
  @currency
end

#destination_addressObject (readonly)

Returns the value of attribute destination_address.



32083
32084
32085
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32083

def destination_address
  @destination_address
end

#feesObject (readonly)

Returns the value of attribute fees.



32083
32084
32085
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32083

def fees
  @fees
end

#origin_addressObject (readonly)

Returns the value of attribute origin_address.



32083
32084
32085
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32083

def origin_address
  @origin_address
end

#serviceObject (readonly)

Returns the value of attribute service.



32083
32084
32085
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32083

def service
  @service
end

#shipment_windowObject (readonly)

Returns the value of attribute shipment_window.



32083
32084
32085
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32083

def shipment_window
  @shipment_window
end

#totalObject (readonly)

Returns the value of attribute total.



32083
32084
32085
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32083

def total
  @total
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



32102
32103
32104
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32102

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

#to_hashObject



32106
32107
32108
32109
32110
32111
32112
32113
32114
32115
32116
32117
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32106

def to_hash
  {
    :origin_address => origin_address.to_hash,
    :destination_address => destination_address.to_hash,
    :service => service.to_hash,
    :shipment_window => shipment_window.to_hash,
    :currency => currency,
    :amount => amount,
    :fees => fees.map { |o| o.to_hash },
    :total => total
  }
end

#to_jsonObject



32098
32099
32100
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 32098

def to_json
  JSON.dump(to_hash)
end