support pnut api v1

This commit is contained in:
Morgan McMillian 2021-02-27 10:52:56 -08:00
parent 84e96df945
commit 90a831650a

View file

@ -22,7 +22,7 @@ _connected = threading.Event()
_error = threading.Event() _error = threading.Event()
def subscribe(connection_id): def subscribe(connection_id):
url = f"https://api.pnut.io/v0/channels/{config['CHANNEL']}/messages" url = f"https://api.pnut.io/v1/channels/{config['CHANNEL']}/messages"
url += "?connection_id=" + connection_id url += "?connection_id=" + connection_id
headers = {'Authorization': "Bearer " + config['ACCESS_TOKEN']} headers = {'Authorization': "Bearer " + config['ACCESS_TOKEN']}
r = requests.get(url, headers=headers) r = requests.get(url, headers=headers)
@ -302,7 +302,8 @@ def on_message(ws, message):
if "channel_type" in msg['meta'] and msg['meta']['channel_type'] == "io.pnut.core.chat": if "channel_type" in msg['meta'] and msg['meta']['channel_type'] == "io.pnut.core.chat":
pmsg = pnutpy.models.Message.from_response_data(msg['data']) for d_item in msg['data']:
pmsg = pnutpy.models.Message.from_response_data(d_item)
if 'is_deleted' in msg['meta']: if 'is_deleted' in msg['meta']:
return return
@ -380,7 +381,7 @@ if __name__ == "__main__":
pnutpy.api.add_authorization_token(config['ACCESS_TOKEN']) pnutpy.api.add_authorization_token(config['ACCESS_TOKEN'])
ws_url = "wss://stream.pnut.io/v0/user" ws_url = "wss://stream.pnut.io/v1/user"
ws_url += "?access_token=" + config['ACCESS_TOKEN'] ws_url += "?access_token=" + config['ACCESS_TOKEN']
# setup the websocket connection # setup the websocket connection