class Contactually::API
Public Class Methods
new(access_token = nil)
click to toggle source
# File lib/contactually/api.rb, line 3 def initialize(access_token = nil) raise ConfigMissingApiKeyError, 'You must provide a Contactually access_token' unless Contactually.config.access_token || access_token @access_token = Contactually.config.access_token || access_token @base_url = Contactually.config.contactually_url end
Public Instance Methods
accounts()
click to toggle source
# File lib/contactually/api.rb, line 34 def accounts @accounts ||= Contactually::Accounts.new self end
buckets()
click to toggle source
# File lib/contactually/api.rb, line 18 def buckets @buckets ||= Contactually::Buckets.new self end
call(url, http_method, params={})
click to toggle source
# File lib/contactually/api.rb, line 9 def call(url, http_method, params={}) response = send(http_method, url, params) JSON.load(response.body) end
connection()
click to toggle source
# File lib/contactually/api.rb, line 46 def connection @connection ||= Faraday.new do |faraday| faraday.headers['Content-Type'] = 'application/json' faraday.headers['Authorization'] = "Bearer #{@access_token}" faraday.adapter Faraday.default_adapter faraday.use Contactually::Middleware::ErrorDetector end end
contact_groupings()
click to toggle source
# File lib/contactually/api.rb, line 38 def contact_groupings @contact_groupings ||= Contactually::ContactGroupings.new self end
contacts()
click to toggle source
# File lib/contactually/api.rb, line 14 def contacts @contacts ||= Contactually::Contacts.new self end
contents()
click to toggle source
# File lib/contactually/api.rb, line 42 def contents @contents ||= Contactually::Contents.new self end
groupings()
click to toggle source
# File lib/contactually/api.rb, line 30 def groupings @groupings ||= Contactually::Groupings.new self end
notes()
click to toggle source
# File lib/contactually/api.rb, line 22 def notes @notes ||= Contactually::Notes.new self end
tasks()
click to toggle source
# File lib/contactually/api.rb, line 26 def tasks @tasks ||= Contactually::Tasks.new self end
Private Instance Methods
base_url(url)
click to toggle source
# File lib/contactually/api.rb, line 83 def base_url(url) "#{@base_url}#{url}" end
call_params(params)
click to toggle source
# File lib/contactually/api.rb, line 57 def call_params(params) params.merge({ access_token: @access_token }) end
delete(url, params)
click to toggle source
# File lib/contactually/api.rb, line 79 def delete(url, params) connection.delete(base_url(url), call_params(params)) end
get(url, params)
click to toggle source
# File lib/contactually/api.rb, line 75 def get(url, params) connection.get(base_url(url), call_params(params)) end
post(url, params)
click to toggle source
# File lib/contactually/api.rb, line 61 def post(url, params) connection.post do |req| req.url base_url(url) req.body = call_params(params).to_json end end
put(url, params)
click to toggle source
# File lib/contactually/api.rb, line 68 def put(url, params) connection.put do |req| req.url base_url(url) req.body = call_params(params).to_json end end