Class: Transloadit::ApiModel

Inherits:
Object
  • Object
show all
Defined in:
lib/transloadit/api_model.rb

Overview

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

Direct Known Subclasses

Assembly, Template

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transloadit, options = {}) ⇒ ApiModel

Creates a new API instance authenticated using the given transloadit instance.

Parameters:

  • transloadit (Transloadit)

    the associated Transloadit instance

  • options (Hash) (defaults to: {})

    the configuration for the API;



21
22
23
24
# File 'lib/transloadit/api_model.rb', line 21

def initialize(transloadit, options = {})
  self.transloadit = transloadit
  self.options = options
end

Instance Attribute Details

#optionsHash

Returns the options describing the Assembly.

Returns:

  • (Hash)

    the options describing the Assembly



12
13
14
# File 'lib/transloadit/api_model.rb', line 12

def options
  @options
end

#transloaditTransloadit

Returns the associated Transloadit instance.

Returns:

  • (Transloadit)

    the associated Transloadit instance



9
10
11
# File 'lib/transloadit/api_model.rb', line 9

def transloadit
  @transloadit
end

Instance Method Details

#inspectString

Returns a human-readable version of the API.

Returns:

  • (String)

    a human-readable version of the API



29
30
31
# File 'lib/transloadit/api_model.rb', line 29

def inspect
  to_hash.inspect
end

#to_hashHash

Returns a Transloadit-compatible Hash of the API’s contents.

Returns:

  • (Hash)

    a Transloadit-compatible Hash of the API’s contents



36
37
38
39
40
# File 'lib/transloadit/api_model.rb', line 36

def to_hash
  options.merge(
    auth: transloadit.to_hash
  ).delete_if { |_, v| v.nil? }
end

#to_jsonString

Returns JSON-encoded String containing the API’s contents.

Returns:

  • (String)

    JSON-encoded String containing the API’s contents



45
46
47
# File 'lib/transloadit/api_model.rb', line 45

def to_json
  MultiJson.dump(to_hash)
end