Permalink
Browse files

Merge pull request #14 from cimnine/master

Added the ability request graph paths which already have the graph-prefix
  • Loading branch information...
2 parents e52ff60 + cedbb19 commit 4340999d28e2c516901524030285999ec4f51bf0 @criso committed Oct 18, 2012
Showing with 30 additions and 1 deletion.
  1. +19 −1 lib/graph.js
  2. +11 −0 tests/graph.test.js
View
@@ -57,7 +57,7 @@ function Graph(method, url, postData, callback) {
postData = {};
}
- url = graphUrl + this.cleanUrl(url);
+ url = this.prepareUrl(url);
this.callback = callback || noop;
this.postData = postData;
@@ -74,6 +74,22 @@ function Graph(method, url, postData, callback) {
return this;
}
+
+/**
+ * "Prepares" given url string
+ * - adds protocol and host prefix if none is given
+ * @param {string} url string
+ */
+Graph.prototype.prepareUrl = function(url) {
+ url = this.cleanUrl(url);
+
+ if (url.substr(0,4) !== 'http') {
+ url = graphUrl + url;
+ }
+
+ return url;
+}
+
/**
* "Cleans" given url string
* - adds lading slash
@@ -82,6 +98,8 @@ function Graph(method, url, postData, callback) {
*/
Graph.prototype.cleanUrl = function(url) {
+ url = url.trim();
+
// add leading slash
if (url.charAt(0) !== '/') url = '/' + url;
View
@@ -99,6 +99,17 @@ vows.describe("graph.test").addBatch({
}
},
+ "and requesting an api url with prefixed graphurl": {
+ topic: function() {
+ graph.get(graph.getGraphUrl() + "/zuck/picture", this.callback);
+ },
+
+ "should be able to get valid data": function (err, res) {
+ assert.include(res, "image");
+ assert.include(res, "location");
+ }
+ },
+
"and trying to access data that requires an access token": {
topic: function () {
graph.get("/817129783203", this.callback);

0 comments on commit 4340999

Please sign in to comment.