Permalink
Browse files

Added files from local copy

  • Loading branch information...
0 parents commit 1f9c92d1a6885f689237160b93ca90234aa4ce4a @jleppert committed Mar 13, 2012
Showing with 2,896 additions and 0 deletions.
  1. 0 README
  2. +13 −0 lib/index.js
  3. +12 −0 lib/nodeflix/README.md
  4. +60 −0 lib/nodeflix/index.js
  5. +211 −0 lib/nodeflix/lib/OAuth.js
  6. +68 −0 lib/nodeflix/lib/Request.js
  7. +15 −0 lib/nodeflix/lib/Response.js
  8. +334 −0 lib/nodeflix/lib/sha1.js
  9. +16 −0 lib/nodeflix/package.json
  10. +12 −0 www/css/animations.css
  11. +34 −0 www/css/app.css
  12. +56 −0 www/css/grid.css
  13. +63 −0 www/css/layout.css
  14. +35 −0 www/css/nav.css
  15. +99 −0 www/css/reset.css
  16. BIN www/images/boxart/14546619.jpg
  17. BIN www/images/boxart/408939.jpg
  18. BIN www/images/boxart/443317.jpg
  19. BIN www/images/boxart/445522.jpg
  20. BIN www/images/boxart/528009.jpg
  21. BIN www/images/boxart/541027.jpg
  22. BIN www/images/boxart/60000890.jpg
  23. BIN www/images/boxart/60002556.jpg
  24. BIN www/images/boxart/60020435.jpg
  25. BIN www/images/boxart/60022048.jpg
  26. BIN www/images/boxart/60022922.jpg
  27. BIN www/images/boxart/60023619.jpg
  28. BIN www/images/boxart/60028202.jpg
  29. BIN www/images/boxart/60030359.jpg
  30. BIN www/images/boxart/60030529.jpg
  31. BIN www/images/boxart/60030653.jpg
  32. BIN www/images/boxart/60034311.jpg
  33. BIN www/images/boxart/60035214.jpg
  34. BIN www/images/boxart/70003040.jpg
  35. BIN www/images/boxart/70011274.jpg
  36. BIN www/images/boxart/70018715.jpg
  37. BIN www/images/boxart/70019981.jpg
  38. BIN www/images/boxart/70019994.jpg
  39. BIN www/images/boxart/70020062.jpg
  40. BIN www/images/boxart/70023522.jpg
  41. BIN www/images/boxart/70033005.jpg
  42. BIN www/images/boxart/70038489.jpg
  43. BIN www/images/boxart/70044300.jpg
  44. BIN www/images/boxart/70058399.jpg
  45. BIN www/images/boxart/70058400.jpg
  46. BIN www/images/boxart/70059201.jpg
  47. BIN www/images/boxart/70077176.jpg
  48. BIN www/images/boxart/70079918.jpg
  49. BIN www/images/boxart/70108140.jpg
  50. BIN www/images/boxart/70112727.jpg
  51. BIN www/images/boxart/70112730.jpg
  52. BIN www/images/boxart/70113005.jpg
  53. BIN www/images/boxart/70117293.jpg
  54. BIN www/images/boxart/70117370.jpg
  55. BIN www/images/boxart/806456.jpg
  56. +158 −0 www/index.html
  57. +40 −0 www/js/lib/netflix/index.js
  58. +112 −0 www/js/lib/netflix/ui.js
  59. +131 −0 www/js/lib/netflix/util.js
  60. +1,427 −0 www/js/lib/vendor/zepto.js
