var vimeoKey = require('./vimeo-key').key;
var vimeo = require('vimeo')(vimeoKey.key, vimeoKey.secret);

// vimeo.area(method[, params[, access]], callback)

var ITEMS_PER_PAGE = 50;

//defaults
var params = { page: 1, per_page: 25, full_response: true };


exports.search = function(query, req, res){
	
	if (!query || query === undefined)
		return res.json(invalidRequest());

	if (res.query.sort)
		params.sort = req.query.sort;

	params.query = query;
	
	vimeo.videos('search', params, function(err, result){
		res.json(result);
	});
}

exports.getCategories = function(req, res){

	vimeo.categories('getAll', params, function(err, result){
		res.json(result);
	});
}

exports.getCategoryVideos = function(category, req, res){

	if (!category || category === undefined)
		return res.json(invalidRequest());

	params.category = category;

	vimeo.categories('getRelatedVideos', params, function(err, result){
		res.json(result);
	});
}

exports.getChannels = function(req, res){

	if (req.query.sort)
		params.sort = req.query.sort;


	vimeo.channels('getAll', params, function(err, result){
		res.json(result);
	});
}

exports.getChannelVideos = function(channelId, req, res){

	if (!channelId || channelId === undefined)
		return res.json(invalidRequest());		

	params.channel_id = channelId;

	vimeo.channels('getVideos', params, function(err, result){
		res.json(result);
	});
}

exports.getVideo = function(videoId, req, res){

	if (!videoId || videoId === undefined)
		return res.json(invalidRequest());

	params.video_id = videoId;

	vimeo.videos('getInfo', params, function(err, result){
		res.json(result);
	});
}


var noResults = function(message){
	return { error: message || 'No Results.' }
}

var invalidRequest = function(message){
	return { error: message || 'Invalid Request' }
}





@@ -203,16 +203,18 @@
 ams = %7B 
+%0A%09
 page: 1,
@@ -214,16 +214,18 @@
 age: 1, 
+%0A%09
 per_page
@@ -230,16 +230,18 @@
 ge: 25, 
+%0A%09
 full_res
@@ -251,17 +251,42 @@
 se: true
- 
+,%0A%09short_response: false %0A
 %7D;%0A%0A%0Aexp
@@ -328,16 +328,71 @@
 res)%7B%0A%09%0A
+%09if (req.query.page)%0A%09%09params.page = req.query.page;%0A%0A%0A
 %09if (!qu
@@ -464,17 +464,17 @@
 %0A%09if (re
-s
+q
 .query.s
@@ -600,32 +600,47 @@
 %09res.json(result
+ %7C%7C noResults()
 );%0A%09%7D);%0A%7D%0A%0Aexpor
@@ -679,16 +679,71 @@
  res)%7B%0A%0A
+%09if (req.query.page)%0A%09%09params.page = req.query.page;%0A%0A%0A
 %09vimeo.c
@@ -802,32 +802,47 @@
 %09res.json(result
+ %7C%7C noResults()
 );%0A%09%7D);%0A%7D%0A%0Aexpor
@@ -891,24 +891,79 @@
 req, res)%7B%0A%0A
+%09if (req.query.page)%0A%09%09params.page = req.query.page;%0A%0A%0A
 %09if (!catego
@@ -1138,32 +1138,47 @@
 %09res.json(result
+ %7C%7C noResults()
 );%0A%09%7D);%0A%7D%0A%0Aexpor
@@ -1207,32 +1207,86 @@
 ion(req, res)%7B%0A%0A
+%09if (req.query.page)%0A%09%09params.page = req.query.page;%0A%0A
 %09if (req.query.s
@@ -1390,32 +1390,47 @@
 %09res.json(result
+ %7C%7C noResults()
 );%0A%09%7D);%0A%7D%0A%0Aexpor
@@ -1567,16 +1567,70 @@
 ());%09%09%0A%0A
+%09if (req.query.page)%0A%09%09params.page = req.query.page;%0A%0A
 %09params.
@@ -1723,32 +1723,48 @@
 %09res.json(result
+  %7C%7C noResults()
 );%0A%09%7D);%0A%7D%0A%0Aexpor
@@ -1972,31 +1972,65 @@
 ult)%7B%0A%09%09
-res.json(result
+console.log(err)%0A%09%09res.json(result %7C%7C noResults()
 );%0A%09%7D);%0A

Add pagination to api