From 5804b073a8c1fdbfaf1e6565c10bf64347d4a46e Mon Sep 17 00:00:00 2001 From: Carol H Date: Fri, 2 Nov 2018 13:51:09 +0800 Subject: [PATCH] [enhance/response-with-offset] return pure hash struct --- lib/hubspot/company.rb | 9 +++++---- spec/lib/hubspot/company_spec.rb | 12 ++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/hubspot/company.rb b/lib/hubspot/company.rb index 58ce991e..9b57b2d9 100644 --- a/lib/hubspot/company.rb +++ b/lib/hubspot/company.rb @@ -60,10 +60,11 @@ def all_with_offset(opts = {}) end response = Hubspot::Connection.get_json(path, opts) - formatted_results = response['results'].map { |c| new(c) } - response = JSON.parse(response.to_json, object_class: OpenStruct) - response.results = formatted_results - response + response_with_offset = {} + response_with_offset['results'] = response['results'].map { |c| new(c) } + response_with_offset['hasMore'] = response['hasMore'] + response_with_offset['offset'] = response['offset'] + response_with_offset end # Finds a list of companies by domain diff --git a/spec/lib/hubspot/company_spec.rb b/spec/lib/hubspot/company_spec.rb index cc0cbc32..e79c5565 100644 --- a/spec/lib/hubspot/company_spec.rb +++ b/spec/lib/hubspot/company_spec.rb @@ -140,10 +140,10 @@ context 'all_with_offset' do it 'should return companies with offset and hasMore' do response = Hubspot::Company.all_with_offset - expect(response.results.size).to eq(20) + expect(response['results'].size).to eq(20) - first = response.results.first - last = response.results.last + first = response['results'].first + last = response['results'].last expect(first).to be_a Hubspot::Company expect(first.vid).to eq(42866817) @@ -155,9 +155,9 @@ it 'must filter only 2 companies' do response = Hubspot::Company.all_with_offset(count: 2) - expect(response.results.size).to eq(2) - expect(response.hasMore).to be_truthy - expect(response.offset).to eq(2) + expect(response['results'].size).to eq(2) + expect(response['hasMore']).to be_truthy + expect(response['offset']).to eq(2) end end end