Class: RIQ::Contact
Overview
Contacts represent people in an Organization’s address book.
Instance Attribute Summary collapse
-
#properties ⇒ Object
Returns the value of attribute properties.
Attributes inherited from RIQObject
Class Method Summary collapse
-
.node(id = nil) ⇒ String
Endpoint.
Instance Method Summary collapse
-
#add(prop, val) ⇒ Array
Adds property with correct scaffolding.
-
#address ⇒ String
The preferred value for address.
-
#data ⇒ Hash
All relevant stored data.
-
#email ⇒ String
The preferred value for email.
-
#info(prop, val) ⇒ Hash
Metadata and other info about a given property.
-
#name ⇒ Array
All of the values for name.
-
#node ⇒ String
Endpoint.
-
#phone ⇒ String
The preferred value for phone.
-
#primary_address ⇒ String
The preferred value for primary_address.
-
#primary_email ⇒ String
The preferred value for primary_email.
-
#primary_name ⇒ String
The preferred value for primary_name.
-
#primary_phone ⇒ String
The preferred value for primary_phone.
-
#remove(prop, val) ⇒ Array
Removes property from hash.
-
#upsert ⇒ Object
Edits an existing object based on matching email(s) or saves a new object.
Methods inherited from RIQObject
#delete, #initialize, #payload, #save
Constructor Details
This class inherits a constructor from RIQ::RIQObject
Instance Attribute Details
#properties ⇒ Object
Returns the value of attribute properties.
7 8 9 |
# File 'lib/riq/contact.rb', line 7 def properties @properties end |
Class Method Details
.node(id = nil) ⇒ String
Returns endpoint.
15 16 17 |
# File 'lib/riq/contact.rb', line 15 def self.node(id = nil) "contacts/#{id}" end |
Instance Method Details
#add(prop, val) ⇒ Array
Adds property with correct scaffolding
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/riq/contact.rb', line 74 def add(prop, val) # validate(prop) prop = prop.to_sym @properties[prop] = [] unless @properties.include? prop if val.is_a? Array val.each do |i| add(prop, i) end return end raise RIQError, 'Values must be strings' unless val.is_a?(String) # don't add duplicate if @properties[prop].select{|p| p[:value] == val}.empty? @properties[prop] << {value: val, metadata: {}} end get_prop(prop) end |
#address ⇒ String
Returns the preferred value for address.
61 62 63 |
# File 'lib/riq/contact.rb', line 61 def address get_prop(:address) end |
#data ⇒ Hash
Returns all relevant stored data.
20 21 22 23 24 25 26 |
# File 'lib/riq/contact.rb', line 20 def data { id: @id, properties: @properties # modified_date: @modified_date } end |
#email ⇒ String
Returns the preferred value for email.
51 52 53 |
# File 'lib/riq/contact.rb', line 51 def email get_prop(:email) end |
#info(prop, val) ⇒ Hash
Returns metadata and other info about a given property.
125 126 127 128 129 |
# File 'lib/riq/contact.rb', line 125 def info(prop, val) # validate(prop) @properties[prop].select{|p| p[:value] == val}.first end |
#name ⇒ Array
Returns all of the values for name.
30 31 32 |
# File 'lib/riq/contact.rb', line 30 def name get_prop(:name) end |
#node ⇒ String
Returns endpoint.
10 11 12 |
# File 'lib/riq/contact.rb', line 10 def node self.class.node(@id) end |
#phone ⇒ String
Returns the preferred value for phone.
41 42 43 |
# File 'lib/riq/contact.rb', line 41 def phone get_prop(:phone) end |
#primary_address ⇒ String
Returns the preferred value for primary_address.
66 67 68 |
# File 'lib/riq/contact.rb', line 66 def primary_address get_primary_prop(:address) end |
#primary_email ⇒ String
Returns the preferred value for primary_email.
56 57 58 |
# File 'lib/riq/contact.rb', line 56 def primary_email get_primary_prop(:email) end |
#primary_name ⇒ String
Returns the preferred value for primary_name.
36 37 38 |
# File 'lib/riq/contact.rb', line 36 def primary_name get_primary_prop(:name) end |
#primary_phone ⇒ String
Returns the preferred value for primary_phone.
46 47 48 |
# File 'lib/riq/contact.rb', line 46 def primary_phone get_primary_prop(:phone) end |
#remove(prop, val) ⇒ Array
Removes property from hash
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/riq/contact.rb', line 99 def remove(prop, val) # validate(prop) prop = prop.to_sym if val.is_a? Array val.each do |i| remove(prop, i) end end if @properties.include? prop @properties[prop] = @properties[prop].reject{|p| p[:value] == val} end get_prop(prop) end |
#upsert ⇒ Object
Edits an existing object based on matching email(s) or saves a new object
117 118 119 120 |
# File 'lib/riq/contact.rb', line 117 def upsert # can only be email right now save({_upsert: 'email'}) end |