Changeset 5 for trunk/UFioAPI.pas


Ignore:
Timestamp:
Mar 14, 2013, 7:55:02 PM (11 years ago)
Author:
chronos
Message:
  • Upraveno: Použita knihovna openssl namísto cryptlib. Přidány binární knihovny.
  • Přidáno: Třídy TFioAPI nyní umí načítat data přes API.
  • Přidáno: Dokument popisu API rozhraní.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UFioAPI.pas

    r4 r5  
    66
    77uses
    8   Classes, SysUtils, httpsend;
     8  Classes, SysUtils, httpsend, ssl_openssl;
    99
    1010type
     
    1313
    1414  TFioAPI = class
     15  private
     16    function Download(URL: string; Data: TStrings): Boolean;
     17  public
    1518    Token: string;
    1619    Format: string;
    17     function Download: Boolean;
     20    function DownloadInterval(TimeFrom, TimeTo: TDateTime; Data: TStrings): Boolean;
     21    function DownloadMonthly(Year, Id: Integer; Data: TStrings): Boolean;
     22    function DownloadLast(Data: TStrings): Boolean;
    1823  end;
    1924
     
    2227{ TFioAPI }
    2328
    24 function TFioAPI.Download: Boolean;
     29function TFioAPI.Download(URL: string; Data: TStrings): Boolean;
    2530var
    2631  HTTPSender: THTTPSend;
     
    3035    Format := 'xml';
    3136    Token := 'dd';
    32 //    HTTPSender.HTTPMethod('GET', 'https://www.fio.cz/ib_api/rest/periods/' + Token +
    33 //      '/2013-03-01/2013-03-15/transactions.' + Format);
    34 HTTPSender.HTTPMethod('GET', 'https://www.fio.cz/e-broker/e-broker.cgi');
     37    HTTPSender.HTTPMethod('GET', URL);
    3538    try
    3639    case HTTPSender.Resultcode of
    3740        100..299:
    3841          begin
    39 {            with TFileStream.Create(TargetFile, fmCreate or fmOpenWrite) do
    40             try
    41               Seek(0, soFromBeginning);
    42               CopyFrom(HTTPSender.Document, 0);
    43             finally
    44               Free;
    45             end;}
     42            Data.LoadFromStream(HTTPSender.Document);
    4643            Result := True;
    4744          end; //informational, success
     
    5350    except
    5451      // We don't care for the reason for this error; the download failed.
    55       Result := false;
     52      Result := False;
    5653    end;
    5754  finally
     
    6057end;
    6158
     59function TFioAPI.DownloadInterval(TimeFrom, TimeTo: TDateTime; Data: TStrings
     60  ): Boolean;
     61begin
     62  Result := Download('https://www.fio.cz/ib_api/rest/periods/' + Token +
     63    '/' + FormatDateTime('yyyy-mm-dd', TimeFrom) +
     64    '/' + FormatDateTime('yyyy-mm-dd', TimeTo) +
     65    '/transactions.' + Format, Data);
     66end;
     67
     68function TFioAPI.DownloadMonthly(Year, Id: Integer; Data: TStrings): Boolean;
     69begin
     70  Result := Download('https://www.fio.cz/ib_api/rest/by-id/' + Token +
     71    '/' + IntToStr(Year) + '/' + IntToStr(Id) +
     72    '/transactions.' + Format, Data);
     73end;
     74
     75function TFioAPI.DownloadLast(Data: TStrings): Boolean;
     76begin
     77  Result := Download('https://www.fio.cz/ib_api/rest/last/' + Token +
     78    '/transactions.' + Format, Data);
     79end;
     80
    6281end.
    6382
Note: See TracChangeset for help on using the changeset viewer.