1.0.4 • Published 4 years ago

@buffedapi/sdk v1.0.4

Weekly downloads
3
License
-
Repository
-
Last release
4 years ago

Buffed API SDK - Javascript

This is the Javascript SDK. You can use this in a node web-server to access the API and manage data and logic for your application.

The application could be a web-app being served by the node application, or it could be some other (android app, desktop game etc) that is using your node app as it's main server.

We do not recommend distributing the Application-Token with instances of your application for security reasons. Better to keep that server-side and program your application to access the server with user credentials (email and password), keeping the Application-Token safely in the server environment.

Installation

Just run:

npm install @buffedapi/sdk

And then import it

const buffedApi = require("@buffedapi/sdk");

And you're ready to go.

Quick-Start guide

The SDK is simple to use. First create a buffed session, supplying Application-Token and ApplicationId if applicable, then login.

CREATE

let buffedSession = new buffedApi.BuffedSession('3298743984234','Ap89efd98yfdv983iuh23');
await buffedSession.login(email,password);

you would obtain these credentials from your user. If this is the first time a user is signing up, you'll want to create an account instead, like so:

let newAccount = new buffedApi.BuffedAccount({username:"NewUser", email:"user@mail.com", password:"mypassword"})
await newAccount.save(buffedSession);

Whenever you make a call to the API you will have to supply the buffedSession object. This is because you may have multiple users running multiple sessions simultaneously.

Account creation uses the Application-Token so doesn't matter at this point if a user is not signed in. Or you could do something like this:

let buffedSession = new buffedApi.BuffedSession('3298743984234','Ap89efd98yfdv983iuh23');
let newAccount = new buffedApi.BuffedAccount({username:"NewUser", email:"user@mail.com", password:"mypassword"})
await newAccount.saveAndLogin(buffedSession);

Then you can go on to do things like:

let newTeam = new buffedApi.BuffedTeam({name:"Team Name"})
await newTeam.save(buffedSession)

And this will automatically create the team using the token for the user who is logged in with this session.

await buffedSession.adminLogin("mail@local.com","securepassword");
let app = new buffedApi.BuffedApplication({name:"Test App"});
await app.save(buffedSession);

Would be a way to create a new application, using the credentials you have from signing up at Buffed API.

READ

You can fetch or fetch_all on most objects:

let applications = await buffedApi.BuffedApplication.fetch_all(buffedSession);
let team = await buffedApi.BuffedTeam.fetch(buffedSession,"f72ac89192b9d81282e9");

UPDATE

You can update existing objects using the save method as well (if it has an object id it will update instead of creating new)

team.name = "New team name";
await team.save(buffedSession);

DELETE

Just call the delete method, and it will delete the resource on the API:

await team.delete(buffedSession);

Further reading

For more information, please visit the Buffed API Docs.

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago