Class: WhatsAppCloudApi::Contact
- Defined in:
- lib/whats_app_cloud_api/models/contact.rb
Overview
Contact Model.
Instance Attribute Summary collapse
-
#addresses ⇒ List of Address
Full contact address(es).
-
#birthday ⇒ String
Full contact address(es).
-
#emails ⇒ List of EmailObject
Contact email address(es).
-
#name ⇒ Name
Full contact name.
-
#org ⇒ Org
Contact organization information.
-
#phones ⇒ List of PhoneObject
Contact phone number(s).
-
#urls ⇒ List of UrlObject
Contact URL(s).
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
-
.names ⇒ Object
A mapping from model property names to API property names.
Instance Method Summary collapse
-
#initialize(name = nil, addresses = nil, birthday = 'YYYY-MM-DD formatted string.', emails = nil, org = nil, phones = nil, urls = nil) ⇒ Contact
constructor
A new instance of Contact.
-
#nullables ⇒ Object
An array for nullable fields.
-
#optionals ⇒ Object
An array for optional fields.
Methods inherited from BaseModel
Constructor Details
#initialize(name = nil, addresses = nil, birthday = 'YYYY-MM-DD formatted string.', emails = nil, org = nil, phones = nil, urls = nil) ⇒ Contact
Returns a new instance of Contact.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/whats_app_cloud_api/models/contact.rb', line 70 def initialize(name = nil, addresses = nil, birthday = 'YYYY-MM-DD formatted string.', emails = nil, org = nil, phones = nil, urls = nil) @addresses = addresses unless addresses == SKIP @birthday = birthday unless birthday == SKIP @emails = emails unless emails == SKIP @name = name unless name == SKIP @org = org unless org == SKIP @phones = phones unless phones == SKIP @urls = urls unless urls == SKIP end |
Instance Attribute Details
#addresses ⇒ List of Address
Full contact address(es)
14 15 16 |
# File 'lib/whats_app_cloud_api/models/contact.rb', line 14 def addresses @addresses end |
#birthday ⇒ String
Full contact address(es)
18 19 20 |
# File 'lib/whats_app_cloud_api/models/contact.rb', line 18 def birthday @birthday end |
#emails ⇒ List of EmailObject
Contact email address(es)
22 23 24 |
# File 'lib/whats_app_cloud_api/models/contact.rb', line 22 def emails @emails end |
#name ⇒ Name
Full contact name
26 27 28 |
# File 'lib/whats_app_cloud_api/models/contact.rb', line 26 def name @name end |
#org ⇒ Org
Contact organization information
30 31 32 |
# File 'lib/whats_app_cloud_api/models/contact.rb', line 30 def org @org end |
#phones ⇒ List of PhoneObject
Contact phone number(s)
34 35 36 |
# File 'lib/whats_app_cloud_api/models/contact.rb', line 34 def phones @phones end |
#urls ⇒ List of UrlObject
Contact URL(s)
38 39 40 |
# File 'lib/whats_app_cloud_api/models/contact.rb', line 38 def urls @urls end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates an instance of the object from a hash.
87 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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/whats_app_cloud_api/models/contact.rb', line 87 def self.from_hash(hash) return nil unless hash # Extract variables from the hash. name = Name.from_hash(hash['name']) if hash['name'] # Parameter is an array, so we need to iterate through it addresses = nil unless hash['addresses'].nil? addresses = [] hash['addresses'].each do |structure| addresses << (Address.from_hash(structure) if structure) end end addresses = SKIP unless hash.key?('addresses') birthday = hash['birthday'] ||= 'YYYY-MM-DD formatted string.' # Parameter is an array, so we need to iterate through it emails = nil unless hash['emails'].nil? emails = [] hash['emails'].each do |structure| emails << (EmailObject.from_hash(structure) if structure) end end emails = SKIP unless hash.key?('emails') org = Org.from_hash(hash['org']) if hash['org'] # Parameter is an array, so we need to iterate through it phones = nil unless hash['phones'].nil? phones = [] hash['phones'].each do |structure| phones << (PhoneObject.from_hash(structure) if structure) end end phones = SKIP unless hash.key?('phones') # Parameter is an array, so we need to iterate through it urls = nil unless hash['urls'].nil? urls = [] hash['urls'].each do |structure| urls << (UrlObject.from_hash(structure) if structure) end end urls = SKIP unless hash.key?('urls') # Create object from extracted values. Contact.new(name, addresses, birthday, emails, org, phones, urls) end |
.names ⇒ Object
A mapping from model property names to API property names.
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/whats_app_cloud_api/models/contact.rb', line 41 def self.names @_hash = {} if @_hash.nil? @_hash['addresses'] = 'addresses' @_hash['birthday'] = 'birthday' @_hash['emails'] = 'emails' @_hash['name'] = 'name' @_hash['org'] = 'org' @_hash['phones'] = 'phones' @_hash['urls'] = 'urls' @_hash end |
Instance Method Details
#nullables ⇒ Object
An array for nullable fields
66 67 68 |
# File 'lib/whats_app_cloud_api/models/contact.rb', line 66 def nullables [] end |
#optionals ⇒ Object
An array for optional fields
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/whats_app_cloud_api/models/contact.rb', line 54 def optionals %w[ addresses birthday emails org phones urls ] end |