Closed vzsg closed 10 years ago
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?
Given the following line:
pusher.list(5629499534213120, 'test list', ['1234', '5678']);
The original version results in empty messages:
With the JSON body, the contents show up properly:
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
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.
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.
Thanks, merged and 0.3.0 released on npm with the fix.
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.