Class: RDStation::Contacts

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/rdstation/contacts.rb

Overview

Instance Method Summary collapse

Constructor Details

#initialize(auth_token) ⇒ Contacts

Returns a new instance of Contacts.



7
8
9
# File 'lib/rdstation/contacts.rb', line 7

def initialize(auth_token)
  @auth_token = auth_token
end

Instance Method Details

#by_email(email) ⇒ Object



22
23
24
25
26
27
# File 'lib/rdstation/contacts.rb', line 22

def by_email(email)
  response = self.class.get(base_url("email:#{email}"), headers: required_headers)
  response_body = JSON.parse(response.body)
  return response_body unless response_body['errors']
  RDStation::ErrorHandler.new(response).raise_errors
end

#by_uuid(uuid) ⇒ Object

param uuid:

The unique uuid associated to each RD Station Contact.


15
16
17
18
19
20
# File 'lib/rdstation/contacts.rb', line 15

def by_uuid(uuid)
  response = self.class.get(base_url(uuid), headers: required_headers)
  response_body = JSON.parse(response.body)
  return response_body unless response_body['errors']
  RDStation::ErrorHandler.new(response).raise_errors
end

#update(uuid, contact_hash) ⇒ Object

The Contact hash may contain the following parameters: :email :name :job_title :linkedin :facebook :twitter :personal_phone :mobile_phone :website :tags



40
41
42
43
44
45
# File 'lib/rdstation/contacts.rb', line 40

def update(uuid, contact_hash)
  response = self.class.patch(base_url(uuid), :body => contact_hash.to_json, :headers => required_headers)
  response_body = JSON.parse(response.body)
  return response_body unless response_body['errors']
  RDStation::ErrorHandler.new(response).raise_errors
end

#upsert(identifier, identifier_value, contact_hash) ⇒ Object

param identifier:

Field that will be used to identify the contact.

param identifier_value:

Value to the identifier given.

param contact_hash:

Contact data


55
56
57
58
59
60
61
# File 'lib/rdstation/contacts.rb', line 55

def upsert(identifier, identifier_value, contact_hash)
  path = "#{identifier}:#{identifier_value}"
  response = self.class.patch(base_url(path), body: contact_hash.to_json, headers: required_headers)
  response_body = JSON.parse(response.body)
  return response_body unless response_body['errors']
  RDStation::ErrorHandler.new(response).raise_errors
end