Skip to content

Commit

Permalink
fetching media by id works
Browse files Browse the repository at this point in the history
  • Loading branch information
Swizec committed Mar 1, 2011
1 parent 2ac9b48 commit 9e2819f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
42 changes: 42 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

var http = require('http'),
https = require('https');


function InstagramClient() {
this.client_id = '';
this.client_secret = '';
}

InstagramClient.prototype.media = function (id, callback) {
var options = {
host: 'api.instagram.com',
path: '/v1/media/'+id+'?client_id='+this.client_id
};

https.get(options, function (res) {
var raw = "";
res.on('data', function (chunk) {
raw += chunk;
});
res.on('end', function () {
var response = JSON.parse(raw);

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();

instagram_client.client_id = client_id;
instagram_client.client_secret = client_secret;

return instagram_client;
}
15 changes: 15 additions & 0 deletions tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

var instagram = require('./index.js').createClient('a8d764b1a7fe4089959910ee6bdcedce',
'253a2b9abade4f25adb3825249d98b85');


exports.testMediaFetchById = function (test) {
test.expect(2);

instagram.media(100, function (media, error) {
test.ok(media['type']);
test.equal(error, null, "Returned an error");

test.done();
});
}

0 comments on commit 9e2819f

Please sign in to comment.