Class: Patchboard::Response
- Inherits:
-
Object
- Object
- Patchboard::Response
- Defined in:
- lib/patchboard/response.rb
Defined Under Namespace
Modules: Headers
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#parsed_headers ⇒ Object
readonly
Returns the value of attribute parsed_headers.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
-
#initialize(raw) ⇒ Response
constructor
A new instance of Response.
- #method_missing(name, *args, &block) ⇒ Object
- #parse_headers ⇒ Object
- #respond_to?(*args) ⇒ Boolean
Constructor Details
#initialize(raw) ⇒ Response
Returns a new instance of Response.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/patchboard/response.rb', line 47 def initialize(raw) @raw = raw if @raw.headers["Content-Type"] if @raw.headers["Content-Type"] =~ %r{application/.*json} @data = JSON.parse @raw.body, :symbolize_names => true end end @parsed_headers = {} parse_headers end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/patchboard/response.rb', line 67 def method_missing(name, *args, &block) if @raw.respond_to? name @raw.send(name, *args, &block) else super end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
46 47 48 |
# File 'lib/patchboard/response.rb', line 46 def data @data end |
#parsed_headers ⇒ Object (readonly)
Returns the value of attribute parsed_headers.
46 47 48 |
# File 'lib/patchboard/response.rb', line 46 def parsed_headers @parsed_headers end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw.
46 47 48 |
# File 'lib/patchboard/response.rb', line 46 def raw @raw end |
#resource ⇒ Object
Returns the value of attribute resource.
45 46 47 |
# File 'lib/patchboard/response.rb', line 45 def resource @resource end |
Instance Method Details
#parse_headers ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/patchboard/response.rb', line 58 def parse_headers @raw.headers.each do |name, string| case name when /www-authenticate/i @parsed_headers["WWW-Authenticate"] = Headers.parse_www_auth(string) end end end |
#respond_to?(*args) ⇒ Boolean
75 76 77 |
# File 'lib/patchboard/response.rb', line 75 def respond_to?(*args) @raw.respond_to?(*args) || super end |