class ActOn::Client

Public Class Methods

new(options={}) click to toggle source
# File lib/act-on/client.rb, line 6
def initialize(options={})
end

Public Instance Methods

authenticate() click to toggle source
# 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() click to toggle source
# File lib/act-on/client.rb, line 9
def authenticate_url
  [ActOn.url, "token"].join("/")
end
create_contact(list_id, contact) click to toggle source
# 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) click to toggle source
# 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={}) click to toggle source
# 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() click to toggle source
# File lib/act-on/client.rb, line 30
def lists
  get(lists_url)
end
lists_url() click to toggle source
# File lib/act-on/client.rb, line 26
def lists_url
  [ActOn.url, "api", "1", "list"].join("/")
end
post(url, params, headers={}) click to toggle source
# File lib/act-on/client.rb, line 52
def post(url, params, headers={})
  JSON.parse(
    RestClient.post(url, params, headers)
  )
end