-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} |