Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Published npm module #11

Closed
wants to merge 2 commits into from

2 participants

Diwank Singh Tomer R. Kevin Nelson
Diwank Singh Tomer

Published npm module and converted node/ into a submodule. (issue #7)

creatorrr added some commits
Diwank Singh Tomer creatorrr Converted node/ to a submodule.
Signed-off-by: Diwank Singh Tomer <diwank.singh@gmail.com>
38734e3
Diwank Singh Tomer creatorrr Pulled latest submodule changes.
Signed-off-by: Diwank Singh Tomer <diwank.singh@gmail.com>
2c23579
R. Kevin Nelson
Collaborator

Thanks for the feedback.

We've talked about this internally a little bit, and we are planning to release this as an npm module, but we're planning to keep the repo within the rdio github account. We're still undecided on whether we want or not to use submodules for this sort of thing.

Closing this for now, since it's not something we're going to merge as-is.

R. Kevin Nelson rknLA closed this
Diwank Singh Tomer

Sounds good, please keep this thread updated with progress on this. I'd be happy to transfer npm endpoint once you guys release it officially.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 27, 2013
  1. Diwank Singh Tomer

    Converted node/ to a submodule.

    creatorrr authored
    Signed-off-by: Diwank Singh Tomer <diwank.singh@gmail.com>
Commits on Mar 29, 2013
  1. Diwank Singh Tomer

    Pulled latest submodule changes.

    creatorrr authored
    Signed-off-by: Diwank Singh Tomer <diwank.singh@gmail.com>
This page is out of date. Refresh to see the latest.
3  .gitmodules
View
@@ -0,0 +1,3 @@
+[submodule "node"]
+ path = node
+ url = git://github.com/creatorrr/node-rdio.git
1  node
@@ -0,0 +1 @@
+Subproject commit 004b756329efb8bb86393b5efbc81e70e59f263f
46 node/README.md
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
-```
54 node/examples/command-line.js
View
@@ -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();
- });
- });
- });
-});
4 node/examples/rdio_consumer_credentials_EXAMPLE.js
View
@@ -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 = ""
136 node/examples/web-based.js
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>');
-}
105 node/om.js
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;
-}
124 node/rdio.js
View
@@ -1,124 +0,0 @@
-var qs = require("querystring"),
- url = require("url"),
- http = require("http"),
- om = require("./om");
-
-module.exports = Rdio;
-
-function Rdio(consumer, token) {
- this.consumer = consumer;
- this.token = token;
-}
-
-Rdio.prototype.beginAuthentication = function beginAuthentication(callbackUrl, callback) {
- var self = this;
-
- this._signedPost("http://api.rdio.com/oauth/request_token", {
- oauth_callback: callbackUrl
- }, function (err, body) {
- if (err) {
- callback(err, null);
- } else {
- var parsed = qs.parse(body);
- var token = [parsed.oauth_token, parsed.oauth_token_secret];
- var authUrl = parsed.login_url + "?oauth_token=" + parsed.oauth_token;
- // Save the token.
- self.token = token;
- // Call the callback with a URL the app can use to auth.
- callback(null, authUrl);
- }
- });
-};
-
-Rdio.prototype.completeAuthentication = function completeAuthentication(verifier, callback) {
- var self = this;
-
- this._signedPost("http://api.rdio.com/oauth/access_token", {
- oauth_verifier: verifier
- }, function (err, body) {
- if (err) {
- callback(err);
- } else {
- var parsed = qs.parse(body);
- var token = [parsed.oauth_token, parsed.oauth_token_secret];
- // Save the token.
- self.token = token;
- // Call the callback.
- callback(null);
- }
- });
-};
-
-Rdio.prototype.call = function call(method, params, callback) {
- if (typeof params == "function") {
- callback = params;
- params = null;
- }
-
- var copy = {};
-
- if (params) {
- for (var param in params) {
- copy[param] = params[param];
- }
- }
-
- copy.method = method;
-
- this._signedPost("http://api.rdio.com/1/", copy, function (err, body) {
- if (err) {
- callback(err);
- } else {
- callback(null, JSON.parse(body));
- }
- });
-};
-
-Rdio.prototype._signedPost = function signedPost(urlString, params, callback) {
- var auth = om(this.consumer, urlString, params, this.token);
- var parsed = url.parse(urlString);
- var content = qs.stringify(params);
-
- var req = http.request({
- method: "POST",
- host: parsed.host,
- port: parsed.port || "80",
- path: parsed.pathname,
- headers: {
- "Authorization": auth,
- "Content-Type": "application/x-www-form-urlencoded",
- "Content-Length": content.length.toString()
- }
- }, function (res) {
- var body = "";
-
- res.setEncoding("utf8");
-
- res.on("data", function (chunk) {
- body += chunk;
- });
-
- res.on("end", function () {
- var data = {};
-
- try {
- data = JSON.parse(body);
- } catch(e) {
- data.status = 'error';
- data.message = body;
- }
-
- if (data.status === 'error') {
- callback(data.message);
- } else {
- callback(null, body);
- }
- });
- });
-
- req.on("error", function (err) {
- callback(err);
- });
-
- req.end(content);
-};
Something went wrong with that request. Please try again.