Skip to content
This repository

Published npm module #11

Closed
wants to merge 2 commits into from

2 participants

Diwank Singh Tomer kevin nelson
Diwank Singh Tomer

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

added some commits March 27, 2013
Diwank Singh Tomer Converted node/ to a submodule.
Signed-off-by: Diwank Singh Tomer <diwank.singh@gmail.com>
38734e3
Diwank Singh Tomer Pulled latest submodule changes.
Signed-off-by: Diwank Singh Tomer <diwank.singh@gmail.com>
2c23579
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.

kevin nelson rknLA closed this January 02, 2014
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

Showing 2 unique commits by 1 author.

Mar 27, 2013
Diwank Singh Tomer Converted node/ to a submodule.
Signed-off-by: Diwank Singh Tomer <diwank.singh@gmail.com>
38734e3
Mar 28, 2013
Diwank Singh Tomer Pulled latest submodule changes.
Signed-off-by: Diwank Singh Tomer <diwank.singh@gmail.com>
2c23579
This page is out of date. Refresh to see the latest.
3  .gitmodules
... ...
@@ -0,0 +1,3 @@
  1
+[submodule "node"]
  2
+	path = node
  3
+	url = git://github.com/creatorrr/node-rdio.git
1  node
... ...
@@ -0,0 +1 @@
  1
