Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
WaTrend Create Instance
See more WaTrend Examples
Create a new WaTrend Instance ID.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Http,
Chilkat.StringBuilder,
Chilkat.HttpResponse,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
http: THttp;
resp: THttpResponse;
sbResponseBody: TStringBuilder;
respStatusCode: Integer;
jResp: TJsonObject;
status: string;
instanceId: string;
begin
success := False;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := THttp.Create;
// Use your actual access token instead of 555555555555555555555555555555
resp := THttpResponse.Create;
success := http.HttpNoBody('GET','https://app.watrend.com/api/createinstance.php?access_token=555555555555555555555555555555',resp);
if (success = False) then
begin
WriteLn(http.LastErrorText);
Exit;
end;
sbResponseBody := TStringBuilder.Create;
resp.GetBodySb(sbResponseBody);
respStatusCode := resp.StatusCode;
WriteLn('Response Status Code = ' + respStatusCode);
if (respStatusCode >= 400) then
begin
WriteLn('Response Header:');
WriteLn(resp.Header);
WriteLn('Failed.');
Exit;
end;
// Both success and failed responses use 200 status code.
// A success response contains this JSON in the response body:
// {"status":"success","message":"Instance ID generated successfully","instance_id":"638EE5A76D3AA"}
// A failed response will contain something like this:
// {"status":"error","message":"Access token does not exist"}
WriteLn(resp.BodyStr);
jResp := TJsonObject.Create;
jResp.LoadSb(sbResponseBody);
status := jResp.StringOf('status');
instanceId := '';
if (jResp.HasMember('instance_id') = True) then
begin
instanceId := jResp.StringOf('instance_id');
end;
WriteLn('status: ' + status);
WriteLn('instance_id: ' + instanceId);
http.Free;
resp.Free;
sbResponseBody.Free;
jResp.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.