Class: RelateIq::Contact
- Inherits:
-
Object
- Object
- RelateIq::Contact
- Defined in:
- lib/relateiq/contact.rb
Instance Attribute Summary collapse
-
#address ⇒ Object
Returns the value of attribute address.
-
#city ⇒ Object
Returns the value of attribute city.
-
#company ⇒ Object
Returns the value of attribute company.
-
#email ⇒ Object
Returns the value of attribute email.
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#id ⇒ Object
Returns the value of attribute id.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#linkedin ⇒ Object
Returns the value of attribute linkedin.
-
#phone ⇒ Object
Returns the value of attribute phone.
-
#state ⇒ Object
Returns the value of attribute state.
-
#title ⇒ Object
Returns the value of attribute title.
-
#twitter ⇒ Object
Returns the value of attribute twitter.
-
#zipcode ⇒ Object
Returns the value of attribute zipcode.
Class Method Summary collapse
- .create(attrs) ⇒ Object
- .find(id) ⇒ Object
- .find_by_email(email) ⇒ Object
- .from_json(json_string) ⇒ Object
- .resource ⇒ Object
Instance Method Summary collapse
- #full_address ⇒ Object
- #full_name ⇒ Object
-
#initialize(attrs = {}) ⇒ Contact
constructor
A new instance of Contact.
- #save ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(attrs = {}) ⇒ Contact
Returns a new instance of Contact.
60 61 62 63 64 65 66 |
# File 'lib/relateiq/contact.rb', line 60 def initialize(attrs = {}) if attrs.key? :properties initialize_from_api(attrs) else initialize_by_user(attrs) end end |
Instance Attribute Details
#address ⇒ Object
Returns the value of attribute address.
3 4 5 |
# File 'lib/relateiq/contact.rb', line 3 def address @address end |
#city ⇒ Object
Returns the value of attribute city.
3 4 5 |
# File 'lib/relateiq/contact.rb', line 3 def city @city end |
#company ⇒ Object
Returns the value of attribute company.
3 4 5 |
# File 'lib/relateiq/contact.rb', line 3 def company @company end |
#email ⇒ Object
Returns the value of attribute email.
3 4 5 |
# File 'lib/relateiq/contact.rb', line 3 def email @email end |
#first_name ⇒ Object
Returns the value of attribute first_name.
3 4 5 |
# File 'lib/relateiq/contact.rb', line 3 def first_name @first_name end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/relateiq/contact.rb', line 3 def id @id end |
#last_name ⇒ Object
Returns the value of attribute last_name.
3 4 5 |
# File 'lib/relateiq/contact.rb', line 3 def last_name @last_name end |
#linkedin ⇒ Object
Returns the value of attribute linkedin.
3 4 5 |
# File 'lib/relateiq/contact.rb', line 3 def linkedin @linkedin end |
#phone ⇒ Object
Returns the value of attribute phone.
3 4 5 |
# File 'lib/relateiq/contact.rb', line 3 def phone @phone end |
#state ⇒ Object
Returns the value of attribute state.
3 4 5 |
# File 'lib/relateiq/contact.rb', line 3 def state @state end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/relateiq/contact.rb', line 3 def title @title end |
#twitter ⇒ Object
Returns the value of attribute twitter.
3 4 5 |
# File 'lib/relateiq/contact.rb', line 3 def twitter @twitter end |
#zipcode ⇒ Object
Returns the value of attribute zipcode.
3 4 5 |
# File 'lib/relateiq/contact.rb', line 3 def zipcode @zipcode end |
Class Method Details
.create(attrs) ⇒ Object
29 30 31 |
# File 'lib/relateiq/contact.rb', line 29 def self.create(attrs) Contact.new(attrs).save end |
.find(id) ⇒ Object
21 22 23 |
# File 'lib/relateiq/contact.rb', line 21 def self.find(id) from_json(resource["#{id}"].get) end |
.find_by_email(email) ⇒ Object
25 26 27 |
# File 'lib/relateiq/contact.rb', line 25 def self.find_by_email(email) from_json(resource["?properties.email=#{email}"].get) end |
.from_json(json_string) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/relateiq/contact.rb', line 51 def self.from_json(json_string) contact_hash = JSON.parse(json_string, symbolize_names: true) if contact_hash.key? :objects contact_hash[:objects].map { |li| Contact.new(li) } else Contact.new(contact_hash) end end |
.resource ⇒ Object
17 18 19 |
# File 'lib/relateiq/contact.rb', line 17 def self.resource @resource ||= ServiceFactory.get_endpoint('contacts') end |
Instance Method Details
#full_address ⇒ Object
38 39 40 41 |
# File 'lib/relateiq/contact.rb', line 38 def full_address return nil unless address || city || state || zipcode "#{address}, #{city}, #{state} #{zipcode}" end |
#full_name ⇒ Object
33 34 35 36 |
# File 'lib/relateiq/contact.rb', line 33 def full_name return nil unless first_name || last_name "#{first_name} #{last_name}" end |
#save ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/relateiq/contact.rb', line 43 def save if id Contact.from_json(Contact.resource["#{id}"].put to_json) else Contact.from_json(Contact.resource.post to_json) end end |
#to_json ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/relateiq/contact.rb', line 68 def to_json riq_hash = { properties: { email: [{ value: @email }] } } riq_hash[:id] = id if id inject_property_value_hash(riq_hash[:properties], 'name', full_name) inject_property_value_hash(riq_hash[:properties], 'phone', phone) inject_property_value_hash(riq_hash[:properties], 'address', address) inject_property_value_hash(riq_hash[:properties], 'liurl', linkedin) inject_property_value_hash(riq_hash[:properties], 'twhan', twitter) inject_property_value_hash(riq_hash[:properties], 'company', company) inject_property_value_hash(riq_hash[:properties], 'title', title) riq_hash.to_json end |