Subversion Repositories currency_converter

Rev

Rev 18 | Rev 22 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 18 Rev 19
Line 423... Line 423...
423
  S_JSON_FILE_INVALID = 'JSON file invalid';
423
  S_JSON_FILE_INVALID = 'JSON file invalid';
424
  S_UNKNOWN_SUCCESS = 'Cannot determinate status of the query.';
424
  S_UNKNOWN_SUCCESS = 'Cannot determinate status of the query.';
425
  S_JSON_UNKNOWN_ERROR = 'Unknown error while loading JSON.';
425
  S_JSON_UNKNOWN_ERROR = 'Unknown error while loading JSON.';
426
  S_API_KEY_INVALID = 'API key invalid.';
426
  S_API_KEY_INVALID = 'API key invalid.';
427
begin
427
begin
428
  try
-
 
429
    {$REGION 'Determinate if we need to download or not'}
428
  {$REGION 'Determinate if we need to download or not'}
430
    if HistoricDate = 0 then
429
  if HistoricDate = 0 then
431
    begin
430
  begin
432
      needDownload := true;
431
    needDownload := true;
433
      if MaxAgeSeconds < -1 then
432
    if MaxAgeSeconds < -1 then
Line 495... Line 494...
495
 
494
 
496
        sJSON := GetPage(url);
495
      sJSON := GetPage(url);
497
 
496
 
498
        xRoot := TlkJSON.ParseText(sJSON) as TlkJSONobject;
497
      xRoot := TlkJSON.ParseText(sJSON) as TlkJSONobject;
499
        if not assigned(xRoot) then raise EVtsCurConvException.Create(S_JSON_FILE_INVALID);
498
      if not assigned(xRoot) then raise EVtsCurConvException.Create(S_JSON_FILE_INVALID);
500
 
499
      try
501
        xSuccess := xRoot.Field['success'] as TlkJSONboolean;
500
        xSuccess := xRoot.Field['success'] as TlkJSONboolean;
502
        if not assigned(xSuccess) then raise EVtsCurConvException.Create(S_UNKNOWN_SUCCESS);
501
        if not assigned(xSuccess) then raise EVtsCurConvException.Create(S_UNKNOWN_SUCCESS);
503
 
502
 
504
        if xSuccess.Value then
503
        if xSuccess.Value then
505
        begin
504
        begin
Line 539... Line 538...
539
            begin
538
            begin
540
              raise EVtsCurConvException.Create(msg);
539
              raise EVtsCurConvException.Create(msg);
541
            end;
540
            end;
542
          end;
541
          end;
543
        end;
542
        end;
-
 
543
      finally
-
 
544
        FreeAndNil(xRoot);
-
 
545
      end;
544
      until not doRetry;
546
    until not doRetry;
545
      {$ENDREGION}
547
    {$ENDREGION}
546
    end;
548
  end;
547
 
549
 
548
    result := sJSON;
550
  result := sJSON;
549
  finally
-
 
550
    FreeAndNil(xRoot);
-
 
551
  end;
-
 
552
end;
551
end;
553
 
552
 
554
end.
553
end.