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
1 parent
3a74235
commit c63404b
Showing
5 changed files
with
127 additions
and
2 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 @@ | ||
Helper (simple wrapper) for 500px API. |
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,66 @@ | ||
var util = require('util') | ||
, EventEmitter = require('events').EventEmitter | ||
|
||
// third-party modules | ||
, OAuth = require('oauth').OAuth | ||
|
||
// globals | ||
, basePoint = 'https://api.500px.com/v1/' | ||
, endPoints = | ||
{ | ||
user : basePoint + 'users', | ||
photos : basePoint + 'photos', | ||
upload : basePoint + 'upload' | ||
} | ||
, config = | ||
{ | ||
request : basePoint + 'oauth/request_token', | ||
access : basePoint + 'oauth/access_token', | ||
version : '1.0A', | ||
signature : 'HMAC-SHA1', | ||
separator : ', ', | ||
|
||
key : '', | ||
secret : '', | ||
callback : '' | ||
} | ||
; | ||
|
||
module.exports = api_500px; | ||
util.inherits(api_500px, EventEmitter); | ||
|
||
function api_500px(options) | ||
{ | ||
// house keeping | ||
if (!(this instanceof api_500px)) throw new Error('usage: var apiInstance = new api_500px(config);'); | ||
EventEmitter.call(this); | ||
|
||
options = options || {}; | ||
|
||
this.OA = new OAuth | ||
( | ||
options.request || config.request, | ||
options.access || config.access, | ||
options.key || config.key, | ||
options.secret || config.secret, | ||
options.version || config.version, | ||
options.callback || config.callback, | ||
options.signature || config.signature | ||
); | ||
|
||
// change header separator to make it work with 500px | ||
this.OA._oauthParameterSeperator = options.separator || config.separator; | ||
|
||
return this; | ||
}; | ||
|
||
// Sends auth request to the api service, | ||
// upon receiving verification token | ||
// creates verification handler | ||
api_500px.prototype.authRequest = function api500pxAuthRequest(callback) | ||
{ | ||
// request token | ||
return this.OA.getOAuthRequestToken(callback); | ||
} | ||
|
||
|
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
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,2 @@ | ||
#!/usr/bin/env node | ||
require('urun')(__dirname); |
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,46 @@ | ||
var assert = require('assert') | ||
, test = require('utest') | ||
|
||
// package thingy | ||
, Api500px = require('../../index') | ||
, api // instance | ||
, emptyFunction = function(){} | ||
; | ||
|
||
test('api_500px', | ||
{ | ||
before: function() | ||
{ | ||
api = new Api500px( | ||
{ | ||
key: 'api_500px_test_key_token', | ||
secret: 'api_500px_test_secret_token', | ||
callback: 'http://api_500px_test_callback_url', | ||
}); | ||
}, | ||
|
||
'check api instance': function() | ||
{ | ||
|
||
assert.equal(api.OA._requestUrl, 'https://api.500px.com/v1/oauth/request_token'); | ||
assert.equal(api.OA._accessUrl, 'https://api.500px.com/v1/oauth/access_token'); | ||
assert.equal(api.OA._consumerKey, 'api_500px_test_key_token'); | ||
assert.equal(api.OA._consumerSecret, 'api_500px_test_secret_token'); | ||
assert.equal(api.OA._version, '1.0A'); | ||
assert.equal(api.OA._authorize_callback, 'http://api_500px_test_callback_url'); | ||
assert.equal(api.OA._signatureMethod, 'HMAC-SHA1'); | ||
assert.equal(api.OA._oauthParameterSeperator, ', '); | ||
}, | ||
|
||
'request auth token': function() | ||
{ | ||
// override OAuth | ||
api.OA.getOAuthRequestToken = function(callback) | ||
{ | ||
assert.ok(typeof callback == 'function'); | ||
}; | ||
|
||
api.authRequest(emptyFunction); | ||
} | ||
|
||
}); |