Class: UspsApi::Contact

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

Overview

Contact information for customs reference. When multiple contact methods are provided, the customs form will prioritize printing phone number, then email address, then the fax number. All contact methods will be manifested electronically.

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(phone: SKIP, fax: SKIP, email: SKIP, additional_properties: nil) ⇒ Contact

Returns a new instance of Contact.



52
53
54
55
56
57
58
59
60
61
# File 'lib/usps_api/models/contact.rb', line 52

def initialize(phone: SKIP, fax: SKIP, email: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @phone = phone unless phone == SKIP
  @fax = fax unless fax == SKIP
  @email = email unless email == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#emailString

Email address used for redirect notification via email.

Returns:

  • (String)


27
28
29
# File 'lib/usps_api/models/contact.rb', line 27

def email
  @email
end

#faxString

The phone number, including the country extension and area code or the local national format, with no punctuation.

Returns:

  • (String)


23
24
25
# File 'lib/usps_api/models/contact.rb', line 23

def fax
  @fax
end

#phoneString

The phone number, including the country extension and area code or the local national format, with no punctuation.

Returns:

  • (String)


18
19
20
# File 'lib/usps_api/models/contact.rb', line 18

def phone
  @phone
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/usps_api/models/contact.rb', line 64

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  phone = hash.key?('phone') ? hash['phone'] : SKIP
  fax = hash.key?('fax') ? hash['fax'] : SKIP
  email = hash.key?('email') ? hash['email'] : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  Contact.new(phone: phone,
              fax: fax,
              email: email,
              additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



30
31
32
33
34
35
36
# File 'lib/usps_api/models/contact.rb', line 30

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['phone'] = 'phone'
  @_hash['fax'] = 'fax'
  @_hash['email'] = 'email'
  @_hash
end

.nullablesObject

An array for nullable fields



48
49
50
# File 'lib/usps_api/models/contact.rb', line 48

def self.nullables
  []
end

.optionalsObject

An array for optional fields



39
40
41
42
43
44
45
# File 'lib/usps_api/models/contact.rb', line 39

def self.optionals
  %w[
    phone
    fax
    email
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



94
95
96
97
98
# File 'lib/usps_api/models/contact.rb', line 94

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

#to_sObject

Provides a human-readable string representation of the object.



87
88
89
90
91
# File 'lib/usps_api/models/contact.rb', line 87

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} phone: #{@phone}, fax: #{@fax}, email: #{@email}, additional_properties:"\
  " #{@additional_properties}>"
end