Class: Uploadcare::Client::RestClient
Abstract
Overview
General client for signed REST requests
Instance Method Summary
collapse
#handle_throttling
#failure, #wrap
Instance Method Details
#api_root ⇒ Object
54
55
56
|
# File 'lib/uploadcare/client/rest_client.rb', line 54
def api_root
Uploadcare.config.rest_api_root
end
|
#api_struct_delete ⇒ Object
18
|
# File 'lib/uploadcare/client/rest_client.rb', line 18
alias api_struct_delete delete
|
#api_struct_get ⇒ Object
19
|
# File 'lib/uploadcare/client/rest_client.rb', line 19
alias api_struct_get get
|
#api_struct_post ⇒ Object
20
|
# File 'lib/uploadcare/client/rest_client.rb', line 20
alias api_struct_post post
|
#api_struct_put ⇒ Object
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
|
58
59
60
61
62
63
64
|
# File 'lib/uploadcare/client/rest_client.rb', line 58
def
{
'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)
= Param::AuthenticationHeader.call(method: method.upcase, uri: uri,
content_type: [:'Content-Type'], **options)
handle_throttling do
send("api_struct_#{method.downcase}",
path: remove_trailing_slash(uri),
headers: ,
body: options[:content],
params: options[:params])
end
end
|