Class: UspsApi::InternationalOptions

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

Overview

Options specific to international shipments

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(mail_class: SKIP, rate_options: SKIP) ⇒ InternationalOptions

Returns a new instance of InternationalOptions.



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

def initialize(mail_class: SKIP, rate_options: SKIP)
  @mail_class = mail_class unless mail_class == SKIP
  @rate_options = rate_options unless rate_options == SKIP
end

Instance Attribute Details

#mail_classMailClass4

The international mail service requested. Note:

  • ‘GLOBAL_EXPRESS_GUARANTEED` - Global Express Guaranteed Service is

suspended as of September 29, 2024.

Returns:



17
18
19
# File 'lib/usps_api/models/international_options.rb', line 17

def mail_class
  @mail_class
end

#rate_optionsArray[InternationalRateOptions]

List of rate options

Returns:



21
22
23
# File 'lib/usps_api/models/international_options.rb', line 21

def rate_options
  @rate_options
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/usps_api/models/international_options.rb', line 50

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  mail_class = hash.key?('mailClass') ? hash['mailClass'] : SKIP
  # Parameter is an array, so we need to iterate through it
  rate_options = nil
  unless hash['rateOptions'].nil?
    rate_options = []
    hash['rateOptions'].each do |structure|
      rate_options << (InternationalRateOptions.from_hash(structure) if structure)
    end
  end

  rate_options = SKIP unless hash.key?('rateOptions')

  # Create object from extracted values.
  InternationalOptions.new(mail_class: mail_class,
                           rate_options: rate_options)
end

.namesObject

A mapping from model property names to API property names.



24
25
26
27
28
29
# File 'lib/usps_api/models/international_options.rb', line 24

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['mail_class'] = 'mailClass'
  @_hash['rate_options'] = 'rateOptions'
  @_hash
end

.nullablesObject

An array for nullable fields



40
41
42
# File 'lib/usps_api/models/international_options.rb', line 40

def self.nullables
  []
end

.optionalsObject

An array for optional fields



32
33
34
35
36
37
# File 'lib/usps_api/models/international_options.rb', line 32

def self.optionals
  %w[
    mail_class
    rate_options
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



73
74
75
76
77
78
79
# File 'lib/usps_api/models/international_options.rb', line 73

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.



88
89
90
91
92
# File 'lib/usps_api/models/international_options.rb', line 88

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

#to_sObject

Provides a human-readable string representation of the object.



82
83
84
85
# File 'lib/usps_api/models/international_options.rb', line 82

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} mail_class: #{@mail_class}, rate_options: #{@rate_options}>"
end