Class: Rubspot::Contact

Inherits:
Base
  • Object
show all
Defined in:
lib/rubspot/models/contact.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

get, post

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

#emailObject

Returns the value of attribute email.



6
7
8
# File 'lib/rubspot/models/contact.rb', line 6

def email
  @email
end

#firstnameObject

Returns the value of attribute firstname.



6
7
8
# File 'lib/rubspot/models/contact.rb', line 6

def firstname
  @firstname
end

#vidObject

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

#saveObject



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