Class: Transloadit::Response

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

Defined Under Namespace

Modules: Assembly

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Creates an enhanced response wrapped around a RestClient response.

Parameters:

  • response (RestClient::Response)

    the JSON response to wrap



14
15
16
# File 'lib/transloadit/response.rb', line 14

def initialize(response)
  __setobj__(response)
end

Instance Method Details

#[](attribute) ⇒ String

Returns the attribute from the JSON response.

Parameters:

  • attribute (String)

    the attribute name to look up

Returns:

  • (String)

    the value for the attribute



24
25
26
# File 'lib/transloadit/response.rb', line 24

def [](attribute)
  body[attribute.to_s]
end

#bodyHash

Returns the parsed JSON body.

Returns:

  • (Hash)

    the parsed JSON body hash



33
34
35
# File 'lib/transloadit/response.rb', line 33

def body
  MultiJson.load __getobj__.body
end

#extend!(mod) ⇒ Transloadit::Response

Chainably extends the response with additional methods. Used to add context-specific functionality to a response.

Parameters:

  • mod (Module)

    the module to extend with

Returns:



53
54
55
56
# File 'lib/transloadit/response.rb', line 53

def extend!(mod)
  extend(mod)
  self
end

#inspectString

Inspects the body of the response.

Returns:

  • (String)

    a human-readable version of the body



42
43
44
# File 'lib/transloadit/response.rb', line 42

def inspect
  body.inspect
end