Class: Europeana::API::FaradayMiddleware::ParseJsonToVarious
- Inherits:
-
FaradayMiddleware::ResponseMiddleware
- Object
- FaradayMiddleware::ResponseMiddleware
- Europeana::API::FaradayMiddleware::ParseJsonToVarious
- Defined in:
- lib/europeana/api/faraday_middleware/response/parse_json_to_various.rb
Overview
Handles JSON parsing of API responses
Returns the response as either a ‘Hash` (default) or an `OpenStruct`.
To set the response format to be ‘OpenStruct`: “`ruby Europeana::API.configure do |config|
config.parse_json_to = OpenStruct
end “‘
If using ‘OpenStruct`, changes “-” in JSON field keys to “_”, so that they become methods.
Class Method Summary collapse
Class Method Details
.underscore_hash_keys(hash) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/europeana/api/faraday_middleware/response/parse_json_to_various.rb', line 42 def underscore_hash_keys(hash) hash.keys.each do |k| hash[k] = underscore_hash_keys(hash[k]) if hash[k].is_a?(Hash) hash[k.underscore] = hash.delete(k) if k =~ /-/ end hash end |