Giter Club home page Giter Club logo

hoodie-client.js's Introduction

API

Setup

couchDB_endpoint = 'http://worlddominatorapp.iriscouch.com';
hoodie = new Hoodie(couchDB_endpoint);

Accounts / Sessions

Sign Up

app.account.sign_up('[email protected]', 'secret')

  .done( function(user) {
    user.email // '[email protected]'
    user.uuid  // auto generated
    
    // data sync kicks in
  } ) 
  
  // signup error
  .fail( function(err) {
    alert("Oops: " + err.message)
  } ) 

Sign In

app.account.sign_in('[email protected]', 'secret')

  .done( function(user) {
    // data sync kicks in
  } ) 
  .fail( function(err) {
    alert("Oops: " + err.message)
  } ) 

Change password

app.account.change_password('current_secret', 'new_secret')

  .done( function(user) { } ) 
  .fail( function(err)  { } )

Sign Out

app.account.sign_out()

  .done( function() {
    // session ends, local data gets cleaned up
  } ) 
  .fail( function(err) {
    alert("Oops: " + err.message)
  } ) 

Forgot Password

app.account.forgot_password('[email protected]')

  .done( function() {
    alert( "Link has been sent to [email protected]")
  } ) 
  .fail( function(err) {
    alert("Oops: " + err.message)
  } )

Data Storage / Sync

uuid

helper to generate unique IDs that you can use to store your objects.

uuid = app.store.uuid(length)

Create / Update

create or update an object.

// create a new object
type = 'rule'
app.store.create( type, {name: "rule the world"} )
  
  .done ( function(new_object) { } )
  .fail ( function(err)        { } )
  
// save an object
id   = 'abc4567'
type = 'rule'
app.store.save( type, id, {name: "rule the world"} )
  
  .done ( function(object) { } )
  .fail ( function(err)        { } )
  
// update an existing object
id   = 'abc4567'
type = 'rule'
app.store.update( type, id, {nr: 1} )
  
  .done ( function(updated_object) { } )
  .fail ( function(err)        { } )

Load

load an existing object

app.store.load( type, id )

  .done ( function(object) { } )
  .fail ( function(err)    { } )

Load all

load all objects available or from a specific type

app.store.loadAll( type )

  .done ( function(objects) { } )
  .fail ( function(err)     { } )

Delete

delete an existing object

app.store.delete( type, id )

  .done ( function(deleted_object) { } )
  .fail ( function(err)            { } )

Remote Updates

subscribe to changes from remote

// new doc created
app.remote.on( 'created', function( type, id, created_object) { } )

// existing doc updated
app.remote.on( 'updated', function( type, id, updated_object) { } )

// doc deleted
app.remote.on( 'deleted', function( type, id, deleted_object) { } )

// any of above events
app.remote.on( 'changed', function( type, id, changed_object) { } )

// all listeners can be filtered by type
app.remote.on( "created:couch", function( id, created_object) { } )
app.remote.on( "updated:couch", function( id, updated_object)  { } )
app.remote.on( "deleted:couch", function( id, deleted_object) { } )
app.remote.on( "changed:couch", function( id, changed_object) { } )

Send E-Mails

hell, yeah!

email = {
  to      : ['[email protected]'],
  cc      : ['[email protected]'],
  subject : 'rule the world',
  body    : "we can do it!\nSigned, Joe"
}

app.email.send( email )

  // synched to server
  .progress ( function(email) { } )

  // email sent successfully
  .done     ( function(email) { } )

  // something went wrong
  .fail     ( function(err)   { } )

Future Ideas

  • sharing
  • searching
  • payments
  • file conversion
  • ... ?

Dependencies

Hoodie depends on and require.js. It currently also depends on jQuery/zepto, but we will remove the dependance soon.

Contribute

When you feel like contributing, I highly recommend to install PhantomJS for automated, headless testing. Run $ cake autotest to have test running in the background while hacking.

When you're done with changes, make sure to run $ r.js -o name=hoodie baseUrl=./compiled out=hoodie.min.js to update the concatenated & minified js file for production use.

License & Copyright

(c) 2012 Gregor Martynus [email protected] Licensed under the Apache License 2.0.

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.