0 README
No changes.
@@ -0,0 +1,13 @@
+var nodeflix = require('./nodeflix');
+
+var n = new nodeflix({
+ consumer_key: '',
+ consumer_secret: '',
+ oauth_token: '',
+ oauth_token_secret: '',
+ user_id: ''
+});
+
+n.get('/users/:user_id', function(doc) {
+ console.log(this.document);
+});
@@ -0,0 +1,12 @@
+var NodeFlix = require('nodeflix');
+
+var Netflix = new NodeFlix({
+ consumer_key: '',
+ consumer_secret: '',
+ access_token: '',
+ access_token_secret: ''
+});
+
+NetFlix.get('catalog/titles', { term: 'Star Trek: Voyager' }).end(function(data) {
+ console.log(data);
+});
@@ -0,0 +1,60 @@
+var util = require('util'),
+ EventEmitter = require('events').EventEmitter,
+ Request = require('./lib/Request'),
+ Auth = require('./lib/OAuth').Auth,
+ OAuthRequest = require('./lib/OAuth').Request;
+
+var NodeFlix = function(config, endPoints) {
+ this.config = config;
+ this.endPoints = {
+ host: 'api.netflix.com',
+ oauth_request_url: 'http://api.netflix.com/oauth/request_token',
+ oauth_access_url: 'http://api.netflix.com/oauth/access_token'
+ };
+
+ copyTo(endPoints, this.endPoints);
+
+ this.auth = new Auth(this.config);
+};
+
+var copyTo = function(source, dest) {
+ for (var prop in source) {
+ dest[prop] = source[prop];
+ }
+};
+
+NodeFlix.prototype = {
+ get: function(path, params, callback) {
+ return this.request('GET', path, params, callback);
+ },
+ post: function(path, params, callback) {
+ return this.request('POST', path, params, callback);
+ },
+ put: function(path, params, callback) {
+ return this.request('PUT', path, params, callback);
+ },
+ delete: function(path, params, callback) {
+ return this.request('DELETE', path, params, callback);
+ },
+
+ request: function(method, path, params, callback) {
+ if(typeof(params) === 'function') {
+ callback = params;
+ params = {};
+ }
+
+ for(var prop in this.config) {
+ path = path.replace(':' + prop, this.config[prop], 'g');
+ }
+
+ var req = new OAuthRequest(this.auth, method, this.endPoints.host, path, params);
+
+ if(typeof(callback) === 'function') {
+ return req.end(callback);
+ } else {
+ return req;
+ }
+ }
+};
+
+module.exports = NodeFlix;
@@ -0,0 +1,211 @@
+var util = require('util'),
+ http = require('http'),
+ querystring = require('querystring'),
+ EventEmitter = require('events').EventEmitter,
+ sha1 = require('./sha1'),
+ Response = require('./Response');
+
+var Auth = function(config) {
+ this.config = {
+ consumer_key: null,
+ consumer_secret: null,
+ oauth_token: null,
+ oauth_token_secret: null,
+ signatureMethod: 'HMAC-SHA1',
+ protocol: 'http'
+ };
+
+ for(var prop in config) {
+ this.config[prop] = config[prop];
+ }
+
+ this.parts = [];
+};
+
+Auth.prototype.getPath = function(p) {
+ var signedParts = this.getSignedParts(p.method, this.config.protocol + '://' + p.host + p.endpoint, this.config.consumer_key, this.config.consumer_secret, p.params, this.config.signatureMethod, this.config.oauth_token, this.config.oauth_token_secret);
+ return p.endpoint + '?' + signedParts.body.join('&') + '&oauth_signature=' + this.escape(signedParts.signature);
+};
+
+Auth.prototype.getURL = function(p) {
+ return this.getSignedURL(p.method, this.config.protocol + '://' + p.endpoint, this.config.consumer_key, this.config.consumer_secret, p.params, this.config.signatureMethod, this.config.oauth_token, this.config.oauth_token_secret);
+};
+
+Auth.prototype.getHeaders = function(p) {
+ return this.getSignedHeader(p.method, this.config.protocol + '://' + p.endpoint, this.config.consumer_key, this.config.consumer_secret, p.params, this.config.signatureMethod, this.config.oauth_token, this.config.oauth_token_secret);
+};
+
+Auth.prototype.getSignedURL = function(method, endpoint, consumer_key, consumer_secret, params, signatureMethod, oauth_token, oauth_token_secret) {
+ var signedParts = this.getSignedParts.apply(this, arguments);
+ return endpoint + '?' + signedParts.body.join('&') + '&oauth_signature=' + this.escape(signedParts.signature);
+};
+
+Auth.prototype.getSignedHeaders = function(method, endpoint, consumer_key, consumer_secret, params, signatureMethod, oauth_token, oauth_token_secret) {
+ var signedParts = this.signedParts.apply(this, arguments);
+ this.authParts.push(['oauth_signature', signedParts.signature]);
+
+ return this.authParts.sort(this.sort);
+};
+
+Auth.prototype.getSignedParts = function(method, endpoint, consumer_key, consumer_secret, params, signatureMethod, oauth_token, oauth_token_secret) {
+ this.parts = [];
+ this.authParts = [
+ ['oauth_consumer_key', this.escape(consumer_key)],
+ ['oauth_nonce', this.escape(this.getNonce())],
+ ['oauth_signature_method', this.escape(signatureMethod.toUpperCase())],
+ ['oauth_timestamp', this.escape(this.getTimestamp())],
+ ['oauth_version', this.escape('1.0')]
+ ];
+ if(oauth_token) this.authParts.push(['oauth_token', this.escape(oauth_token)]);
+ this.parts = this.parts.concat(this.authParts);
+
+ for(var prop in params) {
+ this.parts.push([this.escape(prop), this.escape(params[prop])]);
+ }
+
+ this.parts.sort(this.sort);
+
+ var body = this.createBody();
+ var head = this.createHead(method, endpoint);
+
+ return {
+ body: body,
+ signature: this.createSignature(signatureMethod, head, body, consumer_secret, oauth_token_secret)
+ };
+};
+
+Auth.prototype.createSignature = function(signatureMethod, head, body, consumer_secret, oauth_token_secret) {
+ var base = head.join('&') + '&' + this.escape(body.join('&'));
+ if(signatureMethod.toUpperCase() == 'HMAC-SHA1') {
+ if(oauth_token_secret) return (sha1.HMACSHA1(consumer_secret + '&' + oauth_token_secret, base));
+ return sha1.HMACSHA1(consumer_secret + '&', base);
+ } else if(signatureMethod.toUpperCase() == 'PLAINTEXT') {
+ if(oauth_token_secret) return (consumer_secret + '&' + oauth_token_secret);
+ return (consumer_secret + '&');
+ }
+};
+
+Auth.prototype.createBody = function() {
+ var parts = [];
+ for(var i = 0, l = this.parts.length; i < l; i++) {
+ parts.push(this.parts[i][0] + '=' + this.parts[i][1]);
+ }
+
+ return parts;
+};
+
+Auth.prototype.createHead = function(method, endpoint) {
+ return [method.toUpperCase(), this.escape(endpoint)];
+};
+
+// http://oauth.net/core/1.0/ Section 9.1.1:
+// "Parameters are sorted by name, using lexicographical byte value ordering. If two or more parameters share the same name, they are sorted by their value."
+Auth.prototype.sort = function(a,b) {
+ if(a[0] < b[0]) return -1;
+ if(a[0] > b[0]) return 1;
+ if(a[0] == b[0]) {
+ if(a[1] < b[1]) return -1;
+ if(a[1] > b[1]) return 1;
+ }
+};
+
+Auth.prototype.getTimestamp = function() {
+ return Math.floor(new Date().getTime()/1000);
+};
+
+Auth.prototype.getNonce = function(size) {
+ var size = size || 14,
+ nonce = '';
+
+ for(var i = 0; i < size; i++) {
+ nonce += String.fromCharCode(Math.floor(Math.random() * 10) + 48);
+ }
+
+ return nonce;
+};
+
+Auth.prototype.escape = function(str) {
+ var str = str + '';
+ return encodeURIComponent(str)
+ .replace("!","%21","g")
+ .replace("*","%2A","g")
+ .replace("'","%27","g")
+ .replace("(","%28","g")
+ .replace(")","%29","g")
+ .replace("@","%40","g")
+ .replace(",","%2C","g")
+ .replace(":","%3A","g")
+ .replace("/","%2F","g");
+};
+
+var Request = function(auth, method, host, path, params) {
+ this.auth = auth;
+ this.method = method;
+ this.host = host;
+ this.path = path;
+ this.params = params;
+
+
+ EventEmitter.call(this);
+}
+
+util.inherits(Request, EventEmitter);
+
+Request.prototype.end = function(callback) {
+ this.request = this.performRequest(callback);
+ this.request.end();
+
+ return this;
+};
+
+Request.prototype.performRequest = function(callback) {
+ var action = this.method.toLowerCase();
+
+ switch(action) {
+ case 'get':
+ return http.request({
+ host: this.host,
+ port: this.auth.config.protocol == 'http' ? 80 : 443,
+ path: this.auth.getPath({
+ method: this.method,
+ host: this.host,
+ endpoint: this.path,
+ params: this.params
+ }),
+ method: this.method.toUpperCase()
+ }, this.processResponse(callback)
+ );
+ break;
+
+ case 'post':
+ return this.auth.oAuth.getProtectedResource(
+ this.host + this.path,
+ this.method,
+ this.auth.config.access_token,
+ this.auth.config.access_token_secret,
+ this.processResponse(callback)
+ );
+ break;
+
+ default:
+ throw new Error('Method: ' + this.method + ' not supported');
+ }
+};
+
+Request.prototype.processResponse = function(callback) {
+ var self = this;
+
+ return function(response) {
+ response.setEncoding('utf8');
+ var data = '';
+ response.on('data', function(part) {
+ data += part;
+ });
+ response.on('end', function() {
+ var respObj = new Response(data, { response: response, request: self });
+ callback.call(respObj);
+ });
+ };
+};
+
+module.exports = { Request: Request, Auth: Auth };
@@ -0,0 +1,68 @@
+var util = require('util'),
+ http = require('http'),
+ EventEmitter = require('events').EventEmitter,
+ querystring = require('querystring'),
+ Response = require('./Response');
+
+var Request = function(auth, method, host, path, params) {
+ this.auth = auth;
+ this.method = method;
+ this.host = host;
+ this.params = params || {};
+ console.dir(params);
+ this.params.oauth_consumer_key = this.auth.config.consumer_key;
+ this.path = path + '?' + querystring.stringify(this.params);
+ console.dir(this.params);
+ EventEmitter.call(this);
+};
+
+util.inherits(Request, EventEmitter);
+
+Request.prototype.end = function(callback) {
+ this.request = this.performRequest(callback);
+
+ return this;
+};
+
+Request.prototype.performRequest = function(callback) {
+ var action = this.method.toLowerCase();
+
+ switch(action) {
+ case 'get':
+ console.log('make request', this.host, this.path);
+ var req = http.get({
+ host: this.host,
+ port: 80,
+ path: this.path,
+ method: 'GET'
+ }, this.processResponse(callback));
+ req.end();
+
+ return req;
+ break;
+
+ default:
+ throw new Error('Method: ' + this.method + ' not supported');
+ }
+};
+
+Request.prototype.processResponse = function(callback) {
+ var self = this;
+
+ return function(response) {
+ var respData = '';
+ response.on('data', function(part) {
+ console.log('got data', part);
+ });
+
+ var error = null;
+ response.on('error', function(e) {
+ error = e;
+ });
+ response.on('end', function() {
+ callback.call(self, new Response(respData, { response: response, error: error, status: response.statusCode, headers: response.headers }));
+ });
+ };
+};
+
+module.exports = Request;
@@ -0,0 +1,15 @@
+var crack = require('crack');
+var libxmljs = require('libxmljs');
+
+var Response = function(data, meta) {
+ this.meta = meta;
+ this.data = data;
+
+ this.document = libxmljs.parseXmlString(this.data);
+};
+
+Response.prototype.find = function(element, callback) {
+ this.document.find(element, callback);
+};
+
+module.exports = Response;
Oops, something went wrong.

0 comments on commit 1f9c92d

Please sign in to comment.