Skip to content
This repository has been archived by the owner on Aug 20, 2019. It is now read-only.

Cannot get response in json same as webhook #40

Open
faethonm opened this issue Apr 6, 2016 · 1 comment
Open

Cannot get response in json same as webhook #40

faethonm opened this issue Apr 6, 2016 · 1 comment

Comments

@faethonm
Copy link

faethonm commented Apr 6, 2016

Hi

I am using the api to access data in two ways( webhook and normal request
so
result = FullContact.person(email: email, webhookBody: 'json', webhookUrl: webhook_url) returns the results in json format
but
FullContact.person(email: email, format: 'json') returns the results in Hashie format

How can i get the same format(json) in both requests?

Thank you for the help

@Xorlev
Copy link
Contributor

Xorlev commented Apr 7, 2016

When you say the webhook call returns results in JSON format, do you refer to the handler receiving the webhook back from FullContact?

To effect the same transformation we do, you can use plissken to convert the camelCase keys to snake_case. It just monkeypatches Hash to have a .to_snake_keys() method. See https://github.com/fullcontact/fullcontact-api-ruby/blob/master/lib/faraday/response/rubyize.rb for how that works.

It's similar for wrapping the response in hashie structs:

https://github.com/lostisland/faraday_middleware/blob/master/lib/faraday_middleware/response/mashify.rb#L23-L31

If it's a hash, wrap it in Hashie::Mash. If it's an array, recursively call the method, otherwise leave it be.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants