class CONTENTdmAPI::Response
A class to parse API responses.
Attributes
raw_data[RW]
Public Class Methods
new(raw_data: '')
click to toggle source
@param [String] raw_data
A string of data received from the CONTENTdm API
@return [Void]
# File lib/contentdm_api/response.rb, line 8 def initialize(raw_data: '') @raw_data = raw_data end
Public Instance Methods
parsed()
click to toggle source
A parsed JSON string response that handles cases where the API does not return valid JSON (Response
only supports JSON responses for now).
@return [Hash] A ruby hash of a CONTENTdm response
# 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