Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use JSON interface to fix empty 'list' push messages #2

Merged
merged 1 commit into from
Jan 4, 2014
Merged

Conversation

vzsg
Copy link
Contributor

@vzsg vzsg commented Jan 3, 2014

In 0.2.0, list pushes showed up with empty bodies as FWIW multiple items aren't formatted properly in the form-encoded body. I modified the lib to send push requests as JSON (as per PushBullet support's suggestion), and now everything works as intended.

@alexwhitman
Copy link
Owner

I'm hesitant to merge this without the JSON body functionality being fully documented on https://www.pushbullet.com/api. I'll ask the PushBullet guys to update it.

In the mean time, could you give me an example of something that isn't encoding properly?

@vzsg
Copy link
Contributor Author

vzsg commented Jan 4, 2014

Given the following line:

pusher.list(5629499534213120, 'test list', ['1234', '5678']);

The original version results in empty messages:

empty_push
empty_push_website

With the JSON body, the contents show up properly:

fixed_push
fixed_push_website


The first thing I did when I noticed this was asking PushBullet about it. I'm copying the response:

Here is how my from encoded data looks:
title=mytitle&items=test1&items=test2&items=test3&type=list&device_iden=...
Its just &items=...&items=...&items=... like what standard html does it.
We can also try a JSON post if that does not work for you.

Node doesn't seem to create this repeating pattern when an array is passed to the form.

Regarding the JSON body, this python module uses it too: https://github.com/randomchars/pushbullet.py/blob/master/pushbullet/device.py

@alexwhitman
Copy link
Owner

curl https://api.pushbullet.com/api/pushes -u APIKEY: -d 'device_id=DEVICEID&type=list&title=test&items=1&items=2' -X POST works fine but curl https://api.pushbullet.com/api/pushes -u APIKEY: -d 'device_id=DEVICEID&type=list&title=test&items[]=1&items[]=2' -X POST results in an empty list so this looks like a bug on the server side.

Technically there's no standard when it comes to encoding an array (see http://stackoverflow.com/a/9547490) and various languages and libraries do different things. request turns items: ['first', 'second'] into items[0]=first&items[1]=second which is why no items appear in the pushed list.

Arguably this should be fixed on the server side as it definitely did work when I originally built the module. However, if you tidy up your pull request (indents should be tabs, not spaces) and force push so that there's only one commit to keep things tidy then I'll merge.

@vzsg
Copy link
Contributor Author

vzsg commented Jan 4, 2014

Sorry about the mess in the first place.
I'm not really competent with Git, but I think I managed to fix the pull request.

alexwhitman added a commit that referenced this pull request Jan 4, 2014
Use JSON interface to fix empty 'list' push messages
@alexwhitman alexwhitman merged commit 9d5b5bb into alexwhitman:master Jan 4, 2014
@alexwhitman
Copy link
Owner

Thanks, merged and 0.3.0 released on npm with the fix.

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

Successfully merging this pull request may close these issues.

None yet

2 participants