Class: Fondy::Request

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

Constant Summary collapse

API_HOST =
'https://api.fondy.eu'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method, url, body) ⇒ Request

Returns a new instance of Request.



10
11
12
13
14
# File 'lib/fondy/request.rb', line 10

def initialize(method, url, body)
  @method = method
  @url = url
  @body = body
end

Class Method Details

.call(*args) ⇒ Object



6
7
8
# File 'lib/fondy/request.rb', line 6

def self.call(*args)
  new(*args).call
end

Instance Method Details

#callObject



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fondy/request.rb', line 16

def call
  connection = Faraday::Connection.new(API_HOST)
  connection.public_send(method) do |request|
    request.url url
    if body
      request.body = JSON.generate(request: body)
      request.headers['Content-Type'] = 'application/json'
    end
  end
rescue Faraday::Error => e
  raise Fondy::RequestError, e.message
end