Class: Transloadit::Request
- Inherits:
-
Object
- Object
- Transloadit::Request
- Defined in:
- lib/transloadit/request.rb
Overview
Wraps requests to the Transloadit API. Ensures all API requests return a parsed Transloadit::Response, and abstracts away finding a lightly-used instance on startup.
Constant Summary collapse
- API_ENDPOINT =
The default Transloadit API endpoint.
URI.parse('http://api2.transloadit.com/')
- API_HEADERS =
The default headers to send to the API.
{ 'User-Agent' => "Transloadit Ruby SDK #{Transloadit::VERSION}" }
- HMAC_ALGORITHM =
The HMAC algorithm used for calculation request signatures.
OpenSSL::Digest.new('sha1')
Instance Attribute Summary collapse
-
#secret ⇒ String
The authentication secret to sign the request with.
-
#url ⇒ String
readonly
The API endpoint for the request.
Instance Method Summary collapse
-
#delete(payload = {}) ⇒ Transloadit::Response
Performs an HTTP DELETE to the request’s URL.
-
#get(params = {}) ⇒ Transloadit::Response
Performs an HTTP GET to the request’s URL.
-
#initialize(url, secret = nil) ⇒ Request
constructor
Prepares a request against an endpoint URL, optionally with an encryption secret.
-
#inspect ⇒ String
A human-readable version of the prepared Request.
-
#post(payload = {}) ⇒ Transloadit::Response
Performs an HTTP POST to the request’s URL.
-
#put(payload = {}) ⇒ Transloadit::Response
Performs an HTTP PUT to the request’s URL.
Constructor Details
#initialize(url, secret = nil) ⇒ Request
Prepares a request against an endpoint URL, optionally with an encryption secret. If only a path is passed, the API will automatically determine the best server to use. If a full URL is given, the host provided will be used.
36 37 38 39 |
# File 'lib/transloadit/request.rb', line 36 def initialize(url, secret = nil) self.url = URI.parse(url.to_s) self.secret = secret end |
Instance Attribute Details
#secret ⇒ String
Returns the authentication secret to sign the request with.
25 26 27 |
# File 'lib/transloadit/request.rb', line 25 def secret @secret end |
#url ⇒ String
Returns the API endpoint for the request.
22 23 24 |
# File 'lib/transloadit/request.rb', line 22 def url @url end |
Instance Method Details
#delete(payload = {}) ⇒ Transloadit::Response
Performs an HTTP DELETE to the request’s URL. Takes an optional hash containing the form-encoded payload.
61 62 63 64 65 66 |
# File 'lib/transloadit/request.rb', line 61 def delete(payload = {}) self.request! do = {:payload => self.to_payload(payload)} self.api( = )[url.path].delete(API_HEADERS) end end |
#get(params = {}) ⇒ Transloadit::Response
Performs an HTTP GET to the request’s URL. Takes an optional hash of query params.
48 49 50 51 52 |
# File 'lib/transloadit/request.rb', line 48 def get(params = {}) self.request! do self.api[url.path + self.to_query(params)].get(API_HEADERS) end end |
#inspect ⇒ String
Returns a human-readable version of the prepared Request.
97 98 99 |
# File 'lib/transloadit/request.rb', line 97 def inspect self.url.to_s.inspect end |
#post(payload = {}) ⇒ Transloadit::Response
Performs an HTTP POST to the request’s URL. Takes an optional hash containing the form-encoded payload.
75 76 77 78 79 |
# File 'lib/transloadit/request.rb', line 75 def post(payload = {}) self.request! do self.api[url.path].post(self.to_payload(payload), API_HEADERS) end end |
#put(payload = {}) ⇒ Transloadit::Response
Performs an HTTP PUT to the request’s URL. Takes an optional hash containing the form-encoded payload.
88 89 90 91 92 |
# File 'lib/transloadit/request.rb', line 88 def put(payload = {}) self.request! do self.api[url.path].put(self.to_payload(payload), API_HEADERS) end end |