Class: Dropbox::WebClient::ResponseParser
- Inherits:
-
Object
- Object
- Dropbox::WebClient::ResponseParser
- Defined in:
- lib/dropbox/web_client/response_parser.rb
Instance Attribute Summary collapse
-
#response_text ⇒ Object
readonly
Returns the value of attribute response_text.
Instance Method Summary collapse
- #error? ⇒ Boolean
- #error_data ⇒ Object
-
#initialize(response_text, response_type = :json, error_type = :json) ⇒ ResponseParser
constructor
A new instance of ResponseParser.
- #response_data ⇒ Object
Constructor Details
#initialize(response_text, response_type = :json, error_type = :json) ⇒ ResponseParser
Returns a new instance of ResponseParser.
7 8 9 10 11 12 |
# File 'lib/dropbox/web_client/response_parser.rb', line 7 def initialize(response_text, response_type = :json, error_type = :json) @response_text = response_text @error_type = error_type @response_type = response_type end |
Instance Attribute Details
#response_text ⇒ Object (readonly)
Returns the value of attribute response_text.
5 6 7 |
# File 'lib/dropbox/web_client/response_parser.rb', line 5 def response_text @response_text end |
Instance Method Details
#error? ⇒ Boolean
14 15 16 |
# File 'lib/dropbox/web_client/response_parser.rb', line 14 def error? @response_text.start_with? "err:" end |
#error_data ⇒ Object
18 19 20 |
# File 'lib/dropbox/web_client/response_parser.rb', line 18 def error_data JSON.parse(@response_text.split(":", 2)[1]) if error? end |
#response_data ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dropbox/web_client/response_parser.rb', line 30 def response_data if error? Exception.new(error_data) else begin self.class.send("parse_#{@response_type.to_s}", @response_text) rescue NoMethodError raise Exception.new("Unsupported response format") end end end |