A wrapper for $fh.act to be used with Angular. Available via bower or npm:
bower install ng-act --save
npm install ng-act --save
To use it you'll need to require the FH module for your Angular application (see below) and also have included the FeedHenry JS SDK in your project.
Unlike the standard usage for $fh.act this module accepts only a single callback and follows the node.js callback style with an error being the first parameter. If you wish you can also use a promise style with this service, simply don't provide a callback parameter when calling an act and an AngularJS promise is returned.
Here's an example of how you could use Act within a service.
angular.module('MyApp', ['FH']).config(function() {
});
angular.module('MyApp').service('MyService', ['FH.Act', function(Act) {
this.someFunction = function() {
// Do an act call with callback and timeout of 5000
Act.callFn('myAct', {
str: 'Sample String'
}, function(err, res) {
if (err) {
if(err.type === Act.ERRORS.NO_NETWORK) {
// Inform user of error
}
// etc...
} else {
// It worked!
}
}, 5000);
// Do an act call using promise and timeout of 5000
Act.callFn('myAct', {
str: 'Sample String'
}, null, 5000).then(function(res) {
// It worked!
}, function(err) {
// Darn...something went wrong
});
};
}]);
To run tests run npm install
in the root directory.
Run npm install
in the test/cloud directory.
Run bower install
in the test/client/default directory.
Go to test/cloud/ and run node application.js
Now you can open test/client/default/index.html or run grunt test
from the root directory
to run tests using PhantomJS so long as application.js is running.
Call an Act with the given name. The params, callback and timeout parameters are optional. If no callback is provided a promise is returned. If a callback is provided it has the format function(err, res).
Set a default timeout in milliseconds for all Act calls.
Stop debug info being printed to the console.
Restart debug info being printed to the console.
These are exposed on the Act.ERRORS object so you can identify the reason for an error.
Indicates that no act name was provided to the call.
When an error occurs that can't be identified.
Occurs when a non JSON response is provided to a cloud callback.
The act name provided is not exposed in main.js.
Indicates an error occurred in the cloud code being called. This occurs if you return an error to the main.js callback function.
Call did not receive a response within the expected timeframe.
Occurs when the device has no network (3G / Wifi) connection.