@@ -58,7 +58,7 @@ def __init__(self, username, password):
58
58
self .password = password
59
59
self .header = 'X-Simperium-Token'
60
60
self .token = None
61
- self .mark = "mark "
61
+ self .current = ""
62
62
63
63
def authenticate (self , user , password ):
64
64
""" Method to get simplenote auth token
@@ -115,7 +115,7 @@ def get_note(self, noteid, version=None):
115
115
A tuple `(note, status)`
116
116
117
117
- note (dict): note object
118
- - status (int): 0 on sucesss and -1 otherwise
118
+ - status (int): 0 on success and -1 otherwise
119
119
120
120
"""
121
121
# request note
@@ -151,7 +151,7 @@ def update_note(self, note):
151
151
Returns:
152
152
A tuple `(note, status)`
153
153
- note (dict): note object
154
- - status (int): 0 on sucesss and -1 otherwise
154
+ - status (int): 0 on success and -1 otherwise
155
155
156
156
"""
157
157
# determine whether to create a new note or update an existing one
@@ -202,7 +202,7 @@ def add_note(self, note):
202
202
A tuple `(note, status)`
203
203
204
204
- note (dict): the newly created note
205
- - status (int): 0 on sucesss and -1 otherwise
205
+ - status (int): 0 on success and -1 otherwise
206
206
207
207
"""
208
208
@@ -213,23 +213,30 @@ def add_note(self, note):
213
213
else :
214
214
return "No string or valid note." , - 1
215
215
216
- def get_note_list (self , tags = []):
216
+ def get_note_list (self , data = True , since = None , tags = []):
217
217
""" Method to get the note list
218
218
219
- The method can be passed optional arguments to limit the
220
- the list to notes containing a certain tag. If omitted a list
221
- of all notes is returned.
219
+ The method can be passed optional arguments to limit the list to
220
+ notes containing a certain tag, or only updated since a certain
221
+ Simperium cursor. If omitted a list of all notes is returned.
222
+
223
+ By default data objects are returned. If data is set to false only
224
+ keys/ids and versions are returned. An empty data object is inserted
225
+ for compatibility.
222
226
223
227
Arguments:
224
228
- tags=[] list of tags as string: return notes that have
225
229
at least one of these tags
230
+ - since=cursor Simperium cursor as string: return only changes
231
+ since this cursor
232
+ - data=True If false only return keys/ids and versions
226
233
227
234
Returns:
228
235
A tuple `(notes, status)`
229
236
230
237
- notes (list): A list of note objects with all properties set except
231
238
`content`.
232
- - status (int): 0 on sucesss and -1 otherwise
239
+ - status (int): 0 on success and -1 otherwise
233
240
234
241
"""
235
242
# initialize data
@@ -239,8 +246,13 @@ def get_note_list(self, tags=[]):
239
246
notes = { "index" : [] }
240
247
241
248
# get the note index
242
- # TODO: Using data=false is actually fine with simplenote.vim - sadly no faster though
243
- params = '/index?limit=%s&data=true' % (str (NOTE_FETCH_LENGTH ))
249
+ params = '/index?limit=%s' % (str (NOTE_FETCH_LENGTH ))
250
+
251
+ if since is not None :
252
+ params += '&since=%s' % (since )
253
+ # Fetching data is the default
254
+ if data :
255
+ params += '&data=true'
244
256
245
257
# perform initial HTTP request
246
258
request = Request (DATA_URL + params )
@@ -251,6 +263,9 @@ def get_note_list(self, tags=[]):
251
263
# re-write for v1 consistency
252
264
note_objects = []
253
265
for n in response_notes ["index" ]:
266
+ # If data=False then can't do this bit... or not all of it, just have id and version. Add empty data object.
267
+ if not data :
268
+ n ['d' ] = {}
254
269
note_object = self .__add_simplenote_api_fields (n ['d' ], n ['id' ], n ['v' ])
255
270
note_objects .append (note_object )
256
271
notes ["index" ].extend (note_objects )
@@ -270,14 +285,16 @@ def get_note_list(self, tags=[]):
270
285
# re-write for v1 consistency
271
286
note_objects = []
272
287
for n in response_notes ["index" ]:
288
+ if not data :
289
+ n ['d' ] = {}
273
290
note_object = n ['d' ]
274
- note_object ['version' ] = n ['v' ]
275
- note_object ['key' ] = n ['id' ]
291
+ note_object = self .__add_simplenote_api_fields (n ['d' ], n ['id' ], n ['v' ])
276
292
note_objects .append (note_object )
277
293
notes ["index" ].extend (note_objects )
278
294
except IOError :
279
295
status = - 1
280
296
note_list = notes ["index" ]
297
+ self .current = response_notes ["current" ]
281
298
# Can only filter for tags at end, once all notes have been retrieved.
282
299
if (len (tags ) > 0 ):
283
300
note_list = [n for n in note_list if (len (set (n ["tags" ]).intersection (tags )) > 0 )]
@@ -293,7 +310,7 @@ def trash_note(self, note_id):
293
310
A tuple `(note, status)`
294
311
295
312
- note (dict): the newly created note or an error message
296
- - status (int): 0 on sucesss and -1 otherwise
313
+ - status (int): 0 on success and -1 otherwise
297
314
298
315
"""
299
316
# get note
@@ -321,7 +338,7 @@ def delete_note(self, note_id):
321
338
A tuple `(note, status)`
322
339
323
340
- note (dict): an empty dict or an error message
324
- - status (int): 0 on sucesss and -1 otherwise
341
+ - status (int): 0 on success and -1 otherwise
325
342
326
343
"""
327
344
# notes have to be trashed before deletion
@@ -344,9 +361,13 @@ def __add_simplenote_api_fields(self, note, noteid, version):
344
361
# Compatibility with original Simplenote API v2.1.5
345
362
note [u'key' ] = noteid
346
363
note [u'version' ] = version
347
- note [u'modifydate' ] = note ["modificationDate" ]
348
- note [u'createdate' ] = note ["creationDate" ]
349
- note [u'systemtags' ] = note ["systemTags" ]
364
+ try :
365
+ note [u'modifydate' ] = note ["modificationDate" ]
366
+ note [u'createdate' ] = note ["creationDate" ]
367
+ note [u'systemtags' ] = note ["systemTags" ]
368
+ except KeyError :
369
+ # For when data=False
370
+ pass
350
371
return note
351
372
352
373
def __remove_simplenote_api_fields (self , note ):
0 commit comments