lib/preservation/client/versioned_api_service.rb in preservation-client-6.1.0 vs lib/preservation/client/versioned_api_service.rb in preservation-client-6.2.0

- old
+ new

@@ -19,11 +19,11 @@ resp = connection.get do |req| req.url req_url req.headers['Content-Type'] = 'application/json' req.headers['Accept'] = 'application/json' end - return JSON.parse(resp.body).with_indifferent_access if resp.success? + return with_indifferent_access_for(JSON.parse(resp.body)) if resp.success? errmsg = ResponseErrorFormatter .format(response: resp, object_id: object_id, client_method_name: caller_locations.first.label) raise UnexpectedResponseError, errmsg rescue Faraday::ResourceNotFound @@ -105,9 +105,19 @@ LockedError when 409 ConflictError else UnexpectedResponseError + end + end + + def with_indifferent_access_for(obj) + if obj.is_a?(Array) + obj.map { |member| with_indifferent_access_for(member) } + elsif obj.is_a?(Hash) + obj.with_indifferent_access + else + obj end end end end end