notehub (18 January 2014)
index
/home/sean/projects/notehub/notehub.py

A simple wrapper for the Notehub.org api.
 
A wrapper for the Notehub.org api that simplifies much of the work needed to
make a call. The wrapper handles the work of adding necessary parameters,
hashing passwords, generating signatures, encoding the data and checking
response codes.
 
*************************************************************
***You will need a PID and PSK from http://notehub.org/api***
***in order to use the create_note and update_note methods.**
*************************************************************
 
Example use:
 
    from notehub import Notehub
    from notehub import NotehubError
 
    PID = 'example_pid' # Replace with your PID
    PSK = 'example_psk' # Replace with your PSK
 
    nh = Notehub(PID, PSK)
 
    # get_note
    try:
        note = nh.get_note('2014 1 26 test')
        print(note)
    except NotehubError as e:
        print(e)
 
    # create_note
    note_text = 'Test note 123.'
    try:
        note = nh.create_note(note_text)
        print(note)
    except NotehubError as e:
        print(e)
 
    # create_note with password
    note_text = 'Test note 123.'
    password = 'abc123'
    try:
        note = nh.create_note(note_text, password=password)
        print(note)
    except NotehubError as e:
        print(e)
 
    # create_note with specific theme and fonts
    note_text = 'Test note 123.'
    theme = 'solarized-light'
    text_font = 'Alegreya Sans SC'
    header_font = 'Chau Philomene One'
    try:
        note = nh.create_note(note_text, theme=theme, text_font=text_font,
                              header_font=header_font)
        print(note)
    except NotehubError as e:
        print(e)
 
    # update_note
    note_id = '2014 1 26 test-note-123-1'
    new_note_text = 'Test note 123.'
    password = 'abc123'
    try:
        note = nh.update_note(note_id, new_note_text, password)
        print(note)
    except NotehubError as e:
        print(e)

 
Modules
       
json
requests
sys

 
Classes
       
builtins.Exception(builtins.BaseException)
NotehubError
builtins.object
Notehub

 
class Notehub(builtins.object)
    A wrapper for the Notehub.org api.
 
Attributes:
    pid: The publisher ID received from Notehub.org.
    psk: The publisher secret key received from Notehub.org. 
    version: The api version to use. (Default: '1.2').
 
  Methods defined here:
__init__(self, pid, psk, version='1.2')
Constructor for Notehub object.
 
Args:
    pid: The publisher ID received from Notehub.org.
    psk: The publisher secret key received from Notehub.org.
    version: Optional. Default '1.1'. Which version of the API to use.
create_note(self, note_text, password='', theme='', text_font='', header_font='')
Creates a note on Notehub.org with the given text.
 
Makes a call to Notehub.orgs CREATE NOTE api. To edit a note later
a password must be given. If successful the note's ID and some URLs
linking too it will be returned.
 
Args:
    note_text: The ID of the note to request.
    password: Optional. A password to allow for updating the note.
    theme: Optional. The color theme to use.
    text_font: Optional. Font to use for body text.
    header_font: Optional. Font to use for header text.
 
Returns:
    A dict populated from the JSON response of the API call.
 
Raises:
    NotehubError: There was a problem making the call. Check the
        message.
get_note(self, note_id)
Retreives the text of a note on Notehub.org.
 
Makes a call to Notehub.org's GET NOTE api. This returns
the text of a note from a given note ID. It also returns
some URLs that link to the note and some statistics about it.
 
Args:
    note_id: The ID of the note to request.
 
Returns:
    A dict populated from the JSON response of the API call.
 
Raises:
    NotehubError: There was a problem making the call. Check the
        message.
update_note(self, note_id, new_note_text, password)
Edits a note on Notehub.org.
 
Makes a call to Notehub.org's UPDATE NOTE api. The note must have
been originally created with a password to allow updating. If
successful some URLs that link to the note will be returned.
 
Args:
    note_id: The ID of the note to request.
    new_note_text: The text to replace the existing text with.
    password: The password the note was created with.
 
Returns:
    A dict populated from the JSON response of the API call.
 
Raises:
    NotehubError: There was a problem making the call. Check the
        message.

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
BASE_URL = 'http://notehub.org/api/note'

 
class NotehubError(builtins.Exception)
    Exception thrown by Notehub methods when an error occurs.
 
 
Method resolution order:
NotehubError
builtins.Exception
builtins.BaseException
builtins.object

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Methods inherited from builtins.Exception:
__init__(...)
x.__init__(...) initializes x; see help(type(x)) for signature

Data and other attributes inherited from builtins.Exception:
__new__ = <built-in method __new__ of type object>
T.__new__(S, ...) -> a new object with type S, a subtype of T

Methods inherited from builtins.BaseException:
__delattr__(...)
x.__delattr__('name') <==> del x.name
__getattribute__(...)
x.__getattribute__('name') <==> x.name
__reduce__(...)
__repr__(...)
x.__repr__() <==> repr(x)
__setattr__(...)
x.__setattr__('name', value) <==> x.name = value
__setstate__(...)
__str__(...)
x.__str__() <==> str(x)
with_traceback(...)
Exception.with_traceback(tb) --
set self.__traceback__ to tb and return self.

Data descriptors inherited from builtins.BaseException:
__cause__
exception cause
__context__
exception context
__dict__
__suppress_context__
__traceback__
args

 
Functions
       
md5 = openssl_md5(...)
Returns a md5 hash object; optionally initialized with a string

 
Author
        Sean Watson