class Europeana::API::FaradayMiddleware::ParseJsonToVarious
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.
Public Class Methods
underscore_hash_keys(hash)
click to toggle source
# 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