class Contactually::API

Public Class Methods

new(api_key = nil) click to toggle source
# File lib/contactually/api.rb, line 3
def initialize(api_key = nil)
  raise ConfigMissingApiKeyError, 'You must provide a Contactually API key' unless Contactually.config.api_key || api_key
  @api_key = Contactually.config.api_key || api_key
  @base_url = Contactually.config.contactually_url
end

Public Instance Methods

accounts() click to toggle source
# File lib/contactually/api.rb, line 30
def accounts
  @accounts ||= Contactually::Accounts.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 42
def connection
  @connection ||= Faraday.new do |faraday|
    faraday.headers['Content-Type'] = 'application/json'
    faraday.adapter Faraday.default_adapter
    faraday.use Contactually::Middleware::ErrorDetector
  end
end
contact_groupings() click to toggle source
# File lib/contactually/api.rb, line 34
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 38
def contents
  @contents ||= Contactually::Contents.new self
end
groupings() click to toggle source
# File lib/contactually/api.rb, line 26
def groupings
  @groupings ||= Contactually::Groupings.new self
end
notes() click to toggle source
# File lib/contactually/api.rb, line 18
def notes
  @notes ||= Contactually::Notes.new self
end
tasks() click to toggle source
# File lib/contactually/api.rb, line 22
def tasks
  @tasks ||= Contactually::Tasks.new self
end

Private Instance Methods

base_url(url) click to toggle source
# File lib/contactually/api.rb, line 78
def base_url(url)
  "#{@base_url}#{url}"
end
call_params(params) click to toggle source
# File lib/contactually/api.rb, line 52
def call_params(params)
  params.merge({ api_key: @api_key })
end
delete(url, params) click to toggle source
# File lib/contactually/api.rb, line 74
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 70
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 56
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 63
def put(url, params)
  connection.put do |req|
    req.url base_url(url)
    req.body = call_params(params).to_json
  end
end