Skip to content

Commit

Permalink
Added frame + authRequest method.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexindigo committed Aug 26, 2012
1 parent 3a74235 commit c63404b
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
@@ -0,0 +1 @@
Helper (simple wrapper) for 500px API.
66 changes: 66 additions & 0 deletions index.js
@@ -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);
}


14 changes: 12 additions & 2 deletions package.json
Expand Up @@ -4,7 +4,10 @@
"description": "500px API helper",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "node test/run.js"
},
"engines": {
"node": ">= 0.6"
},
"repository": "",
"keywords": [
Expand All @@ -13,5 +16,12 @@
"oauth"
],
"author": "Alex Indigo <iam@alexindigo.com>",
"license": "MIT"
"license": "MIT",
"devDependencies": {
"utest": "0.0.6",
"urun": "0.0.6"
},
"dependencies": {
"oauth": "~0.9.8"
}
}
2 changes: 2 additions & 0 deletions test/run.js
@@ -0,0 +1,2 @@
#!/usr/bin/env node
require('urun')(__dirname);
46 changes: 46 additions & 0 deletions test/unit/test-base.js
@@ -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);
}

});

0 comments on commit c63404b

Please sign in to comment.