Skip to content

Commit

Permalink
Merge pull request #5 from ahmader/1.1.0
Browse files Browse the repository at this point in the history
Adding params
  • Loading branch information
jusx authored Oct 27, 2017
2 parents be97243 + 3b6cb2a commit 64f5d5b
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 65 deletions.
132 changes: 123 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ Each API returns it's own set of objects which is all documented on [Wufoo.com]
wufoo.getFormEntries("idofForm", function(err, entries) {
// do something with your entries here.
});

// pass in optional query parameters
var optionalQuery = {pretty: true}

wufoo.getForms(optionalQuery, function(err, forms) {
// do something with your forms here.
});

// get a specific form given the id and pass in optional query parameters
wufoo.getForm("idofForm", optionalQuery, function(err, forms) {
// do something with your forms here.
});

wufoo.getFormEntries("idofForm", optionalQuery, function(err, entries) {
// do something with your entries here.
});
```

### Forms
Expand All @@ -39,9 +55,9 @@ Get all the forms for an account. <code>getForms</code> returns an array of <cod
```javascript

wufoo.getForms(function(err, forms) {
console.log(form.hash);
console.log(form.name);
console.log(form.description);
console.log(forms[0].hash);
console.log(forms[0].name);
console.log(forms[0].description);
// do something here.
});

Expand All @@ -50,6 +66,21 @@ Get all the forms for an account. <code>getForms</code> returns an array of <cod
// do something here.
});

// pass in optional query parameters
var optionalQuery = {pretty: true}

wufoo.getForms(optionalQuery, function(err, forms) {
console.log(forms[0].hash);
console.log(forms[0].name);
console.log(forms[0].description);
// do something here.
});

// get a specific form given the id and pass in optional query parameters
wufoo.getForm("idofForm", optionalQuery, function(err, forms) {
// do something here.
});

```

Convenience methods are provided to get entries, fields and entry count for a <code>Form</code>:
Expand All @@ -68,6 +99,22 @@ Convenience methods are provided to get entries, fields and entry count for a <c
form.getFields(function(err, fields) {
// do something here.
});

// pass in optional query parameters
var optionalQuery = {pretty: true}

form.getEntries(optionalQuery, function(err, entries) {
// do something here.
});

form.getEntriesCount(optionalQuery, function(err, count) {
// do something here.
console.log("There are " + count + " number of entries");
});

form.getFields(optionalQuery, function(err, fields) {
// do something here.
});
```


Expand All @@ -77,11 +124,22 @@ Get all the entries for a form or report. <code>getFormEntries</code> and <code>

```javascript

wufoo.getFormEntries(formid, function(err, entries) {
wufoo.getFormEntries("formid", function(err, entries) {
// do something here.
});

wufoo.getReportEntries("reportid", function(err, entries) {
// do something here.
});

// pass in optional query parameters
var optionalQuery = {pretty: true}

wufoo.getFormEntries("formid", optionalQuery, function(err, entries) {
// do something here.
});

wufoo.getReportEntries(reportid, function(err, entries) {
wufoo.getReportEntries("reportid", optionalQuery, function(err, entries) {
// do something here.
});

Expand All @@ -102,6 +160,18 @@ Get all the reports for an account. <code>getReports</code> returns an array of
// do something here.
});

// pass in optional query parameters
var optionalQuery = {pretty: true}

wufoo.getReports(optionalQuery, function(err, reports) {
// do something here
});

// get a specific form given the id.
wufoo.getReport("idofReport", optionalQuery, function(err, report){
// do something here.
});

```
Convenience methods are provided to get entries, fields and entry count for a Report:

Expand All @@ -119,6 +189,22 @@ Convenience methods are provided to get entries, fields and entry count for a Re
report.getFields(function(err, fields) {
// do something here.
});

// pass in optional query parameters
var optionalQuery = {pretty: true}

report.getEntries(optionalQuery, function(err, entries) {
// do something here.
});

report.getEntriesCount(optionalQuery, function(err, count) {
// do something here.
console.log("There are " + count + " number of entries");
});

report.getFields(optionalQuery, function(err, fields) {
// do something here.
});
```


Expand All @@ -128,7 +214,14 @@ Get all the reports for a form. <code>getFields</code> returns an array of <code

```javascript

