Published npm module #11

Closed
wants to merge 2 commits into
from
View
@@ -0,0 +1,3 @@
+[submodule "node"]
+ path = node
+ url = git://github.com/creatorrr/node-rdio.git
1 node
Submodule node added at 004b75
View
@@ -1,46 +0,0 @@
-rdio-simple for JavaScript (node.js)
-====================================
-
-An Rdio client including a built-in OAuth implementation.
-
-It has been tested on the 0.4 branch of node.
-
-To install the library simply add the `om.js` and `rdio.js` files
-to your source directory.
-
-Usage
------
-
-To use the library just load the Rdio class from the rdio module:
-```javascript
-var Rdio = require("rdio");
-```
-Create an Rdio instance passing in a tuple with your consumer key and secret:
-```javascript
-var rdio = new Rdio(["consumerkey", "consumersecret"]);
-```
-Make API calls with the call(methodname, params) method:
-```javascript
-rdio.call('get', {'keys': 'a254895,a104386'});
-```
-Authenticate and authorize with the `beginAuthentication` and
-`completeAuthentication` methods.
-
-The current token (either request or access) is stored in `rdio.token` as an
-array with the token and token secret.
-
-Examples
---------
-
-Both examples authenticate and then list the user's playlists. They use
-credentials stored in `rdio_consumer_credentials.js`.
-
-* [examples/command-line.js](https://github.com/rdio/rdio-simple/blob/master/node/examples/command-line.js)
-* [examples/web-based.js](https://github.com/rdio/rdio-simple/blob/master/node/examples/web-based.js)
-
-**NOTE:** `web-based.js` depends on [Link](http://linkjs.org/). Install the dependency
-in the examples directory by running:
-
-```bash
-npm install link
-```
@@ -1,54 +0,0 @@
-var rl = require("readline"),
- Rdio = require("./../rdio"),
- cred = require("./rdio_consumer_credentials");
-
-var i = rl.createInterface(process.stdin, process.stdout, null);
-
-function done() {
- i.close();
- process.stdin.destroy();
-}
-
-// Create an Rdio object with consumer's credentials.
-var rdio = new Rdio([cred.RDIO_CONSUMER_KEY, cred.RDIO_CONSUMER_SECRET]);
-
-// Authenticate against the Rdio service.
-rdio.beginAuthentication("oob", function (err, authUrl) {
- if (err) {
- console.log("ERROR: " + err);
- done();
- return;
- }
-
- console.log("Go to: " + authUrl);
-
- // Prompt the user for the verifier code.
- i.question("Then enter the code: ", function (verifier) {
- rdio.completeAuthentication(verifier, function (err) {
- if (err) {
- console.log("ERROR: " + err);
- done();
- return;
- }
-
- // Get a list of playlists.
- rdio.call("getPlaylists", {}, function (err, data) {
- if (err) {
- console.log("ERROR: " + err);
- done();
- return;
- }
-
- var playlists = data.result.owned;
-
- console.log("You have the following playlists:");
-
- playlists.forEach(function (playlist) {
- console.log(playlist.name);
- });
-
- done();
- });
- });
- });
-});
@@ -1,4 +0,0 @@
-// You can get these by signing up for a developer account at:
-// http://developer.rdio.com/
-exports.RDIO_CONSUMER_KEY = ""
-exports.RDIO_CONSUMER_SECRET = ""
View
@@ -1,136 +0,0 @@
-var link = require("link"),
- Rdio = require("./../rdio"),
- cred = require("./rdio_consumer_credentials");
-
-var app = new link.Builder;
-
-app.use(link.commonLogger);
-app.use(link.contentType);
-app.use(link.contentLength);
-app.use(link.sessionCookie);
-
-app.route("/", function (env, callback) {
- var session = env["link.session"];
- var accessToken = session.at;
- var accessTokenSecret = session.ats;
-
- if (accessToken && accessTokenSecret) {
- var rdio = new Rdio([cred.RDIO_CONSUMER_KEY, cred.RDIO_CONSUMER_SECRET],
- [accessToken, accessTokenSecret]);
-
- rdio.call("currentUser", function (err, data) {
- if (err && link.handleError(err, env, callback)) {
- return;
- }
-
- var currentUser = data.result;
-
- rdio.call("getPlaylists", function (err, data) {
- if (err && link.handleError(err, env, callback)) {
- return;
- }
-
- var playlists = data.result.owned;
-
- var body = [];
-
- body.push("<html><head><title>Rdio-Simple Example</title></head><body>");
- body.push("<p>" + currentUser.firstName + "'s playlists:</p>");
- body.push("<ul>");
-
- playlists.forEach(function (playlist) {
- body.push('<li><a href="' + playlist.shortUrl + '">' + playlist.name + '</a></li>');
- });
-
- body.push("</ul>");
- body.push('<a href="/logout">Log out of Rdio</a></body></html>');
-
- callback(200, {}, body.join("\n"));
- });
- });
- } else {
- var body = [];
-
- body.push('<html><head><title>Rdio-Simple Example</title></head><body>');
- body.push('<a href="/login">Log into Rdio</a>');
- body.push('</body></html>');
-
- callback(200, {}, body.join("\n"));
- }
-});
-
-app.route("/login", function (env, callback) {
- var session = env["link.session"] = {};
- var req = new link.Request(env);
-
- // Begin the authentication process.
- var rdio = new Rdio([cred.RDIO_CONSUMER_KEY, cred.RDIO_CONSUMER_SECRET]);
- var callbackUrl = req.baseUrl + "/callback";
-
- rdio.beginAuthentication(callbackUrl, function (err, authUrl) {
- if (err && link.handleError(err, env, callback)) {
- return;
- }
-
- // Save the request token/secret in the session.
- session.rt = rdio.token[0];
- session.rts = rdio.token[1];
-
- // Go to Rdio to authenticate the app.
- redirect(authUrl, callback);
- });
-}, "GET");
-
-app.route("/callback", function (env, callback) {
- var session = env["link.session"];
- var req = new link.Request(env);
-
- req.params(function (err, params) {
- if (err && link.handleError(err, env, callback)) {
- return;
- }
-
- var requestToken = session.rt;
- var requestTokenSecret = session.rts;
- var verifier = params.oauth_verifier;
-
- if (requestToken && requestTokenSecret && verifier) {
- // Exchange the verifier and token for an access token.
- var rdio = new Rdio([cred.RDIO_CONSUMER_KEY, cred.RDIO_CONSUMER_SECRET],
- [requestToken, requestTokenSecret]);
-
- rdio.completeAuthentication(verifier, function (err) {
- if (err && link.handleError(err, env, callback)) {
- return;
- }
-
- // Save the access token/secret in the session (and discard the
- // request token/secret).
- session.at = rdio.token[0];
- session.ats = rdio.token[1];
- delete session.rt;
- delete session.rts;
-
- // Go to the home page.
- redirect("/", callback);
- });
- } else {
- // We're missing something important.
- redirect("/logout", callback);
- }
- });
-}, "GET");
-
-app.route("/logout", function (env, callback) {
- env["link.session"] = {};
- redirect("/", callback);
-}, "GET");
-
-var server = link.run(app, {}, function () {
- var addr = server.address();
- console.log("Link server started at %s:%s", addr.address, addr.port);
-});
-
-function redirect(location, callback) {
- callback(302, {"Location": location}, 'Go to <a href="' + location + '">' + location + '</a>');
-}
View
@@ -1,105 +0,0 @@
-var qs = require("querystring"),
- url = require("url"),
- crypto = require("crypto");
-
-module.exports = om;
-
-function om(consumer, urlString, params, token, method, realm, timestamp, nonce) {
- params = params || [];
- method = (method || "POST").toUpperCase();
-
- // Coerce params to array of [key, value] pairs.
- if (!Array.isArray(params)) {
- var paramsArray = [];
-
- for (var key in params) {
- paramsArray.push([key, params[key]]);
- }
-
- params = paramsArray;
- }
-
- var parsed = url.parse(urlString, true);
-
- // Add query params.
- if (parsed.query) {
- for (var key in parsed.query) {
- params.push([key, parsed.query[key]]);
- }
- }
-
- // Generate nonce and timestamp if they weren't provided
- if (typeof timestamp == "undefined" || timestamp == null) {
- timestamp = Math.round(new Date().getTime() / 1000).toString();
- }
- if (typeof nonce == "undefined" || nonce == null) {
- nonce = Math.round(Math.random() * 1000000).toString();
- }
-
- // Add OAuth params.
- params.push(["oauth_version", "1.0"]);
- params.push(["oauth_timestamp", timestamp]);
- params.push(["oauth_nonce", nonce]);
- params.push(["oauth_signature_method", "HMAC-SHA1"]);
- params.push(["oauth_consumer_key", consumer[0]]);
-
- // Calculate the hmac key.
- var hmacKey = consumer[1] + "&";
-
- // If a token was provided, add it to the params and hmac key.
- if (typeof token != "undefined" && token != null) {
- params.push(["oauth_token", token[0]]);
- hmacKey += token[1];
- }
-
- // Sort lexicographically, first by key then by value.
- params.sort();
-
- // Calculate the OAuth signature.
- var paramsString = params.map(function (param) {
- return qs.escape(param[0]) + "=" + qs.escape(param[1]);
- }).join("&");
-
- var urlBase = url.format({
- protocol: parsed.protocol || "http:",
- hostname: parsed.hostname.toLowerCase(),
- pathname: parsed.pathname
- });
-
- var signatureBase = [
- method,
- qs.escape(urlBase),
- qs.escape(paramsString)
- ].join("&");
-
- var hmac = crypto.createHmac("sha1", hmacKey);
- hmac.update(signatureBase);
-
- var oauthSignature = hmac.digest("base64");
-
- // Build the Authorization header.
- var headerParams = [];
-
- if (realm) {
- headerParams.push(["realm", realm]);
- }
-
- headerParams.push(["oauth_signature", oauthSignature]);
-
- // Restrict header params to oauth_* subset.
- var oauthParams = ["oauth_version", "oauth_timestamp", "oauth_nonce",
- "oauth_signature_method", "oauth_signature", "oauth_consumer_key",
- "oauth_token"];
-
- params.forEach(function (param) {
- if (oauthParams.indexOf(param[0]) != -1) {
- headerParams.push(param);
- }
- });
-
- var header = "OAuth " + headerParams.map(function (param) {
- return param[0] + '="' + param[1] + '"';
- }).join(", ");
-
- return header;
-}
Oops, something went wrong.