# API Methods related to wasp-api. - - - ## type APIClient ```pascal type APIClient = record(TSRLBaseRecord) class var Disabled: Boolean; HTTPClient: Int32; StatsServer: String; UUID: String; Timer: TCountDown; TimeStamp: UInt64; IsSetup: Boolean; Benchmark: TIntegerArray; Fails: Int32; end; ``` Type responsible for stats submissions. This is basically a simba wrapper for the waspscripts API. You can find the API docs in https://api.waspscripts.com/docs if you need to read them but the APIClient should be able to do everything for you. - - - ## APICLient.SetUsername ```pascal procedure TAPICLient.SetUsername(user: String = ''); ``` Sets APICLient username if it hasn't been set yet. - - - ## APIClient.Setup ```pascal procedure TAPIClient.Setup(); ``` Internal method automatically called when attempting to use APIClient.GET() and APIClient.POST(). - - - ## APIClient.GetUUID ```pascal function TAPIClient.GetUUID(): String; ``` Returns your UUID. Example: ```pascal WriteLn APIClient.GetUUID(); ``` - - - ## APIClient.GetPassword ```pascal function TAPIClient.GetPassword(): String; ``` Returns your Password. Example: ```pascal WriteLn APIClient.GetPassword(); ``` - - - ## APIClient.GetUsername ```pascal function TAPIClient.GetUsername(): String; ``` Returns your Username. Example: ```pascal WriteLn APIClient.GetUsername(); ``` - - - ## APIClient.SetLocal ```pascal procedure TAPIClient.SetLocal(port: Int32 = 8080); ``` Method only meant to be used if you are hosting a local stats server for debugging purposes. - - - ## APIClient.HashPassword ```pascal function TAPIClient.HashPassword(password: String): String; ``` Returns a salted and hashed password. This serves no purpose other than giving you a glimpse of what is stored in waspscripts database when you submit your password. Try the example below, notice how everytime you run it you will have slightly different results. That's the magic of "salting" passwords. You can read more about it on the wikipedia https://en.wikipedia.org/wiki/Salt_(cryptography). Example: ```pascal WriteLn APIClient.HashPassword('helloworld'); WriteLn APIClient.HashPassword(StatsPayload.Password); ``` - - - ## APIClient.CheckPassword ```pascal function TAPIClient.CheckPassword(password: String): Boolean; ``` Simply returns true/false if the **password** you submit matches what is stored in waspscripts stats database for the specified **uuid**. Example: ```pascal WriteLn APIClient.CheckPassword('0.999999999999999', 'helloworld'); WriteLn APIClient.CheckPassword(APIClient.Generateuuid(), APIClient.GeneratePassword()); ``` - - - ## APIClient.UpdatePassword ```pascal function TAPIClient.UpdatePassword(old, new: String): Boolean; ``` Because users passwords can be changed and that's what are used by default for stats password a way to update the stats password is required. That's what this method is for. This will probably be complicated for regular users but an easier way can be figured out in the future. Example: ```pascal const PASSWORD: String = 'old_password'; NEW_PASSWORD: String = 'new_password'; begin APIClient.UpdatePassword(PASSWORD, NEW_PASSWORD); end. ``` - - - ## APIClient.CheckStats ```pascal function TAPIClient.CheckStats(): String; ``` Returns your stats. Example: ```pascal WriteLn APIClient.CheckStats(); ``` - - - ## APIClient.SubmitStats ```pascal function TAPIClient.SubmitStats(): Boolean; ``` Method to submit stats to wasp-stats with the help of **StatsPayload**. Example: ```pascal StatsPayload.Setup('SCRIPT_ID_HERE', APIClient.GeneratePassword()); StatsPayload.Update(100, 100, 5000); WriteLn APIClient.SubmitStats(APIClient.Generateuuid()); ``` - - - ## APIClient.Pause ```pascal procedure TAPIClient.Pause(); ``` Method used to pause the APIClient timers. - - - ## APIClient.Resume ```pascal procedure TAPIClient.Resume(); ``` Method used to resume the APIClient timers. - - - ## APIClient.GetScript ```pascal APIClient.GetScript(script_id: String; verbose: Boolean = False): String; ``` Retrieves info of the script with the specified **script_id** from https://api.waspscripts.com Example: ```pascal APIClient.GetScript('cf0a01e4-8d20-41c2-a78e-3d83081b388d'); ``` - - - ## APIClient.GetScriptRevision ```pascal function TAPIClient.GetScriptRevision(script_id: String; verbose: Boolean = False): Int32; ``` Retrieves the latest revision number of the script with the specified **script_id** from https://api.waspscripts.com Example: ```pascal WriteLn APIClient.GetScriptRevision('cf0a01e4-8d20-41c2-a78e-3d83081b388d'); ``` - - - ## APIClient.GetVersion ```pascal function TAPIClient.GetVersion(pkg: String; verbose: Boolean = False): String; ``` Retrieves the latest version of the package specified from https://api.waspscripts.com. Example: ```pascal WriteLn APIClient.GetVersion('srl-t'); WriteLn APIClient.GetVersion('wasplib'); ``` - - - ## APIClient.GetAllVersions ```pascal function TAPIClient.GetAllVersions(script_id: String; out revision, srltVersion, wlVersion: String; verbose: Boolean = False): String; ``` Retrieves the latest script revison of **script_id** and the latest SRL-T and WaspLib versions https://api.waspscripts.com.