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



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

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



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

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

#get(options = {}) ⇒ Object



35
36
37
# File 'lib/uploadcare/client/rest_client.rb', line 35

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

#headersObject



55
56
57
58
59
60
61
# File 'lib/uploadcare/client/rest_client.rb', line 55

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

#post(options = {}) ⇒ Object



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

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

#put(options = {}) ⇒ Object



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

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
# 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])
  end
end