Skip to content
Permalink
Browse files

Allow get_note to fetch previous versions of a note

  • Loading branch information...
atomicules committed Nov 9, 2013
1 parent c567d61 commit 50e3de947b70fa5d9a7faee004ae20b169a1547d
Showing with 23 additions and 4 deletions.
  1. +10 −4 simplenote/simplenote.py
  2. +13 −0 tests/test_simplenote.py
@@ -81,11 +81,12 @@ def get_token(self):
return self.token


def get_note(self, noteid):
def get_note(self, noteid, version=None):
""" method to get a specific note
Arguments:
- noteid (string): ID of the note to get
- version (int): optional version of the note to get
Returns:
A tuple `(note, status)`
@@ -95,8 +96,11 @@ def get_note(self, noteid):
"""
# request note
params = '/%s?auth=%s&email=%s' % (str(noteid), self.get_token(),
self.username)
params_version = ""
if version is not None:
params_version = '/' + str(version)

params = '/%s%s?auth=%s&email=%s' % (str(noteid), params_version, self.get_token(), self.username)
request = Request(DATA_URL+params)
try:
response = urllib2.urlopen(request)
@@ -107,7 +111,9 @@ def get_note(self, noteid):
note = json.loads(response.read())
# use UTF-8 encoding
note["content"] = note["content"].encode('utf-8')
note["tags"] = [t.encode('utf-8') for t in note["tags"]]
# For early versions of notes, tags not always available
if note.has_key("tags"):
note["tags"] = [t.encode('utf-8') for t in note["tags"]]
return note, 0

def update_note(self, note):
@@ -144,6 +144,19 @@ def test_note_with_plus_signs(self):
if status == 0:
self.assertEqual("++", note["content"])

def test_note_get_previous_version(self):
note_v1, status = Simplenote(self.user, self.password).add_note("Hello")
if status == 0:
note_v2 = {}
note_v2['key'] = note_v1["key"]
note_v2["content"] = "Goodbye"
note_v2, status = Simplenote(self.user, self.password).update_note(note_v2)
if status == 0:
if note_v2["version"] > 1:
note, status = Simplenote(self.user, self.password).get_note(note_v2["key"], note_v2["version"]-1)
if status == 0:
self.assertEqual("Hello", note["content"])

def is_utf8(self, s):
try:
s.decode('utf-8')

0 comments on commit 50e3de9

Please sign in to comment.
You can’t perform that action at this time.