Skip to content

Commit

Permalink
[0.1.1] More organized responses, response time, and more
Browse files Browse the repository at this point in the history
  • Loading branch information
alejandro committed Dec 19, 2011
1 parent e39163c commit 95b0ef0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
5 changes: 5 additions & 0 deletions examples/all.js
@@ -0,0 +1,5 @@
var vimeo = require('../index').vimeo;

vimeo('user','brad','videos',function(err,data){
console.log(err || data);
});
48 changes: 42 additions & 6 deletions lib/vimeo.js
Expand Up @@ -28,13 +28,21 @@ var ep = {
*/

var video = vimeo.video = function req(id,cb){
var now = new Date().getTime();
var url = ep.video + id + '.json';
request(ep.video + id + '.json', function(err,res){
if (res.statusCode === 200) {
this.raw = this.get = JSON.parse(res.body)[0];
this.thumb = {s: this.raw.thumbnail_small,m:this.raw.thumbnail_medium,l:this.raw.thumbnail_large };
this.username = { name: this.raw.user_name, portrait:this.raw.user_portrait_medium} ;
cb(null,this);
var data = {
time: new Date().getTime() - now ,
statusCode: res.statusCode,
raw: this.raw,
thumb: this.thumb,
username:this.username
}
cb(null,data);
} else {
cb({"error":"request denied","data":err},null);
}
Expand All @@ -57,11 +65,18 @@ var userOption = {
"groups":"Groups the user has created and joined"
}
var user = vimeo.user = function(usr,req, cb){
var now = new Date().getTime();
if (userOption.hasOwnProperty(req)) {
request(ep.root + usr + '/' + req + '.json', function(err,res){
if (res.statusCode === 200){
var body = JSON.parse(res.body) || [];
cb(null,{items: body.length,data:body});
var data = {
time: new Date().getTime() - now ,
statusCode: res.statusCode,
body: body,
items: body.length
}
cb(null,data);
} else {
cb({"error":"user no exists", "data": usr },null);
}
Expand All @@ -78,11 +93,18 @@ var user = vimeo.user = function(usr,req, cb){
*
*/
var activity = vimeo.activity = function(usr,req,cb){
var now = new Date().getTime();
if (activyOptions.hasOwnProperty(req)){
request(ep.activity + usr + '/' + req + '.json', function(err,res){
if (res.statusCode === 200) {
var body = JSON.parse(res.body);
cb(null, {items:body.length,data:body});
var body = JSON.parse(res.body);
var data = {
time: new Date().getTime() - now ,
statusCode: res.statusCode,
body: body,
items: body.length
}
cb(null, data);
} else {
cb({"error": "user no exist", "data":usr},null);
}
Expand Down Expand Up @@ -111,6 +133,7 @@ var albumOption = {
"info":"Album info for the specified album"
}
var all = vimeo.vimeo = function (type, id,req, cb){
var now =Date.now();
var url,error = null;
switch(type) {
case 'group':
Expand Down Expand Up @@ -152,7 +175,13 @@ var all = vimeo.vimeo = function (type, id,req, cb){
this.raw = JSON.parse(res.body)[0];
this.thumb = {s: this.raw.thumbnail_small,m:this.raw.thumbnail_medium,l:this.raw.thumbnail_large };
this.username = { name: this.raw.user_name, portrait:this.raw.user_portrait_medium} ;
cb(null,this);
data = {
time: Date.now() - now,
raw: this.raw,
thumb: this.thumb,
username: this.username
}
cb(null,data);
} else {
cb({"error":"request denied","data":err},null);
}
Expand All @@ -161,7 +190,14 @@ var all = vimeo.vimeo = function (type, id,req, cb){
request( url + '.json', function(err,res){
if (res.statusCode === 200) {
var body = JSON.parse(res.body);
cb(null, {items:body.length,data:body});
data = {
status:'ok',
statusCode: res.statusCode,
time: Date.now() - now,
items: body.length,
body: body
}
cb(null, data);
} else {
cb({"error": "user no exist", "data":id},null);
}
Expand Down

0 comments on commit 95b0ef0

Please sign in to comment.