class Transloadit::ApiModel

Represents an API class that more Transloadit specific API classes would inherit from.

Attributes

options[RW]

@return [Hash] the options describing the Assembly

transloadit[RW]

@return [Transloadit] the associated Transloadit instance

Public Class Methods

new(transloadit, options = {}) click to toggle source

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

inspect() click to toggle source

@return [String] a human-readable version of the API

# File lib/transloadit/api_model.rb, line 29
def inspect
  self.to_hash.inspect
end
to_hash() click to toggle source

@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
to_json() click to toggle source

@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

_do_request(path, params = nil, method = 'get', extra_params = nil) click to toggle source

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