Class: Tickethub::Response
- Inherits:
-
Object
- Object
- Tickethub::Response
- Defined in:
- lib/tickethub/response/headers.rb,
lib/tickethub/response.rb
Overview
:nodoc:
Defined Under Namespace
Classes: Headers
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #as_json ⇒ Object
- #code ⇒ Object (also: #status)
- #decoded ⇒ Object
-
#initialize(response, parser = nil) ⇒ Response
constructor
A new instance of Response.
- #respond_to?(name) ⇒ Boolean
- #to_json ⇒ Object
Constructor Details
#initialize(response, parser = nil) ⇒ Response
Returns a new instance of Response.
5 6 7 8 9 10 11 |
# File 'lib/tickethub/response.rb', line 5 def initialize(response, parser = nil) @response = response @body = response.body @headers = Headers.new(response.to_hash) @format = Formats.for(headers.content_type) @parser ||= @format && @format.new end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (protected)
37 38 39 40 41 42 43 44 45 |
# File 'lib/tickethub/response.rb', line 37 def method_missing(name, *args, &block) if decoded.respond_to?(name) decoded.send(name, *args, &block) elsif response.respond_to?(name) response.send(name, *args, &block) else super end end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
3 4 5 |
# File 'lib/tickethub/response.rb', line 3 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
3 4 5 |
# File 'lib/tickethub/response.rb', line 3 def headers @headers end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
3 4 5 |
# File 'lib/tickethub/response.rb', line 3 def parser @parser end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
3 4 5 |
# File 'lib/tickethub/response.rb', line 3 def response @response end |
Instance Method Details
#as_json ⇒ Object
13 14 15 |
# File 'lib/tickethub/response.rb', line 13 def as_json decoded end |
#code ⇒ Object Also known as: status
21 22 23 |
# File 'lib/tickethub/response.rb', line 21 def code response.code.to_i end |
#decoded ⇒ Object
27 28 29 |
# File 'lib/tickethub/response.rb', line 27 def decoded @decoded ||= parser ? parser.decode(body) : body end |
#respond_to?(name) ⇒ Boolean
31 32 33 |
# File 'lib/tickethub/response.rb', line 31 def respond_to?(name) super || decoded.respond_to?(name) || response.respond_to?(name) end |
#to_json ⇒ Object
17 18 19 |
# File 'lib/tickethub/response.rb', line 17 def to_json(*) as_json.to_json end |