source: trunk/OdorikApi.pas

Last change on this file was 3, checked in by chronos, 5 years ago
  • Modified: Odorik API moved to separate unit UOdorikApi.pas.
File size: 1.1 KB
Line 
1unit OdorikApi;
2
3interface
4
5uses
6 System.SysUtils, System.Types, System.Classes;
7
8type
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
19implementation
20
21function TOdorikApi.SendGet(Path: string; Parameters: string = ''): string;
22var
23 Url: string;
24begin
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 := '';
30end;
31
32function TOdorikApi.GetCredit: Double;
33var
34 Response: string;
35 Value: Extended;
36begin
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;
44end;
45
46
47
48end.
Note: See TracBrowser for help on using the repository browser.