Work with binary data and catch more exceptions

This commit is contained in:
2017-10-13 18:46:22 -06:00
parent be39849693
commit c7309c4136
4 changed files with 51 additions and 19 deletions
+11
View File
@@ -2,6 +2,9 @@ import json, requests, time
from crypt import EncryptionHelper
class SNAPIException(Exception):
pass
class RESTAPI:
def __init__(self, base_url):
self.base_url = base_url
@@ -27,11 +30,19 @@ class StandardNotesAPI:
def genKeys(self, password):
pw_info = self.getAuthParamsForEmail()
if 'error' in pw_info:
raise SNAPIException(pw_info['error']['message'])
return self.encryption_helper.pure_generatePasswordAndKey(password, pw_info['pw_salt'], pw_info['pw_cost'])
def signIn(self, keys):
self.keys = keys
res = self.api.post('/auth/sign_in', dict(email=self.username, password=self.keys['pw']))
if 'error' in res:
raise SNAPIException(res['error']['message'])
self.api.addHeader(dict(Authorization='Bearer ' + res['token']))
def sync(self, dirty_items):