First up, import it
npm i @protagonists/cry_vs
const CryptoVersus = require("@protagonists/cry-vs");
then create a new Client
instance!
const client = new CryptoVersus.Client();
Client.isValid
returns the client's valid state
this is usually always true unless the client was used to delete the account
in which case the client will become invalid
Boolean
console.log(client.isValid); // true or false
true
Client.isConnected
returns the client's connected state
this is held false until Client.login
is called successfully
Boolean
console.log(client.isConnected); // true or false
false
Client.token
returns the client's token IF connected
otherwise, the value is left undefined
String?
console.log(client.token); // current token
My-String-Token
The constructor can be fed in several parameter options that can affect the client's behaviour
Setting the option create
to true will allow the client to create an account in the off case that the client cannot connect due to a 401 response (account non-existant)
const client = new CryptoVersus.Client({create: true});
Setting keyEnabled
to true will edit the account data to enable api keys on the account upon login in
This is all done before the "ready" event is emitted of course, so you do not have to worry about waiting for the account to update
const client = new CryptoVersus.Client({keyEnabled: true});
debug
is a bit more interesting...
It will show detailed info about all endpoint responses as well as any event data sent to the client
const client = new CryptoVersus.Client({debug: true});
ip
is the domain from which webhooks will send data to when the api is sending events
If you do not have one set with your account yet, it is highly recommended that you set one Because clients cannot receive api events if there is no domain for the events to be sent to
const client = new CryptoVersus.Client({ip: "myIpOrDomain"});
listener
is the domain from which the client will create a listener to and handle events from
now, again, although having an ip and listener is not nessecary, it is highly suggested for otherwise, the client cannot receive events from the api
const client = new CryptoVersus.Client({listener: "myIpOrDomain"});
*take note that if both your ip and listener are the same, you could simply use the ip alone
The client defaults to the ip if the listener is not set
This function will essentially log you into the api using either a username and password or an api key
Client.login(username: String, password: String)
or
Client.login(key: String)
client.login("username", "password");
or
client.login("apiKey");
(see getApiKey)
again, if you have the create
parameter set to true in the constructor,
using the login function with a username and password will create an account instead,
although take note that this does not apply if you're using an api key
Client.refresh
does not serve much of a purpose except from refreshing the client's connection token
it is automatically called a second before the token's expiration to generate a new valid token for the client
*this function does not return a Token
nor can it be awaited
Client.refresh(timeout: Number)
client.refresh(timeout);
timeout
is simply a timeout in milliseconds, if undefined, the timeout defaults to 0 ms
Client.getApiKey()
will refresh and return a brand new api key for the current account
if the account does not have api key enabled though, it will end up with an error
Client.getApiKey()
const key = await client.getApiKey();
having the keyEnabled
parameter set to true in the constructor can ensure that it will be enabled once you log into the account
Client.account
handles account editing, from a new password to setting an event domain
Client.account.edit(options: Any)
for detailed information about the expected format check out Account
await client.account.edit({
username:"new_username",
password:"new_password"
});
Client.account
is prehaps the most destructive function of them all for obvious reasons
Client.account.delete()
await client.account.delete();
After doing such, the client will be tagged as "invalid" (see Client.valid
)
This function is entirely made to test out the webhook system of the api
Client.dostuff()
await client.dostuff();
Having debug messages enabled will show that an event object gets sent to the client upon calling the function
The client will occasionally send events that can be of use to users
Please take in note that the mentionned events are NOT the only events that can be sent from the client,
thoses showed below are merely the events that are completely or partially handled by the client
To learn more about such events, check out this other package: @protagonists/emitter
the ready event is sent when the client logs in
Client.on("ready", ()=>{
//Your code!
});
the debug event is sent whenever a request is sent to the api or the client receives data from the api
Client.on("debug", res=>{
//Your code!
});
For more information about the response object's format, go check out this package: @protagonists/https#response