Class: Uploadcare::Client::RestClient Abstract

Inherits:
ApiStruct::Client
  • Object
show all
Includes:
Uploadcare::Concerns::ErrorHandler, Uploadcare::Concerns::ThrottleHandler, Exception
Defined in:
lib/uploadcare/client/rest_client.rb

Overview

This class is abstract.

General client for signed REST requests

Instance Method Summary collapse

Methods included from Uploadcare::Concerns::ThrottleHandler

#handle_throttling

Methods included from Uploadcare::Concerns::ErrorHandler

#failure, #wrap

Instance Method Details

#api_rootObject



54
55
56
# File 'lib/uploadcare/client/rest_client.rb', line 54

def api_root
  Uploadcare.config.rest_api_root
end

#api_struct_deleteObject



18
# File 'lib/uploadcare/client/rest_client.rb', line 18

alias api_struct_delete delete

#api_struct_getObject



19
# File 'lib/uploadcare/client/rest_client.rb', line 19

alias api_struct_get get

#api_struct_postObject



20
# File 'lib/uploadcare/client/rest_client.rb', line 20

alias api_struct_post post

#api_struct_putObject



21
# File 'lib/uploadcare/client/rest_client.rb', line 21

alias api_struct_put put

#delete(options = {}) ⇒ Object



50
51
52
# File 'lib/uploadcare/client/rest_client.rb', line 50

def delete(options = {})
  request(method: 'DELETE', **options)
end

#get(options = {}) ⇒ Object



38
39
40
# File 'lib/uploadcare/client/rest_client.rb', line 38

def get(options = {})
  request(method: 'GET', **options)
end

#headersObject



58
59
60
61
62
63
64
# File 'lib/uploadcare/client/rest_client.rb', line 58

def headers
  {
    'Content-Type': 'application/json',
    Accept: 'application/vnd.uploadcare-v0.7+json',
    'User-Agent': Uploadcare::Param::UserAgent.call
  }
end

#post(options = {}) ⇒ Object



42
43
44
# File 'lib/uploadcare/client/rest_client.rb', line 42

def post(options = {})
  request(method: 'POST', **options)
end

#put(options = {}) ⇒ Object



46
47
48
# File 'lib/uploadcare/client/rest_client.rb', line 46

def put(options = {})
  request(method: 'PUT', **options)
end

#request(uri:, method: 'GET', **options) ⇒ Object

Send request with authentication header

Handle throttling as well



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/uploadcare/client/rest_client.rb', line 26

def request(uri:, method: 'GET', **options)
  request_headers = Param::AuthenticationHeader.call(method: method.upcase, uri: uri,
                                                     content_type: headers[:'Content-Type'], **options)
  handle_throttling do
    send("api_struct_#{method.downcase}",
         path: remove_trailing_slash(uri),
         headers: request_headers,
         body: options[:content],
         params: options[:params])
  end
end