Class: UspsApi::CommonContact

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

Overview

CommonContact Model.

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(contact_name: SKIP, telephone: SKIP, mobile_phone: SKIP, email: SKIP, fax: SKIP, contact_id: SKIP, contact_type: SKIP, additional_properties: nil) ⇒ CommonContact

Returns a new instance of CommonContact.



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/usps_api/models/common_contact.rb', line 71

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

  @contact_name = contact_name unless contact_name == SKIP
  @telephone = telephone unless telephone == SKIP
  @mobile_phone = mobile_phone unless mobile_phone == SKIP
  @email = email unless email == SKIP
  @fax = fax unless fax == SKIP
  @contact_id = contact_id unless contact_id == SKIP
  @contact_type = contact_type unless contact_type == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#contact_idContactId

Identification details for the appointment requestor.

Returns:



34
35
36
# File 'lib/usps_api/models/common_contact.rb', line 34

def contact_id
  @contact_id
end

#contact_nameString

Contact name

Returns:

  • (String)


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

def contact_name
  @contact_name
end

#contact_typeContactType

Carrier contact type

Returns:



38
39
40
# File 'lib/usps_api/models/common_contact.rb', line 38

def contact_type
  @contact_type
end

#emailString

Email address of contact

Returns:

  • (String)


26
27
28
# File 'lib/usps_api/models/common_contact.rb', line 26

def email
  @email
end

#faxString

Fax number of the contact, numbers only, no delimeters, optional +

Returns:

  • (String)


30
31
32
# File 'lib/usps_api/models/common_contact.rb', line 30

def fax
  @fax
end

#mobile_phoneString

Cell phone number of contact, numbers only, no delimeters, optional + sign

Returns:

  • (String)


22
23
24
# File 'lib/usps_api/models/common_contact.rb', line 22

def mobile_phone
  @mobile_phone
end

#telephoneString

Phone number of contact, numbers only, no delimeters, optional + sign

Returns:

  • (String)


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

def telephone
  @telephone
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/usps_api/models/common_contact.rb', line 88

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  contact_name = hash.key?('contactName') ? hash['contactName'] : SKIP
  telephone = hash.key?('telephone') ? hash['telephone'] : SKIP
  mobile_phone = hash.key?('mobilePhone') ? hash['mobilePhone'] : SKIP
  email = hash.key?('email') ? hash['email'] : SKIP
  fax = hash.key?('fax') ? hash['fax'] : SKIP
  contact_id = ContactId.from_hash(hash['contactID']) if hash['contactID']
  contact_type = hash.key?('contactType') ? hash['contactType'] : 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.
  CommonContact.new(contact_name: contact_name,
                    telephone: telephone,
                    mobile_phone: mobile_phone,
                    email: email,
                    fax: fax,
                    contact_id: contact_id,
                    contact_type: contact_type,
                    additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/usps_api/models/common_contact.rb', line 41

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['contact_name'] = 'contactName'
  @_hash['telephone'] = 'telephone'
  @_hash['mobile_phone'] = 'mobilePhone'
  @_hash['email'] = 'email'
  @_hash['fax'] = 'fax'
  @_hash['contact_id'] = 'contactID'
  @_hash['contact_type'] = 'contactType'
  @_hash
end

.nullablesObject

An array for nullable fields



67
68
69
# File 'lib/usps_api/models/common_contact.rb', line 67

def self.nullables
  []
end

.optionalsObject

An array for optional fields



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/usps_api/models/common_contact.rb', line 54

def self.optionals
  %w[
    contact_name
    telephone
    mobile_phone
    email
    fax
    contact_id
    contact_type
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



127
128
129
130
131
132
133
# File 'lib/usps_api/models/common_contact.rb', line 127

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

#to_sObject

Provides a human-readable string representation of the object.



119
120
121
122
123
124
# File 'lib/usps_api/models/common_contact.rb', line 119

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