Class: Io::Flow::V0::Models::Document

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

Defined Under Namespace

Modules: Types

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Document

Returns a new instance of Document.



10859
10860
10861
10862
10863
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 10859

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

Instance Attribute Details

#discriminatorObject (readonly)

Returns the value of attribute discriminator.



10857
10858
10859
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 10857

def discriminator
  @discriminator
end

Class Method Details

.from_json(hash) ⇒ Object



10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 10873

def Document.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[document] requires a field named 'discriminator'"
  end
  case discriminator
    when Types::CATALOG_ITEM_DOCUMENT; CatalogItemDocument.new(hash)
    when Types::HARMONIZATION_DOCUMENT; HarmonizationDocument.new(hash)
    else DocumentUndefinedType.new(:discriminator => discriminator)
  end
end

Instance Method Details

#subtype_to_hashObject



10865
10866
10867
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 10865

def subtype_to_hash
  raise 'Cannot serialize an instance of document directly - must use one of the specific types: catalog_item_document, harmonization_document'
end

#to_hashObject



10869
10870
10871
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 10869

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