diff --git a/README.md b/README.md new file mode 100644 index 0000000..ca48adf --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Helper (simple wrapper) for 500px API. diff --git a/index.js b/index.js new file mode 100644 index 0000000..1d126d6 --- /dev/null +++ b/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); +} + + diff --git a/package.json b/package.json index 3a79b81..8e45c3b 100644 --- a/package.json +++ b/package.json @@ -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": [ @@ -13,5 +16,12 @@ "oauth" ], "author": "Alex Indigo ", - "license": "MIT" + "license": "MIT", + "devDependencies": { + "utest": "0.0.6", + "urun": "0.0.6" + }, + "dependencies": { + "oauth": "~0.9.8" + } } diff --git a/test/run.js b/test/run.js new file mode 100644 index 0000000..25afad2 --- /dev/null +++ b/test/run.js @@ -0,0 +1,2 @@ +#!/usr/bin/env node +require('urun')(__dirname); diff --git a/test/unit/test-base.js b/test/unit/test-base.js new file mode 100644 index 0000000..113c494 --- /dev/null +++ b/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); + } + +});