class UnFichierApi::Base

Public Class Methods

call(path:, method: :post, body: {}, headers: {}) click to toggle source
# File lib/un_fichier_api/base.rb, line 16
def call(path:, method: :post, body: {}, headers: {})
  connection.headers.merge! headers

  response = connection.send(method, path) do |req|
    req.body = body.to_json
  end

  JSON.parse response.body
end
connection() click to toggle source
# File lib/un_fichier_api/base.rb, line 26
def connection
  @connection ||= Faraday.new(
    url: 'https://api.1fichier.com/v1',
    headers: { 'Content-Type' => 'application/json', 'Authorization' => "Bearer #{api_key}" },
    request: { timeout: 120 }
  )
end