Permalink
Browse files

testing logging and revamp complete

  • Loading branch information...
mckelvey committed Apr 30, 2011
1 parent 29316b9 commit d97294abea0197acb2cd38d2cd628ef0f4185647
@@ -1,6 +1,6 @@
###
-Geographies Do Not Yet Work
+Geographies
###
class InstagramGeographies
@@ -12,4 +12,19 @@ class InstagramGeographies
params['path'] = "/#{@parent._api_version}/geographies/#{params['geography_id']}/media/recent?#{@parent._to_querystring(params)}"
@parent._request params
+ ###
+ Subscriptions
+ ###
+
+ subscribe: (params) ->
+ params['object'] = 'geography'
+ @parent.subscriptions._subscribe params
+
+ unsubscribe: (params) ->
+ @parent.subscriptions._unsubscribe params
+
+ unsubscribe_all: (params) ->
+ params['object'] = 'geography'
+ @parent.subscriptions._unsubscribe params
+
module.exports = InstagramGeographies
@@ -1,6 +1,6 @@
(function() {
/*
- Geographies Do Not Yet Work
+ Geographies
*/ var InstagramGeographies;
InstagramGeographies = (function() {
function InstagramGeographies(parent) {
@@ -11,6 +11,20 @@
params['path'] = "/" + this.parent._api_version + "/geographies/" + params['geography_id'] + "/media/recent?" + (this.parent._to_querystring(params));
return this.parent._request(params);
};
+ /*
+ Subscriptions
+ */
+ InstagramGeographies.prototype.subscribe = function(params) {
+ params['object'] = 'geography';
+ return this.parent.subscriptions._subscribe(params);
+ };
+ InstagramGeographies.prototype.unsubscribe = function(params) {
+ return this.parent.subscriptions._unsubscribe(params);
+ };
+ InstagramGeographies.prototype.unsubscribe_all = function(params) {
+ params['object'] = 'geography';
+ return this.parent.subscriptions._unsubscribe(params);
+ };
return InstagramGeographies;
})();
module.exports = InstagramGeographies;
View
@@ -0,0 +1,62 @@
+
+###
+Initialize Instagram
+###
+
+Instagram = require '../lib/class.instagram'
+
+###
+Setup App for Subscription Callbacks
+###
+
+url = require 'url'
+CALLBACK_URL = if process.env['CALLBACK_URL']? then process.env['CALLBACK_URL'] else "http://your.callback/url"
+callback = url.parse CALLBACK_URL
+
+if callback?
+ HOST = callback['hostname']
+ PORT = if typeof callback['port'] isnt 'undefined' then callback['port'] else null
+ PATH = callback['pathname']
+
+express = require 'express'
+app = express.createServer()
+
+app.configure ->
+ app.set 'host', HOST
+ app.use app.router
+
+app.configure 'development', ->
+ app.set 'port', PORT
+ app.use express.logger()
+ app.use express.errorHandler { dumpExceptions: true, showStack: true }
+
+app.get PATH,
+ (request, response) ->
+ Instagram.subscriptions.handshake request, response
+
+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 = (tests) ->
+ for i of tests
+ app._tests_to_do += 1
+ iterations = 0
+ 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 = ->
+ app._tests_completed += 1
+
+###
+Exports
+###
+
+module.exports =
+ app: app
+ Instagram: Instagram
View
@@ -0,0 +1,59 @@
+(function() {
+ /*
+ Initialize Instagram
+ */ 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.configure(function() {
+ app.set('host', HOST);
+ return app.use(app.router);
+ });
+ app.configure('development', function() {
+ app.set('port', PORT);
+ app.use(express.logger());
+ return app.use(express.errorHandler({
+ dumpExceptions: true,
+ showStack: true
+ }));
+ });
+ app.get(PATH, function(request, response) {
+ return Instagram.subscriptions.handshake(request, response);
+ });
+ 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) {
+ app._tests_to_do += 1;
+ }
+ 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 = {
+ app: app,
+ Instagram: Instagram
+ };
+}).call(this);
@@ -1,16 +1,46 @@
###
-Testing Geographies Methods
+Test Setup
###
console.log "\nInstagram API Node.js Lib Tests :: Geographies"
-Instagram = require '../lib/class.instagram'
+Init = require './initialize'
+Instagram = Init.Instagram
+app = Init.app
+
assert = require 'assert'
should = require 'should'
-test_helper = require './helpers.js'
+test = require './helpers'
+
+completed = 0
+to_do = 0
+
+###
+Tests
+###
module.exports =
- 'geographies#recent for id#4167': ->
- test_helper 'geographies#recent for id#4167', Instagram, 'geographies', 'recent', { geography_id: 4167 }, (data) ->
- data.should.not.be.empty
+ 'geographies#subscriptions': ->
+ test.helper "geographies#subscriptions subscribe to geography near Eiffel Tower", Instagram, 'geographies', 'subscribe', { lat: 48.858844300000001, lng: 2.2943506, radius: 1000 }, (data) ->
+ data.should.have.property 'id'
+ test.output "data had the property 'id'"
+ data.id.should.be.above 0
+ test.output "data.id was greater than 0", data.id
+ data.should.have.property 'type', 'subscription'
+ test.output "data had the property 'type' equal to 'subscription'", data
+ subscription_id = data.id
+ test.helper 'geographies#subscriptions list', Instagram, 'subscriptions', 'list', {}, (data) ->
+ data.length.should.be.above 0
+ test.output "data had length greater than 0", data.length
+ found = false
+ for i of data
+ found = true if data[i].id is subscription_id
+ throw "subscription not found" if !found
+ test.output "data had the subscription #{subscription_id}"
+ test.helper "geographies#subscriptions unsubscribe from media near Eiffel Tower", Instagram, 'geographies', 'unsubscribe', { id: subscription_id }, (data) ->
+ throw "geography near Eiffel Tower unsubscribe failed" if data isnt null
+ test.output "data was null; we unsubscribed from the subscription #{subscription_id}"
+ app.finish_test()
+
+app.start_tests module.exports
@@ -1,19 +1,60 @@
(function() {
/*
- Testing Geographies Methods
- */ var Instagram, assert, should, test_helper;
+ Test Setup
+ */ var Init, Instagram, app, assert, completed, should, test, to_do;
console.log("\nInstagram API Node.js Lib Tests :: Geographies");
- Instagram = require('../lib/class.instagram');
+ Init = require('./initialize');
+ Instagram = Init.Instagram;
+ app = Init.app;
assert = require('assert');
should = require('should');
- test_helper = require('./helpers.js');
+ test = require('./helpers');
+ completed = 0;
+ to_do = 0;
+ /*
+ Tests
+ */
module.exports = {
- 'geographies#recent for id#4167': function() {
- return test_helper('geographies#recent for id#4167', Instagram, 'geographies', 'recent', {
- geography_id: 4167
+ 'geographies#subscriptions': function() {
+ return test.helper("geographies#subscriptions subscribe to geography near Eiffel Tower", Instagram, 'geographies', 'subscribe', {
+ lat: 48.858844300000001,
+ lng: 2.2943506,
+ radius: 1000
}, function(data) {
- return data.should.not.be.empty;
+ var subscription_id;
+ data.should.have.property('id');
+ test.output("data had the property 'id'");
+ data.id.should.be.above(0);
+ test.output("data.id was greater than 0", data.id);
+ data.should.have.property('type', 'subscription');
+ test.output("data had the property 'type' equal to 'subscription'", data);
+ subscription_id = data.id;
+ return test.helper('geographies#subscriptions list', Instagram, 'subscriptions', 'list', {}, function(data) {
+ var found, i;
+ data.length.should.be.above(0);
+ test.output("data had length greater than 0", data.length);
+ found = false;
+ for (i in data) {
+ if (data[i].id === subscription_id) {
+ found = true;
+ }
+ }
+ if (!found) {
+ throw "subscription not found";
+ }
+ test.output("data had the subscription " + subscription_id);
+ return test.helper("geographies#subscriptions unsubscribe from media near Eiffel Tower", Instagram, 'geographies', 'unsubscribe', {
+ id: subscription_id
+ }, function(data) {
+ if (data !== null) {
+ throw "geography near Eiffel Tower unsubscribe failed";
+ }
+ test.output("data was null; we unsubscribed from the subscription " + subscription_id);
+ return app.finish_test();
+ });
+ });
});
}
};
+ app.start_tests(module.exports);
}).call(this);
@@ -1,14 +1,24 @@
###
-Testing Location Methods
+Test Setup
###
console.log "\nInstagram API Node.js Lib Tests :: Locations"
-Instagram = require '../lib/class.instagram'
+Init = require './initialize'
+Instagram = Init.Instagram
+app = Init.app
+
assert = require 'assert'
should = require 'should'
-test = require './helpers.js'
+test = require './helpers'
+
+completed = 0
+to_do = 0
+
+###
+Tests
+###
module.exports =
'locations#info for id#1': ->
@@ -19,6 +29,7 @@ module.exports =
test.output "data had the property 'latitude' greater than zero", data.latitude
data.longitude.should.be.below 0
test.output "data had the property 'longitude' less than zero", data.longitude
+ app.finish_test()
'locations#recent for id#1': ->
test.helper 'locations#recent for id#1', Instagram, 'locations', 'recent', { location_id: 1 }, (data, pagination) ->
data.length.should.be.above 0
@@ -29,6 +40,7 @@ module.exports =
test.output "pagination had the property 'next_url'", pagination.next_url
pagination.should.have.property 'next_max_id' or pagination.should.have.property 'next_min_id'
test.output "pagination had the property 'next_max_id' or 'next_min_id'", pagination
+ app.finish_test()
'locations#search for 48.858844300000001/2.2943506': ->
test.helper 'locations#search for 48.858844300000001/2.2943506', Instagram, 'locations', 'search', { lat: 48.858844300000001, lng: 2.2943506 }, (data) ->
data.length.should.be.above 0
@@ -37,3 +49,27 @@ module.exports =
test.output "data[0] had the property 'id'", data[0].id
data[0].should.have.property 'name'
test.output "data[0] had the property 'name'", data[0].name
+ app.finish_test()
+ 'locations#subscriptions': ->
+ test.helper "locations#subscriptions subscribe to location '1257285'", Instagram, 'locations', 'subscribe', { object_id: '1257285' }, (data) ->
+ data.should.have.property 'id'
+ test.output "data had the property 'id'"
+ data.id.should.be.above 0
+ test.output "data.id was greater than 0", data.id
+ data.should.have.property 'type', 'subscription'
+ test.output "data had the property 'type' equal to 'subscription'", data
+ subscription_id = data.id
+ test.helper 'locations#subscriptions list', Instagram, 'subscriptions', 'list', {}, (data) ->
+ data.length.should.be.above 0
+ test.output "data had length greater than 0", data.length
+ found = false
+ for i of data
+ found = true if data[i].id is subscription_id
+ throw "subscription not found" if !found
+ test.output "data had the subscription #{subscription_id}"
+ test.helper "locations#subscriptions unsubscribe from location '1257285'", Instagram, 'locations', 'unsubscribe', { id: subscription_id }, (data) ->
+ throw "location '1257285' unsubscribe failed" if data isnt null
+ test.output "data was null; we unsubscribed from the subscription #{subscription_id}"
+ app.finish_test()
+
+app.start_tests module.exports
Oops, something went wrong.

0 comments on commit d97294a

Please sign in to comment.