Class: Io::Flow::V0::Models::Shipping

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 = {}) ⇒ Shipping

Returns a new instance of Shipping.



65874
65875
65876
65877
65878
65879
65880
65881
65882
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 65874

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:description, :amount], 'Shipping')
  @description = HttpClient::Preconditions.assert_class('description', opts.delete(:description), String)
  @amount = HttpClient::Preconditions.assert_class('amount', HttpClient::Helper.to_big_decimal(opts.delete(:amount)), BigDecimal)
  @tax = (x = opts.delete(:tax); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::PaymentTax) ? x : ::Io::Flow::V0::Models::PaymentTax.new(x)))
  @duty = (x = opts.delete(:duty); x.nil? ? nil : (x = x; x.is_a?(::Io::Flow::V0::Models::PaymentDuty) ? x : ::Io::Flow::V0::Models::PaymentDuty.new(x)))
  @discounts = (x = opts.delete(:discounts); x.nil? ? nil : HttpClient::Preconditions.assert_class('discounts', x, Array).map { |v| (x = v; x.is_a?(::Io::Flow::V0::Models::PaymentDiscount) ? x : ::Io::Flow::V0::Models::PaymentDiscount.new(x)) })
end

Instance Attribute Details

#amountObject (readonly)

Returns the value of attribute amount.



65872
65873
65874
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 65872

def amount
  @amount
end

#descriptionObject (readonly)

Returns the value of attribute description.



65872
65873
65874
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 65872

def description
  @description
end

#discountsObject (readonly)

Returns the value of attribute discounts.



65872
65873
65874
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 65872

def discounts
  @discounts
end

#dutyObject (readonly)

Returns the value of attribute duty.



65872
65873
65874
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 65872

def duty
  @duty
end

#taxObject (readonly)

Returns the value of attribute tax.



65872
65873
65874
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 65872

def tax
  @tax
end

Instance Method Details

#copy(incoming = {}) ⇒ Object



65888
65889
65890
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 65888

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

#to_hashObject



65892
65893
65894
65895
65896
65897
65898
65899
65900
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 65892

def to_hash
  {
    :description => description,
    :amount => amount.to_f.to_s,
    :tax => tax.nil? ? nil : tax.to_hash,
    :duty => duty.nil? ? nil : duty.to_hash,
    :discounts => discounts.nil? ? nil : discounts.map { |o| o.to_hash }
  }
end

#to_jsonObject



65884
65885
65886
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 65884

def to_json
  JSON.dump(to_hash)
end