class Transloadit::ApiModel
Represents an API class that more Transloadit
specific API classes would inherit from.
Attributes
@return [Hash] the options describing the Assembly
@return [Transloadit] the associated Transloadit
instance
Public Class Methods
Creates a new API instance authenticated using the given transloadit
instance.
@param [Transloadit] transloadit the associated Transloadit
instance @param [Hash] options the configuration for the API;
# File lib/transloadit/api_model.rb, line 21 def initialize(transloadit, options = {}) self.transloadit = transloadit self.options = options end
Public Instance Methods
@return [String] a human-readable version of the API
# File lib/transloadit/api_model.rb, line 29 def inspect self.to_hash.inspect end
@return [Hash] a Transloadit-compatible Hash of the API's contents
# File lib/transloadit/api_model.rb, line 36 def to_hash self.options.merge( :auth => self.transloadit.to_hash, ).delete_if {|_,v| v.nil?} end
@return [String] JSON-encoded String containing the API's contents
# File lib/transloadit/api_model.rb, line 45 def to_json MultiJson.dump(self.to_hash) end
Private Instance Methods
Performs http request in favour of it's caller
@param [String] path url path to which request is made @param [Hash] params POST/GET data to submit with the request @param [String] method http request method. This could be 'post' or 'get' @param [Hash] extra_params additional POST/GET data to submit with the request
@return [Transloadit::Response] the response
# File lib/transloadit/api_model.rb, line 65 def _do_request(path, params = nil, method = 'get', extra_params = nil) if !params.nil? params = self.to_hash.update(params) params = { :params => params } if ['post', 'put', 'delete'].include? method params.merge!(extra_params) if !extra_params.nil? end Transloadit::Request.new(path, self.transloadit.secret).public_send(method, params) end