Skip to content
Browse files

[fixes #4] params set when empty; updates testing for express 3.0

  • Loading branch information...
1 parent 85da210 commit f45a6db7ab0716016a57c99475ed22e2d85b4476 @mckelvey committed Aug 21, 2012
View
4 .gitignore
@@ -16,3 +16,7 @@ Thumbs.db
# Testing Environment #
#######################
*.sh
+
+# NPM #
+#######
+node_modules
View
5 HISTORY.md
@@ -1,4 +1,9 @@
+0.1.0 / 2012-08-20
+==================
+
+ * Fixed Issue #4 -- thanks to @joemccann for the suggestion/code
+
0.0.7 / 2011-06-23
==================
View
3 README.md
@@ -493,8 +493,9 @@ I've used [CoffeeScript](http://jashkenas.github.com/coffee-script) to write thi
* [Andrew Senter](https://github.com/andrewsenter)
* [Olivier Balais](https://github.com/bobey)
+ * [Joe McCann](https://github.com/joemccann)
-Both Andrew and Olivier suggested better ways of handling the server response when requesting a token during OAuth.
+Both Andrew and Olivier suggested better ways of handling the server response when requesting a token during OAuth. Joe provided a correction for [issue #4](https://github.com/mckelvey/instagram-node-lib/issues/4).
### Tests
View
4 TODO.md
@@ -1,4 +0,0 @@
-
-## Todo
-
-Visit [PivotalTracker](https://www.pivotaltracker.com/projects/273809) for detail.
View
2 lib/class.instagram.coffee
@@ -92,7 +92,7 @@ class InstagramAPI
Shared Request Methods
###
- _credentials: (params, require = null) ->
+ _credentials: (params = {}, require = null) ->
if require? and params[require]? or params['access_token']? or params['client_id']?
return params
if require isnt null and @_config[require]?
View
3 lib/class.instagram.geographies.js
@@ -1,8 +1,10 @@
+// Generated by CoffeeScript 1.3.3
/*
Geographies
*/
+
(function() {
var InstagramGeographies;
@@ -22,6 +24,7 @@ Geographies
Subscriptions
*/
+
InstagramGeographies.prototype.subscribe = function(params) {
params['object'] = 'geography';
return this.parent.subscriptions._subscribe(params);
View
64 lib/class.instagram.js
@@ -1,3 +1,4 @@
+// Generated by CoffeeScript 1.3.3
(function() {
var APIClient, InstagramAPI, querystring;
@@ -41,10 +42,15 @@
Generic Response Methods
*/
+
InstagramAPI.prototype._error = function(e, value, caller) {
var message;
- if (value === void 0) value = '[undefined]';
- if (value === null) value = '[null]';
+ if (value === void 0) {
+ value = '[undefined]';
+ }
+ if (value === null) {
+ value = '[null]';
+ }
message = "" + e + " occurred: " + value + " in " + caller;
console.log(message);
return message;
@@ -55,18 +61,23 @@
for (i in data) {
console.log(data[i]);
}
- if (pagination != null) return console.log(pagination);
+ if (pagination != null) {
+ return console.log(pagination);
+ }
};
/*
Shared Data Manipulation Methods
*/
+
InstagramAPI.prototype._to_querystring = function(params) {
var i, obj;
obj = {};
for (i in params) {
- if (i !== 'complete' && i !== 'error') obj[i] = params[i];
+ if (i !== 'complete' && i !== 'error') {
+ obj[i] = params[i];
+ }
}
return querystring.stringify(obj);
};
@@ -80,14 +91,20 @@
};
InstagramAPI.prototype._to_value = function(key, value) {
- if (typeof value !== 'object') return value;
- if (value[key] != null) return value[key];
+ if (typeof value !== 'object') {
+ return value;
+ }
+ if (value[key] != null) {
+ return value[key];
+ }
return null;
};
InstagramAPI.prototype._to_object = function(key, value) {
var obj;
- if (typeof value === 'object' && (value[key] != null)) return value;
+ if (typeof value === 'object' && (value[key] != null)) {
+ return value;
+ }
obj = {};
return obj[key] = value;
};
@@ -105,6 +122,7 @@
Set Methods
*/
+
InstagramAPI.prototype._set_maxSockets = function(value) {
if (parseInt(value) === value && value > 0) {
this._http_client.Agent.defaultMaxSockets = value;
@@ -113,8 +131,12 @@
};
InstagramAPI.prototype.set = function(property, value) {
- if (this._config[property] !== void 0) this._config[property] = value;
- if (this._options[property] !== void 0) this._options[property] = value;
+ if (this._config[property] !== void 0) {
+ this._config[property] = value;
+ }
+ if (this._options[property] !== void 0) {
+ this._options[property] = value;
+ }
if (typeof this["_set_" + property] === 'function') {
return this["_set_" + property](value);
}
@@ -124,8 +146,14 @@
Shared Request Methods
*/
+
InstagramAPI.prototype._credentials = function(params, require) {
- if (require == null) require = null;
+ if (params == null) {
+ params = {};
+ }
+ if (require == null) {
+ require = null;
+ }
if ((require != null) && (params[require] != null) || (params['access_token'] != null) || (params['client_id'] != null)) {
return params;
}
@@ -140,14 +168,18 @@
};
InstagramAPI.prototype._request = function(params) {
- var appResponse, complete, error, http_client, options, post_data, request, _ref, _ref2;
+ var appResponse, complete, error, http_client, options, post_data, request, _ref, _ref1;
options = this._clone(this._options);
- if (params['method'] != null) options['method'] = params['method'];
- if (params['path'] != null) options['path'] = params['path'];
+ if (params['method'] != null) {
+ options['method'] = params['method'];
+ }
+ if (params['path'] != null) {
+ options['path'] = params['path'];
+ }
options['path'] = process.env['TEST_PATH_PREFIX'] != null ? "" + process.env['TEST_PATH_PREFIX'] + options['path'] : options['path'];
complete = (_ref = params['complete']) != null ? _ref : params['complete'] = this._complete;
appResponse = params['response'];
- error = (_ref2 = params['error']) != null ? _ref2 : params['error'] = this._error;
+ error = (_ref1 = params['error']) != null ? _ref1 : params['error'] = this._error;
if (options['method'] !== "GET" && (params['post_data'] != null)) {
post_data = this._to_querystring(params['post_data']);
} else {
@@ -187,7 +219,9 @@
}
});
});
- if (post_data != null) request.write(post_data);
+ if (post_data != null) {
+ request.write(post_data);
+ }
request.addListener('error', function(connectionException) {
if (connectionException.code !== 'ENOTCONN') {
if (appResponse != null) {
View
1 lib/class.instagram.locations.js
@@ -1,3 +1,4 @@
+// Generated by CoffeeScript 1.3.3
(function() {
var InstagramLocations;
View
5 lib/class.instagram.media.js
@@ -1,3 +1,4 @@
+// Generated by CoffeeScript 1.3.3
(function() {
var InstagramMedia;
@@ -11,6 +12,7 @@
Basic Media
*/
+
InstagramMedia.prototype.popular = function(params) {
var credentials;
credentials = this.parent._credentials({});
@@ -35,6 +37,7 @@
Likes
*/
+
InstagramMedia.prototype.likes = function(params) {
var credentials;
credentials = this.parent._credentials({});
@@ -60,6 +63,7 @@
Comments
*/
+
InstagramMedia.prototype.comments = function(params) {
var credentials;
credentials = this.parent._credentials({});
@@ -88,6 +92,7 @@
Subscriptions
*/
+
InstagramMedia.prototype.subscribe = function(params) {
params['object'] = 'geography';
return this.parent.subscriptions._subscribe(params);
View
1 lib/class.instagram.oauth.js
@@ -1,3 +1,4 @@
+// Generated by CoffeeScript 1.3.3
(function() {
var InstagramOAuth;
View
8 lib/class.instagram.subscriptions.js
@@ -1,3 +1,4 @@
+// Generated by CoffeeScript 1.3.3
(function() {
var InstagramSubscriptions, crypto, url;
@@ -15,6 +16,7 @@
Verification Methods
*/
+
InstagramSubscriptions.prototype.handshake = function(request, response, complete) {
var body, headers, parsedRequest;
parsedRequest = url.parse(request.url, true);
@@ -53,6 +55,7 @@
Shared Subscription Methods
*/
+
InstagramSubscriptions.prototype._subscribe = function(params) {
var i, _i, _len, _ref;
params['method'] = "POST";
@@ -70,7 +73,9 @@
_ref = ['object_id', 'verify_token', 'lat', 'lng', 'radius'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
i = _ref[_i];
- if (params[i] != null) params['post_data'][i] = params[i];
+ if (params[i] != null) {
+ params['post_data'][i] = params[i];
+ }
}
return this.parent._request(params);
};
@@ -91,6 +96,7 @@
Shared Public Methods
*/
+
InstagramSubscriptions.prototype.subscribe = function(params) {
return this._subscribe(params);
};
View
1 lib/class.instagram.tags.js
@@ -1,3 +1,4 @@
+// Generated by CoffeeScript 1.3.3
(function() {
var InstagramTags;
View
5 lib/class.instagram.users.js
@@ -1,3 +1,4 @@
+// Generated by CoffeeScript 1.3.3
(function() {
var InstagramUsers;
@@ -11,6 +12,7 @@
User Basics
*/
+
InstagramUsers.prototype.info = function(params) {
var credentials;
credentials = this.parent._credentials({});
@@ -28,6 +30,7 @@
Media
*/
+
InstagramUsers.prototype.self = function(params) {
params = this.parent._credentials(params, 'access_token');
params['path'] = "/" + this.parent._api_version + "/users/self/feed?" + (this.parent._to_querystring(params));
@@ -50,6 +53,7 @@
Relationships
*/
+
InstagramUsers.prototype.follows = function(params) {
var credentials;
credentials = this.parent._credentials({}, 'access_token');
@@ -121,6 +125,7 @@
Subscriptions
*/
+
InstagramUsers.prototype.subscribe = function(params) {
params['object'] = 'user';
return this.parent.subscriptions._subscribe(params);
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "instagram-node-lib",
"description": "This package is a wrapper for the Instagram API.",
- "version": "0.0.9",
+ "version": "0.1.0",
"author": "David W. McKelvey <david@mckelveycreative.com> (http://david.mckelveycreative.com/)",
"contributors": [],
"keywords": [
View
4 test/helpers.js
@@ -1,6 +1,9 @@
+// Generated by CoffeeScript 1.3.3
(function() {
var indent;
+
indent = " ";
+
module.exports = {
indent: indent,
helper: function(title, Instagram, type, method, params, assertions) {
@@ -40,4 +43,5 @@
}
}
};
+
}).call(this);
View
2 test/initialize.coffee
@@ -19,7 +19,7 @@ if callback?
PATH = callback['pathname']
express = require 'express'
-app = express.createServer()
+app = express()
app.configure ->
app.set 'host', HOST
View
40 test/initialize.js
@@ -1,25 +1,41 @@
+// Generated by CoffeeScript 1.3.3
+
+/*
+Initialize Instagram
+*/
+
+
(function() {
- /*
- Initialize Instagram
- */ var CALLBACK_URL, HOST, Instagram, PATH, PORT, app, callback, express, url;
+ var CALLBACK_URL, HOST, Instagram, PATH, PORT, app, callback, express, url;
+
Instagram = require('../lib/class.instagram');
+
/*
Setup App for Subscription Callbacks
*/
+
+
url = require('url');
+
CALLBACK_URL = process.env['CALLBACK_URL'] != null ? process.env['CALLBACK_URL'] : "http://your.callback/url";
+
callback = url.parse(CALLBACK_URL);
+
if (callback != null) {
HOST = callback['hostname'];
PORT = typeof callback['port'] !== 'undefined' ? callback['port'] : null;
PATH = callback['pathname'];
}
+
express = require('express');
- app = express.createServer();
+
+ app = express();
+
app.configure(function() {
app.set('host', HOST);
return app.use(app.router);
});
+
app.configure('development', function() {
app.set('port', PORT);
app.use(express.logger());
@@ -28,9 +44,11 @@
showStack: true
}));
});
+
app.get(PATH, function(request, response) {
return Instagram.subscriptions.handshake(request, response);
});
+
app.get('/fake/oauth/authorize', function(request, response) {
var params;
params = url.parse(request.url, true).query;
@@ -39,6 +57,7 @@
});
return response.end();
});
+
app.post('/fake/oauth/access_token', function(request, response) {
var data, fake_response, querystring, should, util;
querystring = require('querystring');
@@ -74,6 +93,7 @@
return response.end(JSON.stringify(fake_response));
});
});
+
app.get('/oauth', function(request, response) {
Instagram.oauth.ask_for_access_token({
request: request,
@@ -96,13 +116,20 @@
});
return null;
});
+
app.listen(PORT);
+
/*
Add-on App Test Monitoring
*/
+
+
app._tests_to_do = 0;
+
app._tests_completed = 0;
+
app._max_execution_time = 10;
+
app.start_tests = function(tests) {
var i, iterations, monitor;
for (i in tests) {
@@ -111,16 +138,21 @@
iterations = 0;
return monitor = setInterval(function(){if(app.fd==null){clearInterval(monitor);}else if((app._tests_completed==app._tests_to_do&&app._tests_completed!=0)||iterations>app._max_execution_time){clearInterval(monitor);app.close();}else{iterations+=1;}}, 1000);
};
+
app.finish_test = function() {
return app._tests_completed += 1;
};
+
/*
Exports
*/
+
+
module.exports = {
host: HOST,
port: PORT,
app: app,
Instagram: Instagram
};
+
}).call(this);
View
25 test/instagram.geographies.js
@@ -1,19 +1,36 @@
+// Generated by CoffeeScript 1.3.3
+
+/*
+Test Setup
+*/
+
+
(function() {
- /*
- Test Setup
- */ var Init, Instagram, app, assert, completed, should, test, to_do;
+ var Init, Instagram, app, assert, completed, should, test, to_do;
+
console.log("\nInstagram API Node.js Lib Tests :: Geographies");
+
Init = require('./initialize');
+
Instagram = Init.Instagram;
+
app = Init.app;
+
assert = require('assert');
+
should = require('should');
+
test = require('./helpers');
+
completed = 0;
+
to_do = 0;
+
/*
Tests
*/
+
+
module.exports = {
'geographies#subscriptions': function() {
return test.helper("geographies#subscriptions subscribe to geography near Eiffel Tower", Instagram, 'geographies', 'subscribe', {
@@ -56,5 +73,7 @@
});
}
};
+
app.start_tests(module.exports);
+
}).call(this);
View
25 test/instagram.js
@@ -1,19 +1,36 @@
+// Generated by CoffeeScript 1.3.3
+
+/*
+Test Setup
+*/
+
+
(function() {
- /*
- Test Setup
- */ var Init, Instagram, app, assert, completed, should, test, to_do;
+ var Init, Instagram, app, assert, completed, should, test, to_do;
+
console.log("\nInstagram API Node.js Lib Tests :: Basic");
+
Init = require('./initialize');
+
Instagram = Init.Instagram;
+
app = Init.app;
+
assert = require('assert');
+
should = require('should');
+
test = require('./helpers');
+
completed = 0;
+
to_do = 0;
+
/*
Tests
*/
+
+
module.exports = {
'instagram#set': function() {
console.log("\ninstagram#set");
@@ -32,5 +49,7 @@
return app.finish_test();
}
};
+
app.start_tests(module.exports);
+
}).call(this);
View
27 test/instagram.locations.js
@@ -1,19 +1,36 @@
+// Generated by CoffeeScript 1.3.3
+
+/*
+Test Setup
+*/
+
+
(function() {
- /*
- Test Setup
- */ var Init, Instagram, app, assert, completed, should, test, to_do;
+ var Init, Instagram, app, assert, completed, should, test, to_do;
+
console.log("\nInstagram API Node.js Lib Tests :: Locations");
+
Init = require('./initialize');
+
Instagram = Init.Instagram;
+
app = Init.app;
+
assert = require('assert');
+
should = require('should');
+
test = require('./helpers');
+
completed = 0;
+
to_do = 0;
+
/*
Tests
*/
+
+
module.exports = {
'locations#info for id#1': function() {
return test.helper('locations#info for id#1', Instagram, 'locations', 'info', {
@@ -108,6 +125,7 @@
});
}
};
+
/*
count seems to return n-1 results; e.g. request 50 returns 49, request 30 returns 29,...
@@ -117,5 +135,8 @@
test.output "data had length of 49"
app.finish_test()
*/
+
+
app.start_tests(module.exports);
+
}).call(this);
View
27 test/instagram.media.js
@@ -1,19 +1,36 @@
+// Generated by CoffeeScript 1.3.3
+
+/*
+Test Setup
+*/
+
+
(function() {
- /*
- Test Setup
- */ var Init, Instagram, app, assert, completed, should, test, to_do;
+ var Init, Instagram, app, assert, completed, should, test, to_do;
+
console.log("\nInstagram API Node.js Lib Tests :: Media");
+
Init = require('./initialize');
+
Instagram = Init.Instagram;
+
app = Init.app;
+
assert = require('assert');
+
should = require('should');
+
test = require('./helpers');
+
completed = 0;
+
to_do = 0;
+
/*
Tests
*/
+
+
module.exports = {
'media#popular': function() {
return test.helper('media#popular', Instagram, 'media', 'popular', {}, function(data) {
@@ -147,6 +164,7 @@
});
}
};
+
/*
tested on Austin, Tx. { lat: 30.30, lng: -97.70, distance: 5000 }; weird, request with count 200 produces 54, request with count 50 produces 46, request with count 46 produces 42, request with count 42 produces 38... I think you see the pattern. :)
@@ -156,5 +174,8 @@
test.output "data had length equal to 42", data.length
app.finish_test()
*/
+
+
app.start_tests(module.exports);
+
}).call(this);
View
27 test/instagram.oauth.js
@@ -1,21 +1,40 @@
+// Generated by CoffeeScript 1.3.3
+
+/*
+Test Setup
+*/
+
+
(function() {
- /*
- Test Setup
- */ var Init, Instagram, app, assert, completed, http_client, should, test, to_do, url;
+ var Init, Instagram, app, assert, completed, http_client, should, test, to_do, url;
+
console.log("\nInstagram API Node.js Lib Tests :: OAuth");
+
Init = require('./initialize');
+
Instagram = Init.Instagram;
+
app = Init.app;
+
assert = require('assert');
+
should = require('should');
+
test = require('./helpers');
+
http_client = require('http');
+
url = require('url');
+
completed = 0;
+
to_do = 0;
+
/*
Tests
*/
+
+
module.exports = {
'oauth#roundtrip': function() {
var options, request, result;
@@ -81,5 +100,7 @@
return request.end();
}
};
+
app.start_tests(module.exports);
+
}).call(this);
View
32 test/instagram.subscriptions.js
@@ -1,25 +1,37 @@
+// Generated by CoffeeScript 1.3.3
+
+/*
+Test Setup
+*/
+
+
(function() {
- /*
- Test Setup
- */ var Init, Instagram, app, assert, completed, should, test, to_do;
- var __indexOf = Array.prototype.indexOf || function(item) {
- for (var i = 0, l = this.length; i < l; i++) {
- if (this[i] === item) return i;
- }
- return -1;
- };
+ var Init, Instagram, app, assert, completed, should, test, to_do,
+ __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
+
console.log("\nInstagram API Node.js Lib Tests :: Subscriptions");
+
Init = require('./initialize');
+
Instagram = Init.Instagram;
+
app = Init.app;
+
assert = require('assert');
+
should = require('should');
+
test = require('./helpers');
+
completed = 0;
+
to_do = 0;
+
/*
Tests
*/
+
+
module.exports = {
'multi#subscriptions': function() {
var subscriptions;
@@ -90,5 +102,7 @@
});
}
};
+
app.start_tests(module.exports);
+
}).call(this);
View
27 test/instagram.tags.js
@@ -1,19 +1,36 @@
+// Generated by CoffeeScript 1.3.3
+
+/*
+Test Setup
+*/
+
+
(function() {
- /*
- Test Setup
- */ var Init, Instagram, app, assert, completed, should, test, to_do;
+ var Init, Instagram, app, assert, completed, should, test, to_do;
+
console.log("\nInstagram API Node.js Lib Tests :: Tags");
+
Init = require('./initialize');
+
Instagram = Init.Instagram;
+
app = Init.app;
+
assert = require('assert');
+
should = require('should');
+
test = require('./helpers');
+
completed = 0;
+
to_do = 0;
+
/*
Tests
*/
+
+
module.exports = {
'tags#info for blue': function() {
return test.helper('tags#info for blue', Instagram, 'tags', 'info', {
@@ -105,6 +122,7 @@
});
}
};
+
/*
seems to max out at 49 rather than 100 (ruby api docs) otherwise works perfectly
@@ -114,5 +132,8 @@
test.output "data had length equal to 200", data.length
app.finish_test()
*/
+
+
app.start_tests(module.exports);
+
}).call(this);
View
27 test/instagram.users.js
@@ -1,19 +1,36 @@
+// Generated by CoffeeScript 1.3.3
+
+/*
+Test Setup
+*/
+
+
(function() {
- /*
- Test Setup
- */ var Init, Instagram, app, assert, completed, should, test, to_do;
+ var Init, Instagram, app, assert, completed, should, test, to_do;
+
console.log("\nInstagram API Node.js Lib Tests :: Users");
+
Init = require('./initialize');
+
Instagram = Init.Instagram;
+
app = Init.app;
+
assert = require('assert');
+
should = require('should');
+
test = require('./helpers');
+
completed = 0;
+
to_do = 0;
+
/*
Tests
*/
+
+
module.exports = {
'users#info for id#291024': function() {
return test.helper('users#info for id#291024', Instagram, 'users', 'info', {
@@ -204,6 +221,7 @@
});
}
};
+
/*
for me, returns 9 regardless, requesting with count seems to have no impact � time based only now?
@@ -213,5 +231,8 @@
test.output "data had length equal to 200", data.length
app.finish_test()
*/
+
+
app.start_tests(module.exports);
+
}).call(this);

0 comments on commit f45a6db

Please sign in to comment.
Something went wrong with that request. Please try again.