Display Filters

class SimpleNote

SimpleNote API wrapper class. Please note that the SimpleNote API expects everything to be UTF-8, and so does simplenote-js.

Constructor

Constructor Parameters Returns
SimpleNote( )

Properties

Properties Type Description
_baseURL String private final

Contains the base URL of the API.

_debugEnabled Boolean private

Enables console output of debugging messages.

Default value: false.

_email String private

After a successful login, this variable holds the account email address required for all subsequent API requests.

_token String private

After a successful login, this variable holds the auth token required for all subsequent API requests.

_version String private final

The simplenote-js version number.

_yqlTableName String private final

Contains the table name used in YQL query.

_yqlTableURL String private

Contains the OpenData table used for all YQL calls.

Default value: http://github.com/carlo/simplenote-js/raw/master/src/yql_simplenote.xml.

VERSION String final

Returns the simplenote-js version number.

Methods

Methods Returns Description
_authenticate( config ) void private

Authenticates the client. The request is made asynchronously via YQL. Throws an exception if one of the arguments is missing or empty.

Parameters:

  • config.email <String>

    SimpleNote account email address

  • config.password <String>

    SimpleNote account password

  • config.success <Function>

    callback function to be called on successful authentication (optional)

  • config.error <Function>

    callback function to be called on failure, is passed a plain text error string (optional)

_clearCredentials( ) void private

Deletes both _email and _token variables.

_createNote( config ) void private

Creates a new note. Returns the new note ID. Throws an exception if one of the arguments is missing or empty.

Parameters:

  • config.body <String>

    the note body

  • config.success <Function>

    callback function to be called on success; the callback will be passed the note ID string

  • config.error <Function>

    callback function to be called on failure, is passed a clear text error string.

_deleteNote( config ) void private

Deletes an existing note. Throws an exception if one of the arguments is missing or empty.

Parameters:

  • config.key <String>

    the ID of the note to delete

  • config.permanently <Boolean>

    set to true if you want to not only mark the note as deleted on the server but to delete it right away (see SN API docs)

  • config.success <Function>

    callback function to be called on success; the callback will be passed the note ID string

  • config.error <Function>

    callback function to be called on failure, is passed a clear text error string.

_getErrorCode( status ) void private

Returns an error code for a passed HTTP status.

Parameters:

  • status <String>

    The HTTP status code returned by YQL.

_getYQLURL( query ) void private

Accepts a YQL query and returns the related YQL URL.

Parameters:

  • query <String>

    YQL query

_isLoggedIn( ) Boolean private

Returns a boolean showing whether the user is currently logged in or not.

_queryYQL( caller, query, cbSuccess, cbError, context ) void private

Proxy method abstracting most YQL calls.

Parameters:

  • caller <String>

    Name of the calling method. Used for log output.

  • query <String>

    The YQL query.

  • cbSuccess <Function>

    The on-success callback.

  • cbError <Function>

    The on-error callback.

  • context <Object>

    The context of the callbacks mentioned above.

_retrieveIndex( config ) void private

Returns an index of all notes. This method will return a JSON object with three main properties for each note: key, modify, and deleted. Some notes may be marked deleted; these notes will be removed permanently the next time the client synchronizes with the server.

Throws an exception if one of the arguments is missing or empty.

The index will be returned as an array containing hashes. The hashes contain the following keys:

  • deleted: true | false
  • key: the note ID
  • modify: a string containing the last-modified date

Parameters:

  • config.success <Function>

    callback function to be called on success; the callback will be passed the array containing the notes index

  • config.error <Function>

    callback function to be called on failure, is passed a plain text error string

_retrieveNote( config ) void private

Retrieves and returns a single note as a hash in the following form:

 {
   body: "my example note",
   key: "agtzaW1wbG0LCxIETm90ZRjoBAw",
   modifydate: "2008-12-18 04:04:20.554442",
   createdate: "2008-12-18 04:04:20.554442",
   deleted: false
 }

Throws an exception if one of the arguments is missing or empty.

Parameters:

  • config.key <String>

    the note ID

  • config.success <Function>

    callback function to be called on success; the callback will be passed the note hash

  • config.error <Function>

    callback function to be called on failure, is passed a clear text error string.

_searchNotes( config ) void private

Returns notes containing a particular term. Throws an exception if one of the arguments is missing or empty.

This method will return a JSON object with two keys, notes (containing an array with found notes) and totalRecords (showing the total number of search results).

Each note is represented as an object containing two keys, key (the note ID) and body (the note string).

Parameters:

  • config.query <String>

    search string

  • config.maxResults <Int>

    (optional): max number of results (default: 10)

  • config.offset <Int>

    (optional) index offset

  • config.success <Function>

    callback function to be called on success; the callback will be passed the array containing the notes index

  • config.error <Function>

    callback function to be called on failure, is passed a clear text error string.

