Class: Io::Flow::V0::Models::Promotion

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

Direct Known Subclasses

Discount, FreeShipping, PromotionUndefinedType

Defined Under Namespace

Modules: Types

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(incoming = {}) ⇒ Promotion

Returns a new instance of Promotion.



14535
14536
14537
14538
14539
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14535

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

Instance Attribute Details

#discriminatorObject (readonly)

Returns the value of attribute discriminator.



14533
14534
14535
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14533

def discriminator
  @discriminator
end

Class Method Details

.from_json(hash) ⇒ Object



14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14549

def Promotion.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[promotion] requires a field named 'discriminator'"
  end
  case discriminator
    when Types::FREE_SHIPPING; FreeShipping.new(hash)
    when Types::DISCOUNT; Discount.new(hash)
    else PromotionUndefinedType.new(:discriminator => discriminator)
  end
end

Instance Method Details

#subtype_to_hashObject



14541
14542
14543
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14541

def subtype_to_hash
  raise 'Cannot serialize an instance of promotion directly - must use one of the specific types: free_shipping, discount'
end

#to_hashObject



14545
14546
14547
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14545

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