Giter Club home page Giter Club logo

simplenote-js's Introduction

simplenote-js

A JS wrapper for the SimpleNote API. Routes all requests through YQL (via HTTPS) using the included Open Data table (see src/ folder). Needs jQuery.

Regarding YQL

All requests to the SimpleNote API are routed through YQL via HTTPS since cross-domain POST requests aren't possible with AJAX. For that, simplenote-js is making use of a custom Open Data table (see src/yql_simplenote.xml). The default table URL is this GitHub project's raw view of that file. It might be a good idea to host your own table XML somewhere to have more control over what is going on between YQL and SimpleNote API, and to be unaffected by changes to the table that might occur during future development and which may break functionality in case of a version mismatch between the JS library you're using and the table file in this here GitHub repository. (See SimpleNote's setOpenDataTable() method for that.)

Usage

It's rather straightforward: first, authenticate, and if you've done so successfully, go nuts.

Authenticating:

var s = new SimpleNote();
SN.enableDebug( true );   // because we're curious
SN.auth({
  email: "[email protected]",
  password: "myPassword",
  success: function() {
    console.log( SN.isLoggedIn() );
    // >> true
  },
  error: function( code ) {
    console.error( "Authentication error: " + code );
  }
});

Searching for notes:

SN.searchNotes({
  query: "simplenote",
  maxResults: 3,
  success: function( resultsHash ) {
    console.info( resultsHash.totalRecords );
    // >> 32 (or some other number)
    
    console.info( resultsHash.notes );
    // >> [
    // >>   {
    // >>     key: "[SimpleNote-internal ID string]",
    // >>     body: "this is a note\nwith more than one line"
    // >>   },
    // >>   {
    // >>     key: "[another SimpleNote-internal ID string]",
    // >>     body: "this is a another note\nwith more than one line"
    // >>   },
    // >>   {
    // >>     key: "[yet another SimpleNote-internal ID string]",
    // >>     body: "this is a 3rd note"
    // >>   }
    // >> ]
  },
  error: function( code ) {
    console.error( code );
  }
});

Getting the notes index:

SN.retrieveIndex({
  success: function( resultsArray ) {
    console.info( resultsArray );
    // >> [
    // >>   {
    // >>     key: "[SimpleNote-internal ID string]",
    // >>     deleted: false,
    // >>     modify: "2010-08-27 12:47:11.259777"
    // >>   },
    // >>   {
    // >>     key: "[another SimpleNote-internal ID string]",
    // >>     deleted: true,
    // >>     modify: "2010-07-27 05:12:09.158457"
    // >>   },
    // >>   …
    // >> ]
  },
  error: function( code ) {
    console.error( code );
  }
});

Creating a note:

SN.createNote({
  body: "This is a new note!\nIt's awesome.",
  success: function( noteID ) {
    console.info( noteID );
    // >> "[new SimpleNote-internal ID string]"
  },
  error: function( code ) {
    console.error( code );
  }
});

Updating a note:

SN.updateNote({
  key: "[SimpleNote-internal ID string]",
  body: "This is the revised note!\nIt's even awesomer.",
  success: function( noteID ) {
    console.info( noteID );
    // >> "[SimpleNote-internal ID string]"
  },
  error: function( code ) {
    console.error( code );
  }
});

Retrieving a note:

SN.retrieveNote({
  key: "[SimpleNote-internal ID string]",
  success: function( noteHash ) {
    console.info( noteHash );
    // >> {
    // >>   body: "my example note",
    // >>   key: "[SimpleNote-internal ID string]",
    // >>   modifydate: "2008-12-18 04:04:20.554442",
    // >>   createdate: "2008-12-18 04:03:31.123456",
    // >>   deleted: false
    // >> }
  },
  error: function( code ) {
    console.error( code );
  }
});

Deleting a note:

SN.deleteNote({
  key: "[SimpleNote-internal ID string]",
  success: function( noteID ) {
    console.info( noteID );
    // >> "[SimpleNote-internal ID string]"
  },
  error: function( code ) {
    console.error( code );
  }
});

Documentation

The SimpleNote API documentation is available from the SimpleNote API Google Groups page.

The simplenote-js API documentation can be generated locally with YUIDoc (run make docs in the repo's root folder); the latest version is available online here.

Tests

There's a QUnit-based test suite (tests-in-tests/ shocker!) with 130+ tests.

Requirements

Author

Carlo Zottmann, municode.de, [email protected]. Nice to meet you.

License

Dual-license, MIT & GNU GPL v2.

simplenote-js's People

Contributors

czottmann avatar

Watchers

Jobe Roberts avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.