Class: CONTENTdmAPI::Response
- Inherits:
-
Object
- Object
- CONTENTdmAPI::Response
- Defined in:
- lib/contentdm_api/response.rb
Overview
A class to parse API responses.
Instance Attribute Summary collapse
-
#raw_data ⇒ Object
Returns the value of attribute raw_data.
Instance Method Summary collapse
- #initialize(raw_data: '') ⇒ Void constructor
-
#parsed ⇒ Hash
A parsed JSON string response that handles cases where the API does not return valid JSON (Response only supports JSON responses for now).
Constructor Details
#initialize(raw_data: '') ⇒ Void
8 9 10 |
# File 'lib/contentdm_api/response.rb', line 8 def initialize(raw_data: '') @raw_data = raw_data end |
Instance Attribute Details
#raw_data ⇒ Object
Returns the value of attribute raw_data.
4 5 6 |
# File 'lib/contentdm_api/response.rb', line 4 def raw_data @raw_data end |
Instance Method Details
#parsed ⇒ Hash
A parsed JSON string response that handles cases where the API does not return valid JSON (Response only supports JSON responses for now).
16 17 18 19 20 21 |
# File 'lib/contentdm_api/response.rb', line 16 def parsed JSON.parse(raw_data) rescue => e # The contentdm_api api spits out HTML when it can't find a collection { 'code' => '-2', 'message' => e.to_s } end |