Class: Kipalog::APIClient

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

Constant Summary collapse

BASE_URI =
'kipalog.com/api/v1'.freeze
X_KIPALOG_TOKEN =
'X-Kipalog-Token'.freeze
ACCEPT_CHARSET =
'Accept-Charset'
DEFAULT_CHARSET =
'application/json'

Instance Method Summary collapse

Constructor Details

#initialize(config = Kipalog.config) ⇒ APIClient

Returns a new instance of APIClient.



11
12
13
# File 'lib/kipalog/api_client.rb', line 11

def initialize(config = Kipalog.config)
  @config = config
end

Instance Method Details

#get(path) ⇒ Object



15
16
17
# File 'lib/kipalog/api_client.rb', line 15

def get(path)
  send_request(:get, path)
end

#post(path, request_body) ⇒ Object



19
20
21
# File 'lib/kipalog/api_client.rb', line 19

def post(path, request_body)
  send_request(:post, path, request_body)
end

#send_request(method, path, body_hash = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kipalog/api_client.rb', line 23

def send_request(method, path, body_hash = {})
  _make_request(method, path, body_hash) do |result|
    response = Kipalog::Response.new(
      result.code,
      result.headers,
      result.parsed_response
    )

    if response.ok?
      response
    else
      raise RequestError, response.body
    end
  end
end