Class: Iwoca::Connection

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

Constant Summary collapse

BASE_PATH =
'/api/lending/v2.1'
BASE_NOTIFICATIONS_PATH =
'/api/notifications/v1'

Instance Method Summary collapse

Constructor Details

#initialize(type = 'base') ⇒ Connection

Returns a new instance of Connection.



14
15
16
# File 'lib/iwoca/connection.rb', line 14

def initialize(type = 'base')
  @base_path = type == 'notifications' ? BASE_NOTIFICATIONS_PATH : BASE_PATH
end

Instance Method Details

#get(path, params = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/iwoca/connection.rb', line 18

def get(path, params = {})
  log "GET #{path} with #{params}"

  http_response = adapter.get(PathSanitizer.sanitize(path), params)

  log "Response: #{http_response.body}"

  Response.new(http_response)
end

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



28
29
30
31
32
33
34
35
36
# File 'lib/iwoca/connection.rb', line 28

def post(path, params = {})
  log "POST #{path} with #{params}"

  http_response = adapter.post(PathSanitizer.sanitize(path), params.to_json)

  log "Response: #{http_response.body}"

  Response.new(http_response)
end

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



38
39
40
41
42
43
44
45
46
# File 'lib/iwoca/connection.rb', line 38

def put(path, params = {})
  log "PUT #{path} with #{params}"

  http_response = adapter.put(PathSanitizer.sanitize(path), params.to_json)

  log "Response: #{http_response.body}"

  Response.new(http_response)
end