+Subproject commit 004b756329efb8bb86393b5efbc81e70e59f263f
46  node/README.md
Source Rendered
... ...
@@ -1,46 +0,0 @@
1  
-rdio-simple for JavaScript (node.js)
2  
-====================================
3  
-
4  
-An Rdio client including a built-in OAuth implementation.
5  
-
6  
-It has been tested on the 0.4 branch of node.
7  
-
8  
-To install the library simply add the `om.js` and `rdio.js` files
9  
-to your source directory.
10  
-
11  
-Usage
12  
------
13  
-
14  
-To use the library just load the Rdio class from the rdio module:
15  
-```javascript
16  
-var Rdio = require("rdio");
17  
-```
18  
-Create an Rdio instance passing in a tuple with your consumer key and secret:
19  
-```javascript
20  
-var rdio = new Rdio(["consumerkey", "consumersecret"]);
21  
-```
22  
-Make API calls with the call(methodname, params) method:
23  
-```javascript
24  
-rdio.call('get', {'keys': 'a254895,a104386'});
25  
-```
26  
-Authenticate and authorize with the `beginAuthentication` and
27  
-`completeAuthentication` methods.
28  
-
29  
-The current token (either request or access) is stored in `rdio.token` as an
30  
-array with the token and token secret.
31  
-
32  
-Examples
33  
---------
34  
-
35  
-Both examples authenticate and then list the user's playlists. They use
36  
-credentials stored in `rdio_consumer_credentials.js`.
37  
- 
38  
-* [examples/command-line.js](https://github.com/rdio/rdio-simple/blob/master/node/examples/command-line.js)
39  
-* [examples/web-based.js](https://github.com/rdio/rdio-simple/blob/master/node/examples/web-based.js)
40  
-
41  
-**NOTE:** `web-based.js` depends on [Link](http://linkjs.org/). Install the dependency
42  
-in the examples directory by running:
43  
-
44  
-```bash
45  
-npm install link
46  
-```
54  node/examples/command-line.js
... ...
@@ -1,54 +0,0 @@
1  
-var rl = require("readline"),
2  
-    Rdio = require("./../rdio"),
3  
-    cred = require("./rdio_consumer_credentials");
4  
-
5  
-var i = rl.createInterface(process.stdin, process.stdout, null);
6  
-
7  
-function done() {
8  
-    i.close();
9  
-    process.stdin.destroy();
10  
-}
11  
-
12  
-// Create an Rdio object with consumer's credentials.
13  
-var rdio = new Rdio([cred.RDIO_CONSUMER_KEY, cred.RDIO_CONSUMER_SECRET]);
14  
-
15  
-// Authenticate against the Rdio service.
16  
-rdio.beginAuthentication("oob", function (err, authUrl) {
17  
-    if (err) {
18  
-        console.log("ERROR: " + err);
19  
-        done();
20  
-        return;
21  
-    }
22  
-
23  
-    console.log("Go to: " + authUrl);
24  
-
25  
-    // Prompt the user for the verifier code.
26  
-    i.question("Then enter the code: ", function (verifier) {
27  
-        rdio.completeAuthentication(verifier, function (err) {
28  
-            if (err) {
29  
-                console.log("ERROR: " + err);
30  
-                done();
31  
-                return;
32  
-            }
33  
-
34  
-            // Get a list of playlists.
35  
-            rdio.call("getPlaylists", {}, function (err, data) {
36  
-                if (err) {
37  
-                    console.log("ERROR: " + err);
38  
-                    done();
39  
-                    return;
40  
-                }
41  
-
42  
-                var playlists = data.result.owned;
43  
-
44  
-                console.log("You have the following playlists:");
45  
-
46  
-                playlists.forEach(function (playlist) {
47  
-                    console.log(playlist.name);
48  
-                });
49  
-
50  
-                done();
51  
-            });
52  
-        });
53  
-    });
54  
-});
4  node/examples/rdio_consumer_credentials_EXAMPLE.js
... ...
@@ -1,4 +0,0 @@
1  
-// You can get these by signing up for a developer account at:
2  
-// http://developer.rdio.com/
3  
-exports.RDIO_CONSUMER_KEY = ""
4  
-exports.RDIO_CONSUMER_SECRET = ""
136  node/examples/web-based.js
... ...
@@ -1,136 +0,0 @@
1  
-var link = require("link"),
2  
-    Rdio = require("./../rdio"),
3  
-    cred = require("./rdio_consumer_credentials");
4  
-
5  
-var app = new link.Builder;
6  
-
7  
-app.use(link.commonLogger);
8  
-app.use(link.contentType);
9  
-app.use(link.contentLength);
10  
-app.use(link.sessionCookie);
11  
-
12  
-app.route("/", function (env, callback) {
13  
-    var session = env["link.session"];
14  
-    var accessToken = session.at;
15  
-    var accessTokenSecret = session.ats;
16  
-
17  
-    if (accessToken && accessTokenSecret) {
18  
-        var rdio = new Rdio([cred.RDIO_CONSUMER_KEY, cred.RDIO_CONSUMER_SECRET],
19  
-                            [accessToken, accessTokenSecret]);
20  
-
21  
-        rdio.call("currentUser", function (err, data) {
22  
-            if (err && link.handleError(err, env, callback)) {
23  
-                return;
24  
-            }
25  
-
26  
-            var currentUser = data.result;
27  
-
28  
-            rdio.call("getPlaylists", function (err, data) {
29  
-                if (err && link.handleError(err, env, callback)) {
30  
-                    return;
31  
-                }
32  
-
33  
-                var playlists = data.result.owned;
34  
-
35  
-                var body = [];
36  
-
37  
-                body.push("<html><head><title>Rdio-Simple Example</title></head><body>");
38  
-                body.push("<p>" + currentUser.firstName + "'s playlists:</p>");
39  
-                body.push("<ul>");
40  
-
41  
-                playlists.forEach(function (playlist) {
42  
-                    body.push('<li><a href="' + playlist.shortUrl + '">' + playlist.name + '</a></li>');
43  
-                });
44  
-
45  
-                body.push("</ul>");
46  
-                body.push('<a href="/logout">Log out of Rdio</a></body></html>');
47  
-
48  
-                callback(200, {}, body.join("\n"));
49  
-            });
50  
-        });
51  
-    } else {
52  
-        var body = [];
53  
-
54  
-        body.push('<html><head><title>Rdio-Simple Example</title></head><body>');
55  
-        body.push('<a href="/login">Log into Rdio</a>');
56  
-        body.push('</body></html>');
57  
-
58  
-        callback(200, {}, body.join("\n"));
59  
-    }
60  
-});
61  
-
62  
-app.route("/login", function (env, callback) {
63  
-    var session = env["link.session"] = {};
64  
-    var req = new link.Request(env);
65  
-
66  
-    // Begin the authentication process.
67  
-    var rdio = new Rdio([cred.RDIO_CONSUMER_KEY, cred.RDIO_CONSUMER_SECRET]);
68  
-    var callbackUrl = req.baseUrl + "/callback";
69  
-
70  
-    rdio.beginAuthentication(callbackUrl, function (err, authUrl) {
71  
-        if (err && link.handleError(err, env, callback)) {
72  
-            return;
73  
-        }
74  
-
75  
-        // Save the request token/secret in the session.
76  
-        session.rt = rdio.token[0];
77  
-        session.rts = rdio.token[1];
78  
-
79  
-        // Go to Rdio to authenticate the app.
80  
-        redirect(authUrl, callback);
81  
-    });
82  
-}, "GET");
83  
-
84  
-app.route("/callback", function (env, callback) {
85  
-    var session = env["link.session"];
86  
-    var req = new link.Request(env);
87  
-
88  
-    req.params(function (err, params) {
89  
-        if (err && link.handleError(err, env, callback)) {
90  
-            return;
91  
-        }
92  
-
93  
-        var requestToken = session.rt;
94  
-        var requestTokenSecret = session.rts;
95  
-        var verifier = params.oauth_verifier;
96  
-
97  
-        if (requestToken && requestTokenSecret && verifier) {
98  
-            // Exchange the verifier and token for an access token.
99  
-            var rdio = new Rdio([cred.RDIO_CONSUMER_KEY, cred.RDIO_CONSUMER_SECRET],
100  
-                                [requestToken, requestTokenSecret]);
101  
-
102  
-            rdio.completeAuthentication(verifier, function (err) {
103  
-                if (err && link.handleError(err, env, callback)) {
104  
-                    return;
105  
-                }
106  
-
107  
-                // Save the access token/secret in the session (and discard the
108  
-                // request token/secret).
109  
-                session.at = rdio.token[0];
110  
-                session.ats = rdio.token[1];
111  
-                delete session.rt;
112  
-                delete session.rts;
113  
-
114  
-                // Go to the home page.
115  
-                redirect("/", callback);
116  
-            });
117  
-        } else {
118  
-            // We're missing something important.
119  
-            redirect("/logout", callback);
120  
-        }
121  
-    });
122  
-}, "GET");
123  
-
124  
-app.route("/logout", function (env, callback) {
125  
-    env["link.session"] = {};
126  
-    redirect("/", callback);
127  
-}, "GET");
128  
-
129  
-var server = link.run(app, {}, function () {
130  
-    var addr = server.address();
131  
-    console.log("Link server started at %s:%s", addr.address, addr.port);
132  
-});
133  
-
134  
-function redirect(location, callback) {
135  
-    callback(302, {"Location": location}, 'Go to <a href="' + location + '">' + location + '</a>');
136  
-}
105  node/om.js
... ...
@@ -1,105 +0,0 @@
1  
-var qs = require("querystring"),
2  
-    url = require("url"),
3  
-    crypto = require("crypto");
4  
-
5  
-module.exports = om;
6  
-
7  
-function om(consumer, urlString, params, token, method, realm, timestamp, nonce) {
8  
-    params = params || [];
9  
-    method = (method || "POST").toUpperCase();
10  
-
11  
-    // Coerce params to array of [key, value] pairs.
12  
-    if (!Array.isArray(params)) {
13  
-        var paramsArray = [];
14  
-
15  
-        for (var key in params) {
16  
-            paramsArray.push([key, params[key]]);
17  
-        }
18  
-
19  
-        params = paramsArray;
20  
-    }
21  
-
22  
-    var parsed = url.parse(urlString, true);
23  
-
24  
-    // Add query params.
25  
-    if (parsed.query) {
26  
-        for (var key in parsed.query) {
27  
-            params.push([key, parsed.query[key]]);
28  
-        }
29  
-    }
30  
-
31  
-    // Generate nonce and timestamp if they weren't provided
32  
-    if (typeof timestamp == "undefined" || timestamp == null) {
33  
-        timestamp = Math.round(new Date().getTime() / 1000).toString();
34  
-    }
35  
-    if (typeof nonce == "undefined" || nonce == null) {
36  
-        nonce = Math.round(Math.random() * 1000000).toString();
37  
-    }
38  
-
39  
-    // Add OAuth params.
40  
-    params.push(["oauth_version", "1.0"]);
41  
-    params.push(["oauth_timestamp", timestamp]);
42  
-    params.push(["oauth_nonce", nonce]);
43  
-    params.push(["oauth_signature_method", "HMAC-SHA1"]);
44  
-    params.push(["oauth_consumer_key", consumer[0]]);
45  
-
46  
-    // Calculate the hmac key.
47  
-    var hmacKey = consumer[1] + "&";
48  
-
49  
-    // If a token was provided, add it to the params and hmac key.
50  
-    if (typeof token != "undefined" && token != null) {
51  
-        params.push(["oauth_token", token[0]]);
52  
-        hmacKey += token[1];
53  
-    }
54  
-
55  
-    // Sort lexicographically, first by key then by value.
56  
-    params.sort();
57  
-
58  
-    // Calculate the OAuth signature.
59  
-    var paramsString = params.map(function (param) {
60  
-        return qs.escape(param[0]) + "=" + qs.escape(param[1]);
61  
-    }).join("&");
62  
-
63  
-    var urlBase = url.format({
64  
-        protocol: parsed.protocol || "http:",
65  
-        hostname: parsed.hostname.toLowerCase(),
66  
-        pathname: parsed.pathname
67  
-    });
68  
-
69  
-    var signatureBase = [
70  
-        method,
71  
-        qs.escape(urlBase),
72  
-        qs.escape(paramsString)
73  
-    ].join("&");
74  
-
75  
-    var hmac = crypto.createHmac("sha1", hmacKey);
76  
-    hmac.update(signatureBase);
77  
-
78  
-    var oauthSignature = hmac.digest("base64");
79  
-
80  
-    // Build the Authorization header.
81  
-    var headerParams = [];
82  
-
83  
-    if (realm) {
84  
-        headerParams.push(["realm", realm]);
85  
-    }
86  
-
87  
-    headerParams.push(["oauth_signature", oauthSignature]);
88  
-
89  
-    // Restrict header params to oauth_* subset.
90  
-    var oauthParams = ["oauth_version", "oauth_timestamp", "oauth_nonce",
91  
-        "oauth_signature_method", "oauth_signature", "oauth_consumer_key",
92  
-        "oauth_token"];
93  
-
94  
-    params.forEach(function (param) {
95  
-        if (oauthParams.indexOf(param[0]) != -1) {
96  
-            headerParams.push(param);
97  
-        }
98  
-    });
99  
-
100  
-    var header = "OAuth " + headerParams.map(function (param) {
101  
-        return param[0] + '="' + param[1] + '"';
102  
-    }).join(", ");
103  
-
104  
-    return header;
105  
-}
124  node/rdio.js
... ...
@@ -1,124 +0,0 @@
1  
-var qs = require("querystring"),
2  
-    url = require("url"),
3  
-    http = require("http"),
4  
-    om = require("./om");
5  
-
6  
-module.exports = Rdio;
7  
-
8  
-function Rdio(consumer, token) {
9  
-    this.consumer = consumer;
10  
-    this.token = token;
11  
-}
12  
-
13  
-Rdio.prototype.beginAuthentication = function beginAuthentication(callbackUrl, callback) {
14  
-    var self = this;
15  
-
16  
-    this._signedPost("http://api.rdio.com/oauth/request_token", {
17  
-        oauth_callback: callbackUrl
18  
-    }, function (err, body) {
19  
-        if (err) {
20  
-            callback(err, null);
21  
-        } else {
22  
-            var parsed = qs.parse(body);
23  
-            var token = [parsed.oauth_token, parsed.oauth_token_secret];
24  
-            var authUrl = parsed.login_url + "?oauth_token=" + parsed.oauth_token;
25  
-            // Save the token.
26  
-            self.token = token;
27  
-            // Call the callback with a URL the app can use to auth.
28  
-            callback(null, authUrl);
29  
-        }
30  
-    });
31  
-};
32  
-
33  
-Rdio.prototype.completeAuthentication = function completeAuthentication(verifier, callback) {
34  
-    var self = this;
35  
-
36  
-    this._signedPost("http://api.rdio.com/oauth/access_token", {
37  
-        oauth_verifier: verifier
38  
-    }, function (err, body) {
39  
-        if (err) {
40  
-            callback(err);
41  
-        } else {
42  
-            var parsed = qs.parse(body);
43  
-            var token = [parsed.oauth_token, parsed.oauth_token_secret];
44  
-            // Save the token.
45  
-            self.token = token;
46  
-            // Call the callback.
47  
-            callback(null);
48  
-        }
49  
-    });
50  
-};
51  
-
52  
-Rdio.prototype.call = function call(method, params, callback) {
53  
-    if (typeof params == "function") {
54  
-        callback = params;
55  
-        params = null;
56  
-    }
57  
-
58  
-    var copy = {};
59  
-
60  
-    if (params) {
61  
-        for (var param in params) {
62  
-            copy[param] = params[param];
63  
-        }
64  
-    }
65  
-
66  
-    copy.method = method;
67  
-
68  
-    this._signedPost("http://api.rdio.com/1/", copy, function (err, body) {
69  
-        if (err) {
70  
-            callback(err);
71  
-        } else {
72  
-            callback(null, JSON.parse(body));
73  
-        }
74  
-    });
75  
-};
76  
-
77  
-Rdio.prototype._signedPost = function signedPost(urlString, params, callback) {
78  
-    var auth = om(this.consumer, urlString, params, this.token);
79  
-    var parsed = url.parse(urlString);
80  
-    var content = qs.stringify(params);
81  
-
82  
-    var req = http.request({
83  
-        method: "POST",
84  
-        host: parsed.host,
85  
-        port: parsed.port || "80",
86  
-        path: parsed.pathname,
87  
-        headers: {
88  
-            "Authorization": auth,
89  
-            "Content-Type": "application/x-www-form-urlencoded",
90  
-            "Content-Length": content.length.toString()
91  
-        }
92  
-    }, function (res) {
93  
-        var body = "";
94  
-        
95  
-        res.setEncoding("utf8");
96  
-        
97  
-        res.on("data", function (chunk) {
98  
-            body += chunk;
99  
-        });
100  
-
101  
-        res.on("end", function () {
102  
-            var data = {};
103  
-            
104  
-            try {
105  
-                data = JSON.parse(body);
106  
-            } catch(e) {
107  
-                data.status = 'error';
108  
-                data.message = body;
109  
-            }
110  
-
111  
-            if (data.status === 'error') {
112  
-                callback(data.message);
113  
-            } else {
114  
-                callback(null, body);
115  
-            }
116  
-        });
117  
-    });
118  
-
119  
-    req.on("error", function (err) {
120  
-        callback(err);
121  
-    });
122  
-
123  
-    req.end(content);
124  
-};
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.