Class: Tazapay::Client

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

Overview

Base API client

Direct Known Subclasses

Bank, Checkout, Escrow, Metadata, Refund, Release, User

Instance Method Summary collapse

Instance Method Details

#handle_error(response_body, response_code) ⇒ Object

Raises:



31
32
33
# File 'lib/tazapay/client.rb', line 31

def handle_error(response_body, response_code)
  raise Tazapay::Error.new(response_body, response_code)
end

#interpret_response(resp) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/tazapay/client.rb', line 21

def interpret_response(resp)
  body = resp.body.empty? ? "" : JSON.parse(resp.body)
  response = {
    body: body,
    code: resp.status
  }
  handle_error(response[:body], response[:code]) unless resp.status >= 200 && resp.status < 300
  body
end

#send_request(method:, path:, headers: default_headers, body: {}) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/tazapay/client.rb', line 11

def send_request(method:, path:, headers: default_headers, body: {})
  conn = prepare_connection(headers)
  case method.to_s
  when "get" then response = conn.get(path)
  when "post" then response = conn.post(path, body.to_json)
  when "put" then response = conn.put(path, body.to_json)
  end
  interpret_response(response)
end