gratipay / gratipay.com

Here lieth a pioneer in open source sustainability. RIP
https://gratipay.news/the-end-cbfba8f50981
MIT License
1.12k stars 308 forks source link

Make *.json API support JSONP callback #873

Closed jeresig closed 11 years ago

jeresig commented 11 years ago

For example: https://www.gittip.com/whit537/public.json

Should support: https://www.gittip.com/whit537/public.json?callback=test

Which would return:

test({"receiving": "262.98", "giving": "88.41", "elsewhere": {"bitbucket": "https://bitbucket.org/api/1.0/users/whit537", "github": "https://api.github.com/users/whit537", "twitter": "https://api.twitter.com/1/users/show.json?id=34175404&include_entities=1"}, "my_tip": "1.00", "goal": null})
chadwhitacre commented 11 years ago

I implemented this as a one-off for public.json, and started a branch in aspen-python for the general case. Let's reticket other specific Gittip endpoints that need this.

chadwhitacre commented 11 years ago

Blech. Deploy fail. "Heroku push rejected due to an unrecognized error." Sec ...

chadwhitacre commented 11 years ago

I believe this is working now:

https://www.gittip.com/whit537/public.json?callback=test

jeresig commented 11 years ago

Awesome! Some cursory testing seems to show that it's working well.

No callback param: JSON ?callback=test: test(...) ?callback=: Error ?callback=#$(*&%: Error

Good job - and thanks!

chadwhitacre commented 11 years ago

:)

rummik commented 11 years ago

I'm not getting valid JSONP when passing the callback parameter.

Without passing the param (JSON-y as expected): {"elsewhere": {"github": "https://api.github.com/users/whit537", "bitbucket": "https://bitbucket.org/api/1.0/users/whit537", "twitter": "https://api.twitter.com/1/users/show.json?id=34175404&include_entities=1"}, "giving": "88.41", "avatar": "https://www.gravatar.com/avatar/fb054b407a6461e417ee6b6ae084da37.jpg?s=128", "username": "whit537", "receiving": "264.73", "id": 1451, "goal": null}

With the param (looks like a Python-y thing rather than a JSONP-y thing): test({'elsewhere': {'github': 'https://api.github.com/users/whit537', 'bitbucket': 'https://bitbucket.org/api/1.0/users/whit537', 'twitter': u'https://api.twitter.com/1/users/show.json?id=34175404&include_entities=1'}, 'giving': '88.41', 'avatar': u'https://www.gravatar.com/avatar/fb054b407a6461e417ee6b6ae084da37.jpg?s=128', 'username': u'whit537', 'receiving': '264.73', 'id': 1451L, 'goal': None})

(Sorry about the reopen by the way ^^;)

chadwhitacre commented 11 years ago

Good catch, rummik, thanks. Try now?

https://www.gittip.com/whit537/public.json?callback=test

rummik commented 11 years ago

Yup, that works perfect! :+1:

chadwhitacre commented 11 years ago

:)