diff --git a/lib/pco/api/endpoint.rb b/lib/pco/api/endpoint.rb index bf130ee..86053d9 100644 --- a/lib/pco/api/endpoint.rb +++ b/lib/pco/api/endpoint.rb @@ -5,6 +5,10 @@ module PCO module API URL = 'https://api.planningcenteronline.com' + class Response < Hash + attr_accessor :headers + end + class Endpoint attr_reader :url, :last_result @@ -69,8 +73,8 @@ def delete def _build_response(result) case result.status when 200..299 - res = result.body - res['headers'] = result.headers + res = Response[result.body] + res.headers = result.headers res when 400 fail Errors::BadRequest, result diff --git a/lib/pco/api/errors.rb b/lib/pco/api/errors.rb index 3d9b4b7..63402cf 100644 --- a/lib/pco/api/errors.rb +++ b/lib/pco/api/errors.rb @@ -4,11 +4,12 @@ module Errors class AuthRequiredError < StandardError; end class BaseError < StandardError - attr_reader :status, :detail + attr_reader :status, :detail, :headers def initialize(response) @status = response.status @detail = response.body + @headers = response.headers end def to_s diff --git a/spec/pco/api/endpoint_spec.rb b/spec/pco/api/endpoint_spec.rb index b70decb..7bc9ad7 100644 --- a/spec/pco/api/endpoint_spec.rb +++ b/spec/pco/api/endpoint_spec.rb @@ -50,6 +50,7 @@ it 'returns the result of making a GET request to the endpoint' do expect(@result).to be_a(Hash) expect(@result['data']).to eq(result) + expect(@result.headers).to eq('Content-Type' => 'application/vnd.api+json') end end @@ -76,6 +77,7 @@ end expect(error.status).to eq(404) expect(error.message).to eq('Resource Not Found') + expect(error.headers).to eq('Content-Type' => 'application/vnd.api+json') end end