|
Last change
on this file was 3, checked in by chronos, 6 years ago |
- Modified: Odorik API moved to separate unit UOdorikApi.pas.
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | unit OdorikApi;
|
|---|
| 2 |
|
|---|
| 3 | interface
|
|---|
| 4 |
|
|---|
| 5 | uses
|
|---|
| 6 | System.SysUtils, System.Types, System.Classes;
|
|---|
| 7 |
|
|---|
| 8 | type
|
|---|
| 9 | TOdorikApi = class
|
|---|
| 10 | private
|
|---|
| 11 | public
|
|---|
| 12 | UserName: string;
|
|---|
| 13 | Password: string;
|
|---|
| 14 | ServerUrl: string;
|
|---|
| 15 | function GetCredit: Double;
|
|---|
| 16 | function SendGet(Path, Parameters: string): string;
|
|---|
| 17 | end;
|
|---|
| 18 |
|
|---|
| 19 | implementation
|
|---|
| 20 |
|
|---|
| 21 | function TOdorikApi.SendGet(Path: string; Parameters: string = ''): string;
|
|---|
| 22 | var
|
|---|
| 23 | Url: string;
|
|---|
| 24 | begin
|
|---|
| 25 | if (ServerUrl <> '') and (UserName <> '') and (Password <> '') then begin
|
|---|
| 26 | Url := ServerUrl + Path + '?user=' + UserName + '&password=' + Password;
|
|---|
| 27 | if Parameters <> '' then Url := Url + '&' + Parameters;
|
|---|
| 28 | Result := IdHTTP1.Get(Url);
|
|---|
| 29 | end else Result := '';
|
|---|
| 30 | end;
|
|---|
| 31 |
|
|---|
| 32 | function TOdorikApi.GetCredit: Double;
|
|---|
| 33 | var
|
|---|
| 34 | Response: string;
|
|---|
| 35 | Value: Extended;
|
|---|
| 36 | begin
|
|---|
| 37 | Response := SendGet('/balance');
|
|---|
| 38 | if Response <> '' then begin
|
|---|
| 39 | Response := StringReplace(Response, '.', FormatSettings.DecimalSeparator, [rfReplaceAll]);
|
|---|
| 40 | if TryStrToFloat(Response, Value) then
|
|---|
| 41 | Result := Value
|
|---|
| 42 | else Result := 0;
|
|---|
| 43 | end else Result := 0;
|
|---|
| 44 | end;
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 | end.
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.