class Hubbah::Contact
Attributes
attributes[R]
vid[R]
Public Class Methods
create_or_update(email, attributes)
click to toggle source
# File lib/hubbah/contact.rb, line 45 def create_or_update(email, attributes) new(attributes.merge('email' => email)).tap do |contact| contact.save end end
new(attributes)
click to toggle source
# File lib/hubbah/contact.rb, line 8 def initialize(attributes) @attributes = attributes end
Public Instance Methods
email()
click to toggle source
# File lib/hubbah/contact.rb, line 12 def email attributes['email'] end
property_collection()
click to toggle source
# File lib/hubbah/contact.rb, line 35 def property_collection @attributes.map do |field, value| { property: field, value: value } end end
save()
click to toggle source
# File lib/hubbah/contact.rb, line 16 def save resp = client.post do |req| req.url "/contacts/v1/contact/createOrUpdate/email/#{URI.encode(email)}/" req.body = { properties: property_collection }.to_json req.headers[:content_type] = 'application/json' end if resp.status == 200 @vid = JSON.parse(resp.body)['vid'] return true elsif resp.status == 401 raise Hubbah::AccessDenied.new(resp.body) elsif resp.status == 500 raise Hubbah::ServerErrorEncountered.new(resp.body) else raise Hubbah::Error.new(resp.body) end end
Protected Instance Methods
api_key()
click to toggle source
# File lib/hubbah/contact.rb, line 67 def api_key configuration.api_key end
client()
click to toggle source
# File lib/hubbah/contact.rb, line 53 def client @client ||= Faraday.new({ url: 'http://api.hubapi.com/', params: { hapikey: api_key, portalId: hub_id } }) end
configuration()
click to toggle source
# File lib/hubbah/contact.rb, line 71 def configuration Hubbah.configuration end
hub_id()
click to toggle source
# File lib/hubbah/contact.rb, line 63 def hub_id configuration.hub_id end