Class: Io::Flow::V0::Models::ServiceFee

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



10513
10514
10515
10516
10517
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 10513

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

Instance Attribute Details

#discriminatorObject (readonly)

Returns the value of attribute discriminator.



10511
10512
10513
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 10511

def discriminator
  @discriminator
end

Class Method Details

.from_json(hash) ⇒ Object



10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 10527

def ServiceFee.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[service_fee] requires a field named 'discriminator'"
  end
  case discriminator
    when Types::FUEL_SURCHARGE_SERVICE_FEE; FuelSurchargeServiceFee.new(hash)
    when Types::REMOTE_AREA_SERVICE_FEE; RemoteAreaServiceFee.new(hash)
    else ServiceFeeUndefinedType.new(:discriminator => discriminator)
  end
end

Instance Method Details

#subtype_to_hashObject



10519
10520
10521
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 10519

def subtype_to_hash
  raise 'Cannot serialize an instance of service_fee directly - must use one of the specific types: fuel_surcharge_service_fee, remote_area_service_fee'
end

#to_hashObject



10523
10524
10525
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 10523

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