Class: Rubspot::Contact
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#firstname ⇒ Object
Returns the value of attribute firstname.
-
#vid ⇒ Object
Returns the value of attribute vid.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Contact
constructor
A new instance of Contact.
- #save ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(opts = {}) ⇒ Contact
Returns a new instance of Contact.
8 9 10 11 12 |
# File 'lib/rubspot/models/contact.rb', line 8 def initialize(opts = {}) opts.each do |opt| instance_variable_set("@#{opt[0]}", opt[1]) end end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
6 7 8 |
# File 'lib/rubspot/models/contact.rb', line 6 def email @email end |
#firstname ⇒ Object
Returns the value of attribute firstname.
6 7 8 |
# File 'lib/rubspot/models/contact.rb', line 6 def firstname @firstname end |
#vid ⇒ Object
Returns the value of attribute vid.
6 7 8 |
# File 'lib/rubspot/models/contact.rb', line 6 def vid @vid end |
Class Method Details
.find_by_email(email) ⇒ Object
14 15 16 17 18 |
# File 'lib/rubspot/models/contact.rb', line 14 def self.find_by_email(email) response = Rubspot::Base::get("https://api.hubapi.com/contacts/v1/contact/email/#{email}/profile?hapikey=#{Rubspot::API_KEY}") return nil unless response.ok? Rubspot::ContactRepresentation.new(Rubspot::Contact.new).from_json response.body end |
Instance Method Details
#save ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/rubspot/models/contact.rb', line 20 def save params = Rubspot::ContactRepresentation.new(self).to_json response = Rubspot::Base::post("http://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/#{self.email}/?hapikey=#{Rubspot::API_KEY}&portalId=#{Rubspot::PORTAL_ID}", params) return false unless response.ok? populate_attributes_from response true end |