Class: Contactually::API

Inherits:
Object
  • Object
show all
Defined in:
lib/contactually.rb

Defined Under Namespace

Classes: ReturnValue

Constant Summary collapse

HTTP_ACTIONS =
%w(get post put delete).freeze
METHODS =
%w(contacts notes groupings).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, headers = {}) ⇒ API

Returns a new instance of API.



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/contactually.rb', line 14

def initialize(api_key, headers = {})
  @api_key = api_key

  # The Contactually API recommends passing in a User-Agent header unique to
  # the client application as a best practice
  # (see: http://developers.contactually.com/docs/):
  #
  #     Contactually::API.new(
  #         { "YOUR_CONTACTUALLY_API_KEY", :user_agent => "YOUR_APP_NAME" }
  #     )
  #
  @headers = headers
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



36
37
38
# File 'lib/contactually.rb', line 36

def method_missing(method, *args)
  call(method, args.try(:first) || {})
end

Instance Attribute Details

#contactually_methodObject (readonly)

Returns the value of attribute contactually_method.



12
13
14
# File 'lib/contactually.rb', line 12

def contactually_method
  @contactually_method
end

#http_actionObject (readonly)

Returns the value of attribute http_action.



12
13
14
# File 'lib/contactually.rb', line 12

def http_action
  @http_action
end

Instance Method Details

#call(method, params) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/contactually.rb', line 28

def call(method, params)
  if (parsed_response = make_call(method, params))
    parsed_response
  else
    false
  end
end