Permalink
Browse files

searching for media works

  • Loading branch information...
1 parent b30f8d4 commit 93783d8892a0d883a46645e9060bd87e950acc6c @Swizec committed Mar 1, 2011
Showing with 39 additions and 1 deletion.
  1. +17 −1 index.js
  2. +22 −0 tests.js
View
@@ -1,6 +1,7 @@
var http = require('http'),
- https = require('https');
+ https = require('https'),
+ querystring = require('querystring');
function InstagramClient(client_id, client_secret) {
@@ -58,6 +59,21 @@ InstagramMediaClient.prototype.popular = function (callback) {
});
}
+InstagramMediaClient.prototype.search = function (parameters, callback) {
+ parameters['client_id'] = this.parent.client_id;
+
+ var options = {
+ path: '/v1/media/search/?'+querystring.stringify(parameters)
+ }
+ this.parent.fetch(options, function (response) {
+ if (response['meta']['code'] == 200) {
+ callback(response['data'], null);
+ }else{
+ callback(response['meta'], response['meta']['code']);
+ }
+ });
+}
+
exports.createClient = function (client_id, client_secret) {
var instagram_client = new InstagramClient(client_id, client_secret);
View
@@ -24,3 +24,25 @@ exports.testMediaFetchPopular = function (test) {
test.done();
});
};
+
+exports.testMediaSearch = function (test) {
+ var params = [{lat: 37.7937111, lng: -122.3926227},
+ {lat: 37.7937111, lng: -122.3926227, distance: 2000}];
+
+ test.expect(params.length*2);
+
+ var do_it = function (i, callback) {
+ instagram.media.search(params[i], function (media, error) {
+ test.ok((media.length > 0));
+ test.equal(error, null, "Return error for "+params);
+
+ if (i < params.length-1) {
+ do_it(i+1, do_it);
+ }else{
+ test.done();
+ }
+ });
+ }
+
+ do_it(0);
+};

0 comments on commit 93783d8

Please sign in to comment.