playbasis.js
v1.4.6
Published
Playbasis Javascript SDK
Downloads
11
Maintainers
Readme
Playbasis Native JS SDK
Playbasis.js allows developers to connect and utilize Playbasis API with Javascript with Promise support.
Development
The development uses git branching model approach, this applies to when you add a new feature and making a new release.
- Clone the project, then
npm install
to install all dependencies to be ready to begin development. - Add API support especially in
src/api/api.xxx.js
according to which API you're targeting to support for Playbasis end-point. You can take a look at Playbasis Live Doc to see which end-point the end-point isn't supported yet. - Write test case (we use jasmine for finished feature you've added in
test/api.xxx.test.js
. - Make sure tests pass by executing
npm run unittest
. - When need to publish to NPM, execute
npm publish
. This will begin build process, and automatically generate documentation of SDK in which it will push to remotegh-pages
branch. - You're done!
Available Commands
The following commands can be executed separately. But normally you will just follow steps in Development section above.
npm run test
ornpm run uniitest
- run unittest for all tests insidetest/
directorynpm run build
- build the project. This will create distribution files insidedist/
npm run doc
- generate documentation based on comments on each function in source file.npm run deploy
- this command should be run afternpm run doc
. It will copy generated document directory then commit and push to remotegh-pages
branch serving live documentation there. You can see it at https://playbasis.github.io/native-sdk-js/.
Deployment needs ghp-import to be installed on your system. You can install it by executing
pip install ghp-import
. That's it. When you executed command in Available Commands section, it will be used automatically.
How to Use
Get it via npm
Execute npm install playbasis.js
or npm install --save playbasis.js
.
Import it in your source file as follows.
var Playbasis = require('playbasis.js');
Get it via manual build
Create a distribution of library file included a minified version by executing gulp build
.
It will create Playbasis.js
and Playbasis.min.js
in ./dist
folder.
Include it in your source code via
<script src="dist/Playbasis.min.js"></script>
Usage
Create Playbasis's environment first before calling APIs via the following call. Get your apikey, and apisecret by registering a new account, and creating a new application at Playbasis Dashboard.
Playbasis.builder
.setApiKey("<YOUR-API-KEY-HERE>")
.setApiSecret("<YOUR-API-SECRET-HERE>")
.build();
Then you're free to call other apis.
Get player's public information.
Playbasis.playerApi.playerPublicInfo("jon")
.then((result) => {
console.log(result);
})
.error((e) => {
console.log(e.code + ": " + e.message);
});
Execute rule engine click
action for player id jon
. This rule is set up via Playbasis Dashboard to give dynamic reward upon executing the call.
By specify reward
, and quantity
we can customize reward and its amount to give to player.
Playbasis.engineApi.rule("click", "jon", {reward: "point", quantity: 20})
.then((result) => {
console.log(result);
})
.error((e) => {
console.log(e.code + ": " + e.message);
});
Document
There's many more apis you can call. There're 2 options for you.
- Generate it manually via
npm run doc
. Document will be generated atdocs/
thus you can look at it offline. - Go to live document (generated and deployed using commands represented in Available Commands section) at https://playbasis.github.io/native-sdk-js/. We update it against every release. Thus it's always latest.
License
Playbasis.js is available under the MIT license.