Class: ActOn::Client
- Inherits:
-
Object
- Object
- ActOn::Client
- Defined in:
- lib/act-on/client.rb
Instance Method Summary collapse
- #authenticate ⇒ Object
- #authenticate_url ⇒ Object
- #create_contact(list_id, contact) ⇒ Object
- #create_contact_url(list_id) ⇒ Object
- #get(url, params = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #lists ⇒ Object
- #lists_url ⇒ Object
- #post(url, params, headers = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
6 7 |
# File 'lib/act-on/client.rb', line 6 def initialize(={}) end |
Instance Method Details
#authenticate ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/act-on/client.rb', line 13 def authenticate params = { grant_type: "password", username: ActOn.username, password: ActOn.password, client_id: ActOn.client_id, client_secret: ActOn.client_secret } response = post(authenticate_url, params) raise response unless response["error"].nil? ActOn.access_token = response["access_token"] end |
#authenticate_url ⇒ Object
9 10 11 |
# File 'lib/act-on/client.rb', line 9 def authenticate_url [ActOn.url, "token"].join("/") end |
#create_contact(list_id, contact) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/act-on/client.rb', line 38 def create_contact(list_id, contact) headers = { "Authorization" => "Bearer #{ActOn.access_token}", :content_type => "application/json" } post(create_contact_url(list_id), contact.to_json, headers) end |
#create_contact_url(list_id) ⇒ Object
34 35 36 |
# File 'lib/act-on/client.rb', line 34 def create_contact_url(list_id) [ActOn.url, "api", "1", "list", list_id, "record"].join("/") end |
#get(url, params = {}) ⇒ Object
46 47 48 49 50 |
# File 'lib/act-on/client.rb', line 46 def get(url, params={}) JSON.parse( RestClient.get("#{url}?#{params.collect { |k,v| "#{k}=#{v.to_s.gsub(" ","+")}"}.join("&")}", { "Authorization" => "Bearer #{ActOn.access_token}" }) ) end |
#lists ⇒ Object
30 31 32 |
# File 'lib/act-on/client.rb', line 30 def lists get(lists_url) end |
#lists_url ⇒ Object
26 27 28 |
# File 'lib/act-on/client.rb', line 26 def lists_url [ActOn.url, "api", "1", "list"].join("/") end |
#post(url, params, headers = {}) ⇒ Object
52 53 54 55 56 |
# File 'lib/act-on/client.rb', line 52 def post(url, params, headers={}) JSON.parse( RestClient.post(url, params, headers) ) end |