Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated to https and tweaked the posts/all so it can receive a parameter

  • Loading branch information...
commit c73c0ebc42488a09f33b1c21d44a14a7f29e5c74 1 parent fec90ac
@fczuardi authored
Showing with 18 additions and 15 deletions.
  1. +7 −7 README.md
  2. +11 −8 lib/forrst.js
View
14 README.md
@@ -13,7 +13,7 @@ Work in progress...
This wapper is at the moment basically an extension of Node.js’s [http.get](http://nodejs.org/docs/v0.4.8/api/http.html#http.get)
method, below are 2 basic examples of how to use it:
-### Methods with no parameters
+### Calling the stats method
var forrst = require('forrst');
forrst.stats(function(res){
@@ -27,11 +27,12 @@ method, below are 2 basic examples of how to use it:
console.error(e);
});
-Forrst methods that dont have parameters, such as [stats](http://forrst.com/api#m-stats) and
-[posts/all](http://forrst.com/api#m-posts-all) are called with only one argument on node-forrst, the callback
-that works like a regular node.js http request callback.
+The stats method is the only one that don't accept parameters, so the only argument to pass to forrst.stats is the callback function.
-### Methods with parameters
+For all other methods you pass an object containing the method parameters as the first argument and the callback function as the second argument,
+see the example below:
+
+### Calling any other method
var forrst = require('forrst');
forrst.posts.list({post_type:'snap'}, function(res){
@@ -46,8 +47,7 @@ that works like a regular node.js http request callback.
console.error(e);
});
-For all other methods the first argument is an object with the method parameters
-and the second is the callback function. The method names use dots instead of slashes, so posts/list become posts.list
+The method names use dots instead of slashes, so posts/list become posts.list
## Implemented Methods
View
19 lib/forrst.js
@@ -3,25 +3,28 @@ var defaults = {
host: "forrst.com"
, endpoint: "/api/v2/"
};
-
//libraries
-var http = require('http')
+var https = require('https')
, querystring = require('querystring');
//private functions
function forrstGet(method, params, callback){
var path = defaults.endpoint + method;
if (typeof params !== 'object') {
- throw new TypeError('Method '+method.replace('/','.')+
- ' expects an object as the first argument. Found '+
- (typeof params)+' instead.');
+ if ((method == 'posts/all/') && (typeof params == 'undefined')){
+ params = {};
+ } else {
+ throw new TypeError('Method '+method.replace('/','.')+
+ ' expects an object as the first argument. Found '+
+ (typeof params)+' instead.');
+ }
}
if (typeof callback !== 'function') {
throw new TypeError('Callback for '+method+' needs to be a function. Found '+
(typeof params)+' instead.');
}
path = path + "?" + querystring.stringify(params);
- return http.get({ host: defaults.host, path: path}, callback);
+ return https.get({ host: defaults.host, path: path}, callback);
}
//exports
@@ -33,7 +36,7 @@ this.user = {
posts: forrstGet.bind(null, "user/posts")
};
this.posts = {
- all: forrstGet.bind(null, "posts/all/", {})
+ all: forrstGet.bind(null, "posts/all/")
, show: forrstGet.bind(null, "posts/show")
, list: forrstGet.bind(null, "posts/list")
-};
+};
Please sign in to comment.
Something went wrong with that request. Please try again.