'use strict';

var makeRequest = require('./api-request').makeRequest;
var jsonParser = require('./json-parser');

var API_URL = 'https://api.vimeo.com/';

// so, this could be a security issue...because anyone can read the access token from the source.
// however, if the access token set doesn't have any priviliges, then what's the harm?
if (! process.env.VIMEO_ACCESS_TOKEN) {
	throw 'VIMEO_ACCESS_TOKEN must be set in environment variables';
}

module.exports = {
	// callback in node style
	video: function(vimeoId, callback) {
		makeRequest({
			url: API_URL + 'videos/' + vimeoId,
			responseParser: jsonParser,
			onLoad: function(data) {
				callback(null, data);
			},
			onError: callback,
			headers: {
				'Authorization': 'bearer ' + process.env.VIMEO_ACCESS_TOKEN
			}
		});
	}
};
@@ -443,16 +443,33 @@
 es';%0A%7D%0A%0A
+var cache = %7B%7D;%0A%0A
 module.e
@@ -544,16 +544,103 @@
 back) %7B%0A
+%09%09if ( cache.hasOwnProperty(vimeoId)) %7B%0A%09%09%09callback(null, cache%5BvimeoId%5D);%0A%09%09%7D else %7B%0A%09
 %09%09makeRe
@@ -647,16 +647,17 @@
 quest(%7B%0A
+%09
 %09%09%09url: 
@@ -687,16 +687,17 @@
 imeoId,%0A
+%09
 %09%09%09respo
@@ -722,16 +722,17 @@
 ser,%0A%09%09%09
+%09
 onLoad: 
@@ -748,16 +748,45 @@
 data) %7B%0A
+%09%09%09%09%09cache%5BvimeoId%5D = data;%0A%09
 %09%09%09%09call
@@ -810,11 +810,13 @@
 %0A%09%09%09
+%09
 %7D,%0A
+%09
 %09%09%09o
@@ -836,16 +836,17 @@
 ack,%0A%09%09%09
+%09
 headers:
@@ -848,16 +848,17 @@
 ders: %7B%0A
+%09
 %09%09%09%09'Aut
@@ -920,16 +920,22 @@
 %0A%09%09%09
+%09
 %7D%0A
+%09
 %09%09%7D);%0A
+%09%09%7D%0A
 %09%7D%0A%7D

add cache to vimeo-api