Class: Io::Flow::V0::Models::Token

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

Defined Under Namespace

Modules: Types

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Token

Returns a new instance of Token.



4804
4805
4806
4807
4808
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4804

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

Class Method Details

.from_json(hash) ⇒ Object



4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4818

def Token.from_json(hash)
  HttpClient::Preconditions.assert_class('hash', hash, Hash)
  discriminator = HttpClient::Helper.symbolize_keys(hash)[:discriminator].to_s.strip
  if discriminator.empty?
    raise "Union type[token] requires a field named 'discriminator'"
  end
  case discriminator
    when Types::ORGANIZATION_TOKEN; OrganizationToken.new(hash)
    when Types::PARTNER_TOKEN; PartnerToken.new(hash)
    else TokenUndefinedType.new(:name => discriminator)
  end
end

Instance Method Details

#subtype_to_hashObject



4810
4811
4812
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4810

def subtype_to_hash
  raise 'Cannot serialize an instance of token directly - must use one of the specific types: organization_token, partner_token'
end

#to_hashObject



4814
4815
4816
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 4814

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