Skip to content

Commit

Permalink
Merge branch 'enhance/response-with-offset' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
CarolHsu committed Nov 2, 2018
2 parents 8dad58b + 5804b07 commit f577e3a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions lib/hubspot/company.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions spec/lib/hubspot/company_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit f577e3a

Please # to comment.