class ImageKitRequest
ImageKitRequest
requests and sends data from server
Attributes
options[R]
private_key[R]
public_key[R]
transformation_position[R]
url_endpoint[R]
Public Class Methods
new(private_key, public_key, url_endpoint, transformation_position = nil, options = nil)
click to toggle source
# File lib/imagekit/resource.rb, line 12 def initialize(private_key, public_key, url_endpoint, transformation_position = nil, options = nil) @private_key = private_key @public_key = public_key @url_endpoint = url_endpoint @transformation_position = transformation_position || Default::TRANSFORMATION_POSITION @options = options || {} end
Public Instance Methods
auth_headers()
click to toggle source
# File lib/imagekit/resource.rb, line 26 def auth_headers encoded_private_key = Base64.strict_encode64(@private_key+":") {Authorization: "Basic #{encoded_private_key}"} end
create_headers()
click to toggle source
creates required headers
# File lib/imagekit/resource.rb, line 21 def create_headers headers = {'Accept-Encoding': "application/json", 'Content-Type': "application/json"} headers.update(auth_headers) end
request(method, url, headers = nil, payload = nil)
click to toggle source
request method communicates with server
# File lib/imagekit/resource.rb, line 32 def request(method, url, headers = nil, payload = nil) headers ||= create_headers response = {response: nil, error: nil} begin resp = RestClient::Request.new(method: method, url: url, headers: headers, payload: payload).execute if resp.code == 404 raise RestClient::ExceptionWithResponse elsif (resp.code >= 200) && (resp.code < 204) response[:response] = JSON.parse(resp.body.to_s) elsif resp.code == 204 response[:response] = {'success': true} end rescue RestClient::ExceptionWithResponse => err err.http_code == 404 ? response[:error] = {'message': err.response.to_s} : JSON.parse(err.response) end response end