Skip to content

Commit

Permalink
Merge branch 'master' into 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmader authored Oct 18, 2017
2 parents 4bb7b76 + be97243 commit 3b6cb2a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 38 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![Build](https://circleci.com/gh/jusx/node-wufoo.svg?style=shield&circle-token=3c6bf745453828aa4cc23daf7befe363287e0b97)

# Node-Wufoo

Node-Wufoo is a [Wufoo API] (http://www.wufoo.com/docs/api/v3/) wrapper for [node.js] (http://nodejs.org/). It simplifies working with the Wufoo API and provides an abstraction layer.
Expand Down Expand Up @@ -336,7 +338,7 @@ Please fork it. Add new features or fix bugs and do a pull request. Tests should
- Create new Pull Request.

### Testing
Be sure to have [mocha](http://visionmedia.github.io/mocha/) installed. Run the entire test suite from the root directory of the project:
Be sure to have [mocha](http://mochajs.org/) installed. Run the entire test suite from the root directory of the project:

$ mocha

Expand All @@ -346,4 +348,4 @@ Node-Wufoo implements almost all of the Wufoo RESTful API except the following:
- Updating Entries ([POST API] (http://www.wufoo.com/docs/api/v3/entries/post/)).
- [Login] (http://www.wufoo.com/docs/api/v3/login/).

Implementation and support of the above will be included in future versions.
Implementation and support of the above will be included in future versions.
3 changes: 3 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test:
override:
- mocha
2 changes: 1 addition & 1 deletion lib/webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ WebHook.prototype.delete = function(formid, hashId, fn) {
this.wufoo.request("delete", this.wufoo._toUri("forms/" + formid + "/webhooks/" + hashId), function(err, json) {
fn(err, (json.WebHookDeleteResult.Hash == hashId));
});
}
}
27 changes: 6 additions & 21 deletions lib/wufoo.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = Wufoo;
function Wufoo(account, apiKey) {
this.account = account;
this.url = "https://"+account+".wufoo.com/api/v3/";
this.apiKey = apiKey;
this.apiKey = apiKey;
}

// build the arguments params, fn
Expand Down Expand Up @@ -118,16 +118,6 @@ Wufoo.prototype.get = function (uri, params, fn) {
// uri: full uri
// fn: callback function.
Wufoo.prototype.request = function(method, uri, params, fn) {


if (fn!=undefined && params !=undefined && method.toUpperCase()=='GET') {
params = Object.keys(params).map(function(k) {
//return encodeURIComponent(k) + '=' + encodeURIComponent(params[k])
return (k) + '=' + (params[k])
}).join('&')
uri+='?'+params;
params = {};
}

var options = {
uri: uri,
Expand All @@ -136,11 +126,11 @@ Wufoo.prototype.request = function(method, uri, params, fn) {
"Authorization" : "Basic " + new Buffer(this.apiKey + ":footastic").toString("base64")
}
}
if (fn!=undefined && params !=undefined) options["form"] = params; // params for form post was passed in.

if (fn!=undefined && params !=undefined) options["body"] = require('querystring').stringify(params); // params for form post was passed in.
if (fn == undefined && params != undefined) fn = params; // no params was passed in. In which case it is fn callback.
request(options, function(err, res, body) {

request(options, function(err, res, body) {
if (err){console.error(err);}
fn(err, JSON.parse(body));
});
Expand Down Expand Up @@ -174,7 +164,7 @@ function Form(wufoo) {
}

Form.prototype.addWebhook = function(opt, fn) {
this.wufoo.webhook().add(this.hash, opt, fn);
this.wufoo.webhook().add(this.hash, opt, fn);
}

Form.prototype.deleteWebhook = function(hookid, fn) {
Expand All @@ -191,8 +181,3 @@ Report.prototype.getWidgets = function() {
var args = this.buildArgs.apply(null, arguments);
this._cacheOrFetch(this.linkWidgets, "Widgets", args.params, args.fn);
}





28 changes: 14 additions & 14 deletions test/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,37 @@ var helper = require("./helper.js");

describe("Form", function() {
var $form;

before(function(done) {
helper.wufoo.getForms(function(err, forms){
$form = forms[0];
done(err);
});
})

describe("#getEntries", function() {
it("Should return array of entries", function(done){
$form.getEntries({system:'true'}, function(err, entries){
(entries.constructor == Array).should.be.true;
helper.isEntry(entries[0]);
done(err);
});
});
})

});

describe("#getFields", function() {
it("Should return array of fields", function(done){
$form.getFields({system:'true'}, function(err, fields){
(fields.constructor == Array).should.be.true;
helper.isField(fields[0]);
done(err);
});
});
})


});

describe("#getEntriesCount", function() {
it("Should return a number", function(done) {
$form.getEntriesCount(function(err, count) {
Expand All @@ -42,7 +42,7 @@ describe("Form", function() {
});
});
});

describe("#addWebhook and #deleteWebhook", function() {
it("Should add a webhoook successfully", function(done) {
$form.addWebhook("http://localhost:3000/bin", function(err, hashid) {
Expand All @@ -53,9 +53,9 @@ describe("Form", function() {
done(err);
});
});

});
})
})


})
1 change: 1 addition & 0 deletions test/mocha.opts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--timeout 7000

0 comments on commit 3b6cb2a

Please sign in to comment.