Skip to content

Instantly share code, notes, and snippets.

@bsmt
Last active August 29, 2015 14:04
Show Gist options
  • Save bsmt/b87da4982a55c4a41bab to your computer and use it in GitHub Desktop.
Save bsmt/b87da4982a55c4a41bab to your computer and use it in GitHub Desktop.
'''Demonstrates communicating with the Wunderlist 3 websocket API.
This example just sends a ping request of sorts.
First, you must add your client id, device id, and access token to this script.
An easy way to do that is to load Wunderlist in lldb and do this:
[lldb]$breakpoint set -n '-[SRWebSocket initWithURLRequest:]'
[lldb]$r
Process 602 stopped
-> 0x10039b82f: pushq %rbp
0x10039b830: movq %rsp, %rbp
0x10039b833: movq 871062(%rip), %rsi ; "initWithURLRequest:protocols:"
0x10039b83a: xorl %ecx, %ecx
[lldb]$po $rdx
<NSURLRequest: 0x100908d80> { URL: wss://socket.wunderlist.com... }
[lldb]$c
Then, to dump data sent to the server, do the same thing as above but break on
-[SRWebSocket send:].
Oh, and make sure you have ws4py installed. "sudo pip install ws4py"
'''
from ws4py.client.threadedclient import WebSocketClient
CLIENT_ID = "OMITTED"
DEVICE_ID = "OMITTED"
ACCESS_TOKEN = "OMITTED"
WS_URL = "wss://socket.wunderlist.com:8443/api/v1/sync"
WS_URL += "?client_id={}&client_device_id={}&access_token={}".format(CLIENT_ID,
DEVICE_ID,
ACCESS_TOKEN)
class Client(WebSocketClient):
def opened(self):
print("Opened")
self.send('{"type":"health","headers":{"x-client-request-id":"2"}}')
def closed(self, code, reason=None):
print("Closed ({}): {}".format(code, reason))
def received_message(self, msg):
print("Recv: {}".format(msg))
if __name__ == "__main__":
try:
ws = Client(WS_URL)
ws.connect()
ws.run_forever()
except KeyboardInterrupt:
ws.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment