source: trunk/UFioAPI.pas@ 11

Last change on this file since 11 was 10, checked in by chronos, 12 years ago
  • Opraveno: České znaky v názvu ukládaných výpisů.
  • Opraveno: Název exportu CVS na CSV.
File size: 2.4 KB
Line 
1unit UFioAPI;
2
3{$mode delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, httpsend, ssl_openssl;
9
10type
11
12 TFioDataFormat = (dfXML, dfCVS, dfGPC, dfOFX, dfJSON, dfHTML, dfSTA);
13
14 { TFioAPI }
15
16 TFioAPI = class
17 private
18 function Download(URL: string; Data: TStrings): Boolean;
19 public
20 Token: string;
21 Format: TFioDataFormat;
22 function DownloadInterval(TimeFrom, TimeTo: TDateTime; Data: TStrings): Boolean;
23 function DownloadMonthly(Year, Id: Integer; Data: TStrings): Boolean;
24 function DownloadLast(Data: TStrings): Boolean;
25 end;
26
27const
28 DataFormatText: array[TFioDataFormat] of string = ('XML', 'CSV', 'GPC', 'OFX',
29 'JSON', 'HTML', 'STA');
30 DataFormatURL: array[TFioDataFormat] of string = ('xml', 'csv', 'gpc', 'ofx',
31 'json', 'html', 'sta');
32
33implementation
34
35{ TFioAPI }
36
37function TFioAPI.Download(URL: string; Data: TStrings): Boolean;
38var
39 HTTPSender: THTTPSend;
40begin
41 HTTPSender := THTTPSend.Create;
42 try
43 HTTPSender.HTTPMethod('GET', URL);
44 try
45 case HTTPSender.Resultcode of
46 100..299:
47 begin
48 Data.LoadFromStream(HTTPSender.Document);
49 Result := True;
50 end; //informational, success
51 300..399: Result := False; //redirection. Not implemented, but could be.
52 400..499: Result := False; //client error; 404 not found etc
53 500..599: Result := False; //internal server error
54 else Result := False; //unknown code
55 end;
56 except
57 // We don't care for the reason for this error; the download failed.
58 Result := False;
59 end;
60 finally
61 HTTPSender.Free;
62 end;
63end;
64
65function TFioAPI.DownloadInterval(TimeFrom, TimeTo: TDateTime; Data: TStrings
66 ): Boolean;
67begin
68 Result := Download('https://www.fio.cz/ib_api/rest/periods/' + Token +
69 '/' + FormatDateTime('yyyy-mm-dd', TimeFrom) +
70 '/' + FormatDateTime('yyyy-mm-dd', TimeTo) +
71 '/transactions.' + DataFormatURL[Format], Data);
72end;
73
74function TFioAPI.DownloadMonthly(Year, Id: Integer; Data: TStrings): Boolean;
75begin
76 Result := Download('https://www.fio.cz/ib_api/rest/by-id/' + Token +
77 '/' + IntToStr(Year) + '/' + IntToStr(Id) +
78 '/transactions.' + DataFormatURL[Format], Data);
79end;
80
81function TFioAPI.DownloadLast(Data: TStrings): Boolean;
82begin
83 Result := Download('https://www.fio.cz/ib_api/rest/last/' + Token +
84 '/transactions.' + DataFormatURL[Format], Data);
85end;
86
87end.
88
Note: See TracBrowser for help on using the repository browser.