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

Returns a new instance of ServiceFee.



14159
14160
14161
14162
14163
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14159

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.



14157
14158
14159
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14157

def discriminator
  @discriminator
end

Class Method Details

.from_json(hash) ⇒ Object



14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14173

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::FUEL_SURCHARGE_AMOUNT_BY_WEIGHT_SERVICE_FEE; FuelSurchargeAmountByWeightServiceFee.new(hash)
    when Types::REMOTE_AREA_SERVICE_FEE; RemoteAreaServiceFee.new(hash)
    when Types::EMERGENCY_SITUATION_SURCHARGE_SERVICE_FEE; EmergencySituationSurchargeServiceFee.new(hash)
    when Types::PEAK_SURCHARGE_SERVICE_FEE; PeakSurchargeServiceFee.new(hash)
    when Types::PEAK_SURCHARGE_BY_WEIGHT_SERVICE_FEE; PeakSurchargeByWeightServiceFee.new(hash)
    when Types::DUTIES_TAXES_PAID_SURCHARGE_SERVICE_FEE; DutiesTaxesPaidSurchargeServiceFee.new(hash)
    else ServiceFeeUndefinedType.new(:discriminator => discriminator)
  end
end

Instance Method Details

#subtype_to_hashObject



14165
14166
14167
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14165

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

#to_hashObject



14169
14170
14171
# File 'lib/flow_commerce/flow_api_v0_client.rb', line 14169

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