Skip to content
This repository has been archived by the owner on Dec 12, 2023. It is now read-only.

Commit

Permalink
Massage response of custom fields list
Browse files Browse the repository at this point in the history
  • Loading branch information
mattapayne committed Jun 1, 2018
1 parent d2f1ca0 commit 1ebed68
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 7 additions & 1 deletion lib/freshdesk_api_v2/list_only_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def initialize(http)
end

def list
@http.get(endpoint)
fix_list_response(@http.get(endpoint))
end

protected
Expand All @@ -14,5 +14,11 @@ def list
def endpoint
raise StandardError, 'Please implement this method.'
end

def fix_list_response(response)
altered_body = "{\"results\": #{response.body}}"
response.body = altered_body
response
end
end
end
4 changes: 2 additions & 2 deletions spec/freshdesk_api_v2/company_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
method: :get,
path: '/api/v2/company_fields'
}, {
body: [{ id: 1, name: 'Field' }].to_json
body: { results: [{ id: 1, name: 'Field' }] }.to_json
})
end

it 'return a list of hashes corresponding to the fields on a company' do
expect(JSON.parse(subject.list.body)).to be_an_instance_of(Array)
expect(JSON.parse(subject.list.body)).to be_an_instance_of(Hash)
end
end
end
4 changes: 2 additions & 2 deletions spec/freshdesk_api_v2/contact_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
method: :get,
path: '/api/v2/contact_fields'
}, {
body: [{ id: 1, name: 'Field' }].to_json
body: { results: [{ id: 1, name: 'Field' }] }.to_json
})
end

it 'return a list of hashes corresponding to the fields on a contact' do
expect(JSON.parse(subject.list.body)).to be_an_instance_of(Array)
expect(JSON.parse(subject.list.body)).to be_an_instance_of(Hash)
end
end

Expand Down

0 comments on commit 1ebed68

Please sign in to comment.