Skip to content

Instantly share code, notes, and snippets.

View vadimdemedes's full-sized avatar
🇺🇦

Vadim Demedes vadimdemedes

🇺🇦
View GitHub Profile
async.waterfall [
(next) ->
users = red back.createHash 'facebook_uids'
console.log '1'
next null, users
, (users, next) ->
console.log '2'
users.get fbMetadata.uid, (err, reply) ->
console.log "3 = #{ reply }"
next null, reply
# Declaration
findFBUser: (fbMetadata, callback) ->
users = redback.createHash "facebook_uids"
users.get fbMetadata.uid, (err, reply) ->
callback reply
# Usage
@vadimdemedes
vadimdemedes / test.coffee
Created May 13, 2012 14:13
Accessing fields in hooks and validation methods
Mongorito = require 'mongorito'
Mongorito.connect ['127.0.0.1:27017/databaseName']
class User
keys: ['email', 'api_token']
afterCreate: ->
@email
@api_token
var albums = new Chute.API.Albums({ oauth_token: 'OAUTH_TOKEN' });
albums.fetch({ success: function(){
_(albums.models).forEach(function(album){
// album is an instance of Chute.API.Album
});
}, error: function(){
// something wrong happened
}});
var album = new Chute.API.Album({ album: 'ALBUM_SHORTCUT' });
album.fetch({ success: function(){
var name = album.get('name'); // get album's name
}});
var album = new Chute.API.Album({ album: 'ALBUM_SHORTCUT' });
album.assets({ success: function(assets){
_(assets).forEach(function(asset){
// asset is an instance of Chute.API.Asset
});
}});
var assets = new Chute.API.Assets({ album: 'ALBUM_SHORTCUT' });
assets.fetch({ success: function(){
_(assets.models).forEach(function(asset){
// asset is an instance of Chute.API.Asset
});
}});
var assets = new Chute.API.Assets({ album: 'ALBUM_SHORTCUT', username: 'steve' }); // fetching only assets of user 'steve'
assets.fetch({ success: function(){
_(assets.models).forEach(function(asset){
// asset is an instance of Chute.API.Asset
});
}});
var asset = new Chute.API.Asset({ album: 'ALBUM_SHORTCUT', asset: 'ASSET_SHORTCUT' });
asset.fetch({ success: function(){
var url = asset.get('url'); // getting asset's URL
}});
var asset = new Chute.API.Asset({ album: 'ALBUM_SHORTCUT', asset: 'ASSET_SHORTCUT' });
if(asset.hearted() == false) { // use hearted() method to check if asset was already hearted by this client before
asset.heart({ success: function(){
// asset hearted
}});
} else {
asset.unheart({ success: function(){
// asset unhearted
}});