_throwUnlessLoggedIn( ) void private

Throws an exception if either the internal email or token aren't set (which means the user's not logged in).

_updateNote( config ) void private

Updates an existing note. Returns the note ID on success. Throws an exception if one of the arguments is missing or empty.

Parameters:

  • config.key <String>

    the ID of the note to update

  • config.body <String>

    the note body

  • config.success <Function>

    callback function to be called on success; the callback will be passed the note ID string

  • config.error <Function>

    callback function to be called on failure, is passed a clear text error string.

_validateRetrievalConfig( obj ) void private

Checks if the passed argument is an object and has error and success keys which are functions. Throws an ArgumentError exception on failure.

Parameters:

  • obj <Object>

    The object to validate.

auth( config ) void

Authenticates the client. The request is made asynchronously via YQL. Throws an exception if one of the arguments is missing or empty.

Parameters:

  • config.email <String>

    SimpleNote account email address

  • config.password <String>

    SimpleNote account password

  • config.success <Function>

    callback function to be called on successful authentication (optional)

  • config.error <Function>

    callback function to be called on failure, is passed a plain text error string (optional)

createNote( config ) void

Creates a new note. Returns the new note ID. Throws an exception if one of the arguments is missing or empty.

Parameters:

  • config.body <String>

    the note body

  • config.success <Function>

    callback function to be called on success; the callback will be passed the note ID string

  • config.error <Function>

    callback function to be called on failure, is passed a clear text error string.

deleteNote( config ) void

Deletes an existing note. Throws an exception if one of the arguments is missing or empty.

Parameters:

  • config.key <String>

    the ID of the note to delete

  • config.permanently <Boolean>

    set to true if you want to not only mark the note as deleted on the server but to delete it right away (see SN API docs)

  • config.success <Function>

    callback function to be called on success; the callback will be passed the note ID string

  • config.error <Function>

    callback function to be called on failure, is passed a clear text error string.

enableDebug( bool ) void

Enables console output of debugging messages.

Parameters:

  • bool <Boolean>

    Enable/disable debugging.

getAuthDetails( ) Object

Returns auth details, i.e. an object containing the current email address and auth token returned by the API after a successful login.

Returns:

  • <Object>

    Auth info.

getOpenDataTable( ) String

Returns the Open Data table used in all YQL requests.

Returns:

  • <String>

    Open Data Table URL.

isLoggedIn( ) Boolean

Returns a boolean showing whether the user is currently logged in or not.

retrieveIndex( config ) void

Returns an index of all notes. This method will return a JSON object with three main properties for each note: key, modify, and deleted. Some notes may be marked deleted; these notes will be removed permanently the next time the client synchronizes with the server.

Throws an exception if one of the arguments is missing or empty.

Parameters:

  • config.success <Function>

    callback function to be called on success; the callback will be passed the array containing the notes index

  • config.error <Function>

    callback function to be called on failure, is passed a plain text error string

retrieveNote( config ) void

Retrieves and returns a single note as a hash in the following form:

 {
   body: "my example note",
   key: "agtzaW1wbG0LCxIETm90ZRjoBAw",
   modifydate: "2008-12-18 04:04:20.554442",
   createdate: "2008-12-18 04:04:20.554442",
   deleted: false
 }

Throws an exception if one of the arguments is missing or empty.

Parameters:

  • config.key <String>

    the note ID

  • config.success <Function>

    callback function to be called on success; the callback will be passed the note hash

  • config.error <Function>

    callback function to be called on failure, is passed a clear text error string.

searchNotes( config ) void

Returns notes containing a particular term. Throws an exception if one of the arguments is missing or empty.

This method will return a JSON object with two keys, notes (containing an array with found notes) and totalRecords (showing the total number of search results).

Each note is represented as an object containing two keys, key (the note ID) and body (the note string).

Parameters:

  • config.query <String>

    search string

  • config.maxResults <Int>

    (optional): max number of results (default: 10)

  • config.offset <Int>

    (optional) index offset

  • config.success <Function>

    callback function to be called on success; the callback will be passed the array containing the notes index

  • config.error <Function>

    callback function to be called on failure, is passed a clear text error string.

setOpenDataTable( ) void

Sets the Open Data table used in all YQL requests. Usually, you'll want to put the Open Data table XML file (see yql_simplenote.xml) on a server controlled by you so you have full control over it. If you do that, you can tell SimpleNote to use it by setting the new URL with this method.

updateNote( config ) void

Updates an existing note. Returns the note ID on success. Throws an exception if one of the arguments is missing or empty.

Parameters:

  • config.key <String>

    the ID of the note to update

  • config.body <String>

    the note body

  • config.success <Function>

    callback function to be called on success; the callback will be passed the note ID string

  • config.error <Function>

    callback function to be called on failure, is passed a clear text error string.