Class: CampaignHQ::API

Inherits:
Object
  • Object
show all
Defined in:
lib/campaign_h_q/api.rb,
lib/campaign_h_q/api/error.rb,
lib/campaign_h_q/api/response.rb,
lib/campaign_h_q/api/error/not_found.rb,
lib/campaign_h_q/api/error/unauthorized.rb,
lib/campaign_h_q/api/error/invalid_parameters.rb

Defined Under Namespace

Classes: Error, Response

Constant Summary collapse

HOST =
'api.campaignhq.co'
PORT =
443
HEADERS =
{
  'Content-Type' => 'application/json'
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ API

Returns a new instance of API.



14
15
16
17
18
19
20
21
# File 'lib/campaign_h_q/api.rb', line 14

def initialize(api_key)
  @http = Net::HTTP.new HOST, PORT
  @http.use_ssl = true
  @api_key = api_key
  @auth_headers = HEADERS.merge(
    'Authorization' => "Bearer #{@api_key}"
  )
end

Instance Method Details

#delete(path) ⇒ Object



39
40
41
# File 'lib/campaign_h_q/api.rb', line 39

def delete(path)
  Response.new @http.delete(path, @auth_headers)
end

#get(path) ⇒ Object



23
24
25
# File 'lib/campaign_h_q/api.rb', line 23

def get(path)
  Response.new @http.get(path, @auth_headers)
end

#patch(path, body = {}) ⇒ Object



31
32
33
# File 'lib/campaign_h_q/api.rb', line 31

def patch(path, body = {})
  Response.new @http.patch(path, body.to_json, @auth_headers)
end

#post(path, body = {}) ⇒ Object



27
28
29
# File 'lib/campaign_h_q/api.rb', line 27

def post(path, body = {})
  Response.new @http.post(path, body.to_json, @auth_headers)
end

#put(path, body = {}) ⇒ Object



35
36
37
# File 'lib/campaign_h_q/api.rb', line 35

def put(path, body = {})
  Response.new @http.put(path, body.to_json, @auth_headers)
end