Class: UnFichierApi::Base

Inherits:
Object
  • Object
show all
Includes:
Helpers::RequestHelper
Defined in:
lib/un_fichier_api/base.rb

Direct Known Subclasses

File, Folder, Ftp, FtpUser, Remote, User

Class Method Summary collapse

Class Method Details

.call(path:, method: :post, body: {}, headers: {}) ⇒ Object



16
17
18
19
20
21
22
23
24
# 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

.connectionObject



26
27
28
29
30
31
32
# 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