wufoo.getFields(formid, function(err, fields) {
wufoo.getFields("formid", function(err, fields) {
// do something here.
});

// pass in optional query parameters
var optionalQuery = {pretty: true}

wufoo.getFields("formid", optionalQuery, function(err, fields) {
// do something here.
});

Expand All @@ -139,7 +232,14 @@ Get all the widgets for a report. <code>getWidgets</code> returns an array of <c

```javascript

wufoo.getWidgets(reportid, function(err, widgets) {
wufoo.getWidgets("reportid", function(err, widgets) {
// do something here.
});

// pass in optional query parameters
var optionalQuery = {pretty: true}

wufoo.getWidgets("reportid", optionalQuery, function(err, widgets) {
// do something here.
});

Expand All @@ -150,7 +250,14 @@ Get all the comments for a form. <code>getComments</code> returns an array of <c

```javascript

wufoo.getComments(formid, function(err, comments) {
wufoo.getComments("formid", function(err, comments) {
// do something here.
});

// pass in optional query parameters
var optionalQuery = {pretty: true}

wufoo.getComments("formid", optionalQuery, function(err, comments) {
// do something here.
});

Expand All @@ -159,7 +266,14 @@ Get all the comments for a form. <code>getComments</code> returns an array of <c
Alternatively if all you need is the amount of comments for a form you can call <code>getCommentCount</code>:
```javascript

wufoo.getCommentCount(formid, function(err, count) {
wufoo.getCommentCount("formid", function(err, count) {
// do something here.
});

// pass in optional query parameters
var optionalQuery = {pretty: true}

wufoo.getCommentCount("formid", optionalQuery, function(err, count) {
// do something here.
});

Expand Down
31 changes: 21 additions & 10 deletions lib/generics.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,31 @@ function GenericParentEntity(wufoo) {
this.wufoo = wufoo;
}

GenericParentEntity.prototype.getFields = function(fn) {
this._cacheOrFetch(this.linkFields, "Fields", fn);
// build the arguments id, params, fn
GenericParentEntity.prototype.buildArgs = function() { // (arguments)
var args = Array.prototype.slice.call(arguments, 0),
params = (args.length==2 ? args.shift() : {}),
fn = args.shift();
return {params: params, fn: fn};
}

GenericParentEntity.prototype.getEntries = function (fn) {
this._cacheOrFetch(this.linkEntries, "Entries", fn);
GenericParentEntity.prototype.getFields = function() {
var args = this.buildArgs.apply(null, arguments);
this._cacheOrFetch(this.linkFields, "Fields", args.params, args.fn);
}

GenericParentEntity.prototype.getEntriesCount = function(fn) {
GenericParentEntity.prototype.getEntries = function () {
var args = this.buildArgs.apply(null, arguments);
this._cacheOrFetch(this.linkEntries, "Entries", args.params, args.fn);
}

GenericParentEntity.prototype.getEntriesCount = function() {
var self = this;
this._cacheOrAction("entriesCount", fn, function(){
self.wufoo.get(self.linkEntriesCount, function(err, json) {
var args = this.buildArgs.apply(null, arguments);
this._cacheOrAction("entriesCount", args.fn, function(){
self.wufoo.get(self.linkEntriesCount, args.params, function(err, json) {
self.entriesCount = Number(json.EntryCount);
fn(err, self.entriesCount);
args.fn(err, self.entriesCount);
});
});
}
Expand All @@ -42,12 +53,12 @@ GenericParentEntity.prototype._cacheOrAction = function(propName, fn, action) {
}

// wrapper for fetching objects from wufoo cacheOrAction is called to check for local copy existence first.
GenericParentEntity.prototype._cacheOrFetch = function(link, propName, fn) {
GenericParentEntity.prototype._cacheOrFetch = function(link, propName, params, fn) {
var self = this;
var thisProp = propName.toLowerCase();

this._cacheOrAction(thisProp, fn, function() {
self.wufoo.get(link, function(err, json) {
self.wufoo.get(link, params, function(err, json) {
self[thisProp] = utils.cloneObjects(json[propName], function() {return new GenericEntity(self.wufoo)});
fn(err, self[thisProp]);
});
Expand Down
Loading

0 comments on commit 64f5d5b

Please sign in to comment.