Class: UspsApi::InternationalPricingOption

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/usps_api/models/international_pricing_option.rb

Overview

Option for international pricing

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(shipping_options: SKIP, price_type: ShipmentsPriceType1::COMMERCIAL, payment_account: SKIP) ⇒ InternationalPricingOption

Returns a new instance of InternationalPricingOption.



49
50
51
52
53
54
55
# File 'lib/usps_api/models/international_pricing_option.rb', line 49

def initialize(shipping_options: SKIP,
               price_type: ShipmentsPriceType1::COMMERCIAL,
               payment_account: SKIP)
  @shipping_options = shipping_options unless shipping_options == SKIP
  @price_type = price_type unless price_type == SKIP
  @payment_account =  unless  == SKIP
end

Instance Attribute Details

#payment_accountShipmentsPaymentAccount

Payment account information. Used only if ‘priceType` is `CONTRACT`.



24
25
26
# File 'lib/usps_api/models/international_pricing_option.rb', line 24

def 
  @payment_account
end

#price_typeShipmentsPriceType1

Price type of the Shipping Request. Note:

  • If ‘priceType` is `CONTRACT`, `paymentAccount` is required.

Returns:



20
21
22
# File 'lib/usps_api/models/international_pricing_option.rb', line 20

def price_type
  @price_type
end

#shipping_optionsArray[InternationalOptions]

List of available shipping services and delivery options for the package

Returns:



14
15
16
# File 'lib/usps_api/models/international_pricing_option.rb', line 14

def shipping_options
  @shipping_options
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/usps_api/models/international_pricing_option.rb', line 58

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  # Parameter is an array, so we need to iterate through it
  shipping_options = nil
  unless hash['shippingOptions'].nil?
    shipping_options = []
    hash['shippingOptions'].each do |structure|
      shipping_options << (InternationalOptions.from_hash(structure) if structure)
    end
  end

  shipping_options = SKIP unless hash.key?('shippingOptions')
  price_type = hash['priceType'] ||= ShipmentsPriceType1::COMMERCIAL
   = ShipmentsPaymentAccount.from_hash(hash['paymentAccount']) if
    hash['paymentAccount']

  # Create object from extracted values.
  InternationalPricingOption.new(shipping_options: shipping_options,
                                 price_type: price_type,
                                 payment_account: )
end

.namesObject

A mapping from model property names to API property names.



27
28
29
30
31
32
33
# File 'lib/usps_api/models/international_pricing_option.rb', line 27

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['shipping_options'] = 'shippingOptions'
  @_hash['price_type'] = 'priceType'
  @_hash['payment_account'] = 'paymentAccount'
  @_hash
end

.nullablesObject

An array for nullable fields



45
46
47
# File 'lib/usps_api/models/international_pricing_option.rb', line 45

def self.nullables
  []
end

.optionalsObject

An array for optional fields



36
37
38
39
40
41
42
# File 'lib/usps_api/models/international_pricing_option.rb', line 36

def self.optionals
  %w[
    shipping_options
    price_type
    payment_account
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



84
85
86
87
88
89
90
# File 'lib/usps_api/models/international_pricing_option.rb', line 84

def self.validate(value)
  return true if value.instance_of? self

  return false unless value.instance_of? Hash

  true
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



100
101
102
103
104
# File 'lib/usps_api/models/international_pricing_option.rb', line 100

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} shipping_options: #{@shipping_options.inspect}, price_type:"\
  " #{@price_type.inspect}, payment_account: #{@payment_account.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



93
94
95
96
97
# File 'lib/usps_api/models/international_pricing_option.rb', line 93

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} shipping_options: #{@shipping_options}, price_type: #{@price_type},"\
  " payment_account: #{@payment_account}>"
end