Class: InkFilePicker::Response

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ink_file_picker/response.rb

Overview

Public: Simple decorator class for response.

Decorates the response with hash like access to the parsed body, which is expected to be JSON.

Constant Summary collapse

DELEGATE_TO_RESPONSE =
%w[
  success? status headers body finished?
]
DELEGATE_TO_PARSED_BODY =
%w[
  to_hash each
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Response

Returns a new instance of Response.



26
27
28
# File 'lib/ink_file_picker/response.rb', line 26

def initialize(http_response)
  @http_response = http_response
end

Instance Attribute Details

#http_responseObject (readonly)

Returns the value of attribute http_response.



20
21
22
# File 'lib/ink_file_picker/response.rb', line 20

def http_response
  @http_response
end

Instance Method Details

#[](key) ⇒ Object



30
31
32
# File 'lib/ink_file_picker/response.rb', line 30

def [](key)
  parsed_body[key.to_s]
end

#parsed_bodyObject



34
35
36
# File 'lib/ink_file_picker/response.rb', line 34

def parsed_body
  @parsed_body ||= JSON.parse http_response.body
end

#valid?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
43
# File 'lib/ink_file_picker/response.rb', line 38

def valid?
  body == 'success' ||
  parsed_body
rescue JSON::ParserError
  false
end