couchDB_endpoint = 'http://worlddominatorapp.iriscouch.com';
hoodie = new Hoodie(couchDB_endpoint);
app.account.sign_up('joe@example.com', 'secret')
.done( function(user) {
user.email // 'joe@example.com'
user.uuid // auto generated
// data sync kicks in
} )
// signup error
.fail( function(err) {
alert("Oops: " + err.message)
} )
app.account.sign_in('joe@example.com', 'secret')
.done( function(user) {
// data sync kicks in
} )
.fail( function(err) {
alert("Oops: " + err.message)
} )
app.account.change_password('current_secret', 'new_secret')
.done( function(user) { } )
.fail( function(err) { } )
If you want to make sure that a user is authenticated with a valid
session, you can use the authenticate
method.
app.account.authenticate()
.done( function(user) {
// you are authenticated, your session is valid
} )
.fail( function(err) {
// sorry, but your not authenticated, probably your session expired
} )
app.account.sign_out()
.done( function() {
// session ends, local data gets cleaned up
} )
.fail( function(err) {
alert("Oops: " + err.message)
} )
app.account.forgot_password('joe@example.com')
.done( function() {
alert( "Link has been sent to joe@example.com")
} )
.fail( function(err) {
alert("Oops: " + err.message)
} )
helper to generate unique IDs that you can use to store your objects.
uuid = app.store.uuid(length)
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 an existing object
app.store.load( type, id )
.done ( function(object) { } )
.fail ( function(err) { } )
load all objects available or from a specific type
app.store.loadAll( type )
.done ( function(objects) { } )
.fail ( function(err) { } )
delete an existing object
app.store.delete( type, id )
.done ( function(deleted_object) { } )
.fail ( function(err) { } )
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) { } )
hell, yeah!
email = {
to : ['susan@example.com'],
cc : ['bill@example.com'],
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) { } )
- sharing
- searching
- payments
- file conversion
- ... ?
Hoodie depends on and require.js. It currently also depends on jQuery/zepto, but we will remove the dependance soon.
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.
(c) 2012 Gregor Martynus g@minutes.io Licensed under the Apache License 2.0.