Class: Io::Flow::V0::Models::LocalizedPrice

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

Overview

The localized prices for an item are returned as a list - the key of each element is defined here

Defined Under Namespace

Modules: Types

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ LocalizedPrice

Returns a new instance of LocalizedPrice.



6968
6969
6970
6971
6972
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6968

def initialize(incoming={})
  opts = HttpClient::Helper.symbolize_keys(incoming)
  HttpClient::Preconditions.require_keys(opts, [:key], 'LocalizedPrice')
  @key = HttpClient::Preconditions.assert_class('key', opts.delete(:key), String)
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



6966
6967
6968
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6966

def key
  @key
end

Class Method Details

.from_json(hash) ⇒ Object



6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6982

def LocalizedPrice.from_json(hash)
  HttpClient::Preconditions.assert_class('hash', hash, Hash)
  discriminator = HttpClient::Helper.symbolize_keys(hash)[:key].to_s.strip
  if discriminator.empty?
    raise "Union type[localized_price] requires a field named 'key'"
  end
  case discriminator
    when Types::LOCALIZED_ITEM_PRICE; LocalizedItemPrice.new(hash)
    when Types::LOCALIZED_ITEM_VAT; LocalizedItemVat.new(hash)
    when Types::LOCALIZED_ITEM_DUTY; LocalizedItemDuty.new(hash)
    when Types::LOCALIZED_TOTAL; LocalizedTotal.new(hash)
    else LocalizedPriceUndefinedType.new(:key => discriminator)
  end
end

Instance Method Details

#subtype_to_hashObject



6974
6975
6976
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6974

def subtype_to_hash
  raise 'Cannot serialize an instance of localized_price directly - must use one of the specific types: localized_item_price, localized_item_vat, localized_item_duty, localized_total'
end

#to_hashObject



6978
6979
6980
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 6978

def to_hash
  subtype_to_hash.merge(:key => @key)
end