Chilkat Online Tools

RetryBuild Delphi (DLL) Example

AWS CodeBuild

var
rest: HCkRest;
success: Boolean;
authAws: HCkAuthAws;
json: HCkJsonObject;
sbRequestBody: HCkStringBuilder;
sbResponseBody: HCkStringBuilder;
respStatusCode: Integer;
jResp: HCkJsonObject;
strVal: PWideChar;
name: PWideChar;
v_type: PWideChar;
value: PWideChar;
identifier: PWideChar;
location: PWideChar;
mountOptions: PWideChar;
mountPoint: PWideChar;
durationInSeconds: Integer;
endTime: Integer;
phaseStatus: PWideChar;
phaseType: PWideChar;
startTime: Integer;
j: Integer;
count_j: Integer;
message: PWideChar;
statusCode: PWideChar;
artifactIdentifier: PWideChar;
bucketOwnerAccess: PWideChar;
encryptionDisabled: Integer;
md5sum: PWideChar;
overrideArtifactName: Integer;
sha256sum: PWideChar;
authResource: PWideChar;
authType: PWideChar;
buildspec: PWideChar;
buildStatusConfigContext: PWideChar;
buildStatusConfigTargetUrl: PWideChar;
gitCloneDepth: Integer;
gitSubmodulesConfigFetchSubmodules: Integer;
insecureSsl: Integer;
reportBuildStatus: Integer;
sourceIdentifier: PWideChar;
sourceVersion: PWideChar;
Arn: PWideChar;
ArtifactIdentifier: PWideChar;
BucketOwnerAccess: PWideChar;
EncryptionDisabled: Integer;
Location: PWideChar;
Md5sum: PWideChar;
OverrideArtifactName: Integer;
Sha256sum: PWideChar;
BuildBatchArn: PWideChar;
BuildComplete: Integer;
BuildNumber: Integer;
BuildStatus: PWideChar;
CacheLocation: PWideChar;
v_Type: PWideChar;
CurrentPhase: PWideChar;
SessionEnabled: Integer;
SessionTarget: PWideChar;
EncryptionKey: PWideChar;
EndTime: Integer;
Certificate: PWideChar;
ComputeType: PWideChar;
Image: PWideChar;
ImagePullCredentialsType: PWideChar;
PrivilegedMode: Integer;
Credential: PWideChar;
CredentialProvider: PWideChar;
EnvironmentType: PWideChar;
Id: PWideChar;
Initiator: PWideChar;
GroupName: PWideChar;
Status: PWideChar;
StreamName: PWideChar;
CloudWatchLogsArn: PWideChar;
DeepLink: PWideChar;
LogsGroupName: PWideChar;
S3DeepLink: PWideChar;
S3LogsBucketOwnerAccess: PWideChar;
S3LogsEncryptionDisabled: Integer;
S3LogsLocation: PWideChar;
S3LogsStatus: PWideChar;
S3LogsArn: PWideChar;
LogsStreamName: PWideChar;
NetworkInterfaceId: PWideChar;
SubnetId: PWideChar;
ProjectName: PWideChar;
QueuedTimeoutInMinutes: Integer;
ResolvedSourceVersion: PWideChar;
ServiceRole: PWideChar;
Resource: PWideChar;
AuthType: PWideChar;
Buildspec: PWideChar;
Context: PWideChar;
TargetUrl: PWideChar;
GitCloneDepth: Integer;
FetchSubmodules: Integer;
InsecureSsl: Integer;
SourceLocation: PWideChar;
ReportBuildStatus: Integer;
SourceIdentifier: PWideChar;
SourceType: PWideChar;
SourceVersion: PWideChar;
StartTime: Integer;
TimeoutInMinutes: Integer;
VpcId: PWideChar;
i: Integer;
count_i: Integer;

begin
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

rest := CkRest_Create();

authAws := CkAuthAws_Create();
CkAuthAws_putAccessKey(authAws,'AWS_ACCESS_KEY');
CkAuthAws_putSecretKey(authAws,'AWS_SECRET_KEY');

// Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
CkAuthAws_putRegion(authAws,'us-west-2');
CkAuthAws_putServiceName(authAws,'codebuild');
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest_SetAuthAws(rest,authAws);

// URL: https://codebuild.us-west-2.amazonaws.com/
// Use the same region as specified above.
success := CkRest_Connect(rest,'codebuild.us-west-2.amazonaws.com',443,True,True);
if (success <> True) then
  begin
    Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(CkRest_getConnectFailReason(rest)));
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

// The following code creates the JSON request body.
// The JSON created by this code is shown below.

// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON

json := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'id','string');
CkJsonObject_UpdateString(json,'idempotencyToken','string');

// The JSON request body created by the above code:

// {
//   "id": "string",
//   "idempotencyToken": "string"
// }

CkRest_AddHeader(rest,'Content-Type','application/x-amz-json-1.1');
CkRest_AddHeader(rest,'X-Amz-Target','CodeBuild_20161006.RetryBuild');

sbRequestBody := CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);
sbResponseBody := CkStringBuilder_Create();
success := CkRest_FullRequestSb(rest,'POST','/',sbRequestBody,sbResponseBody);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;
respStatusCode := CkRest_getResponseStatusCode(rest);
Memo1.Lines.Add('response status code = ' + IntToStr(respStatusCode));
if (respStatusCode <> 200) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkRest__responseHeader(rest));
    Memo1.Lines.Add('Response Body:');
    Memo1.Lines.Add(CkStringBuilder__getAsString(sbResponseBody));
    Exit;
  end;

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);

// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.

// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON

Arn := CkJsonObject__stringOf(jResp,'build.arn');
ArtifactIdentifier := CkJsonObject__stringOf(jResp,'build.artifacts.artifactIdentifier');
BucketOwnerAccess := CkJsonObject__stringOf(jResp,'build.artifacts.bucketOwnerAccess');
EncryptionDisabled := CkJsonObject_IntOf(jResp,'build.artifacts.encryptionDisabled');
Location := CkJsonObject__stringOf(jResp,'build.artifacts.location');
Md5sum := CkJsonObject__stringOf(jResp,'build.artifacts.md5sum');
OverrideArtifactName := CkJsonObject_IntOf(jResp,'build.artifacts.overrideArtifactName');
Sha256sum := CkJsonObject__stringOf(jResp,'build.artifacts.sha256sum');
BuildBatchArn := CkJsonObject__stringOf(jResp,'build.buildBatchArn');
BuildComplete := CkJsonObject_IntOf(jResp,'build.buildComplete');
BuildNumber := CkJsonObject_IntOf(jResp,'build.buildNumber');
BuildStatus := CkJsonObject__stringOf(jResp,'build.buildStatus');
CacheLocation := CkJsonObject__stringOf(jResp,'build.cache.location');
v_Type := CkJsonObject__stringOf(jResp,'build.cache.type');
CurrentPhase := CkJsonObject__stringOf(jResp,'build.currentPhase');
SessionEnabled := CkJsonObject_IntOf(jResp,'build.debugSession.sessionEnabled');
SessionTarget := CkJsonObject__stringOf(jResp,'build.debugSession.sessionTarget');
EncryptionKey := CkJsonObject__stringOf(jResp,'build.encryptionKey');
EndTime := CkJsonObject_IntOf(jResp,'build.endTime');
Certificate := CkJsonObject__stringOf(jResp,'build.environment.certificate');
ComputeType := CkJsonObject__stringOf(jResp,'build.environment.computeType');
Image := CkJsonObject__stringOf(jResp,'build.environment.image');
ImagePullCredentialsType := CkJsonObject__stringOf(jResp,'build.environment.imagePullCredentialsType');
PrivilegedMode := CkJsonObject_IntOf(jResp,'build.environment.privilegedMode');
Credential := CkJsonObject__stringOf(jResp,'build.environment.registryCredential.credential');
CredentialProvider := CkJsonObject__stringOf(jResp,'build.environment.registryCredential.credentialProvider');
EnvironmentType := CkJsonObject__stringOf(jResp,'build.environment.type');
Id := CkJsonObject__stringOf(jResp,'build.id');
Initiator := CkJsonObject__stringOf(jResp,'build.initiator');
GroupName := CkJsonObject__stringOf(jResp,'build.logs.cloudWatchLogs.groupName');
Status := CkJsonObject__stringOf(jResp,'build.logs.cloudWatchLogs.status');
StreamName := CkJsonObject__stringOf(jResp,'build.logs.cloudWatchLogs.streamName');
CloudWatchLogsArn := CkJsonObject__stringOf(jResp,'build.logs.cloudWatchLogsArn');
DeepLink := CkJsonObject__stringOf(jResp,'build.logs.deepLink');
LogsGroupName := CkJsonObject__stringOf(jResp,'build.logs.groupName');
S3DeepLink := CkJsonObject__stringOf(jResp,'build.logs.s3DeepLink');
S3LogsBucketOwnerAccess := CkJsonObject__stringOf(jResp,'build.logs.s3Logs.bucketOwnerAccess');
S3LogsEncryptionDisabled := CkJsonObject_IntOf(jResp,'build.logs.s3Logs.encryptionDisabled');
S3LogsLocation := CkJsonObject__stringOf(jResp,'build.logs.s3Logs.location');
S3LogsStatus := CkJsonObject__stringOf(jResp,'build.logs.s3Logs.status');
S3LogsArn := CkJsonObject__stringOf(jResp,'build.logs.s3LogsArn');
LogsStreamName := CkJsonObject__stringOf(jResp,'build.logs.streamName');
NetworkInterfaceId := CkJsonObject__stringOf(jResp,'build.networkInterface.networkInterfaceId');
SubnetId := CkJsonObject__stringOf(jResp,'build.networkInterface.subnetId');
ProjectName := CkJsonObject__stringOf(jResp,'build.projectName');
QueuedTimeoutInMinutes := CkJsonObject_IntOf(jResp,'build.queuedTimeoutInMinutes');
ResolvedSourceVersion := CkJsonObject__stringOf(jResp,'build.resolvedSourceVersion');
ServiceRole := CkJsonObject__stringOf(jResp,'build.serviceRole');
Resource := CkJsonObject__stringOf(jResp,'build.source.auth.resource');
AuthType := CkJsonObject__stringOf(jResp,'build.source.auth.type');
Buildspec := CkJsonObject__stringOf(jResp,'build.source.buildspec');
Context := CkJsonObject__stringOf(jResp,'build.source.buildStatusConfig.context');
TargetUrl := CkJsonObject__stringOf(jResp,'build.source.buildStatusConfig.targetUrl');
GitCloneDepth := CkJsonObject_IntOf(jResp,'build.source.gitCloneDepth');
FetchSubmodules := CkJsonObject_IntOf(jResp,'build.source.gitSubmodulesConfig.fetchSubmodules');
InsecureSsl := CkJsonObject_IntOf(jResp,'build.source.insecureSsl');
SourceLocation := CkJsonObject__stringOf(jResp,'build.source.location');
ReportBuildStatus := CkJsonObject_IntOf(jResp,'build.source.reportBuildStatus');
SourceIdentifier := CkJsonObject__stringOf(jResp,'build.source.sourceIdentifier');
SourceType := CkJsonObject__stringOf(jResp,'build.source.type');
SourceVersion := CkJsonObject__stringOf(jResp,'build.sourceVersion');
StartTime := CkJsonObject_IntOf(jResp,'build.startTime');
TimeoutInMinutes := CkJsonObject_IntOf(jResp,'build.timeoutInMinutes');
VpcId := CkJsonObject__stringOf(jResp,'build.vpcConfig.vpcId');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'build.cache.modes');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'build.cache.modes[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'build.environment.environmentVariables');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    name := CkJsonObject__stringOf(jResp,'build.environment.environmentVariables[i].name');
    v_type := CkJsonObject__stringOf(jResp,'build.environment.environmentVariables[i].type');
    value := CkJsonObject__stringOf(jResp,'build.environment.environmentVariables[i].value');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'build.exportedEnvironmentVariables');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    name := CkJsonObject__stringOf(jResp,'build.exportedEnvironmentVariables[i].name');
    value := CkJsonObject__stringOf(jResp,'build.exportedEnvironmentVariables[i].value');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'build.fileSystemLocations');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    identifier := CkJsonObject__stringOf(jResp,'build.fileSystemLocations[i].identifier');
    location := CkJsonObject__stringOf(jResp,'build.fileSystemLocations[i].location');
    mountOptions := CkJsonObject__stringOf(jResp,'build.fileSystemLocations[i].mountOptions');
    mountPoint := CkJsonObject__stringOf(jResp,'build.fileSystemLocations[i].mountPoint');
    v_type := CkJsonObject__stringOf(jResp,'build.fileSystemLocations[i].type');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'build.phases');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    durationInSeconds := CkJsonObject_IntOf(jResp,'build.phases[i].durationInSeconds');
    endTime := CkJsonObject_IntOf(jResp,'build.phases[i].endTime');
    phaseStatus := CkJsonObject__stringOf(jResp,'build.phases[i].phaseStatus');
    phaseType := CkJsonObject__stringOf(jResp,'build.phases[i].phaseType');
    startTime := CkJsonObject_IntOf(jResp,'build.phases[i].startTime');
    j := 0;
    count_j := CkJsonObject_SizeOfArray(jResp,'build.phases[i].contexts');
    while j < count_j do
      begin
        CkJsonObject_putJ(jResp,j);
        message := CkJsonObject__stringOf(jResp,'build.phases[i].contexts[j].message');
        statusCode := CkJsonObject__stringOf(jResp,'build.phases[i].contexts[j].statusCode');
        j := j + 1;
      end;

    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'build.reportArns');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'build.reportArns[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'build.secondaryArtifacts');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    artifactIdentifier := CkJsonObject__stringOf(jResp,'build.secondaryArtifacts[i].artifactIdentifier');
    bucketOwnerAccess := CkJsonObject__stringOf(jResp,'build.secondaryArtifacts[i].bucketOwnerAccess');
    encryptionDisabled := CkJsonObject_IntOf(jResp,'build.secondaryArtifacts[i].encryptionDisabled');
    location := CkJsonObject__stringOf(jResp,'build.secondaryArtifacts[i].location');
    md5sum := CkJsonObject__stringOf(jResp,'build.secondaryArtifacts[i].md5sum');
    overrideArtifactName := CkJsonObject_IntOf(jResp,'build.secondaryArtifacts[i].overrideArtifactName');
    sha256sum := CkJsonObject__stringOf(jResp,'build.secondaryArtifacts[i].sha256sum');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'build.secondarySources');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    authResource := CkJsonObject__stringOf(jResp,'build.secondarySources[i].auth.resource');
    authType := CkJsonObject__stringOf(jResp,'build.secondarySources[i].auth.type');
    buildspec := CkJsonObject__stringOf(jResp,'build.secondarySources[i].buildspec');
    buildStatusConfigContext := CkJsonObject__stringOf(jResp,'build.secondarySources[i].buildStatusConfig.context');
    buildStatusConfigTargetUrl := CkJsonObject__stringOf(jResp,'build.secondarySources[i].buildStatusConfig.targetUrl');
    gitCloneDepth := CkJsonObject_IntOf(jResp,'build.secondarySources[i].gitCloneDepth');
    gitSubmodulesConfigFetchSubmodules := CkJsonObject_IntOf(jResp,'build.secondarySources[i].gitSubmodulesConfig.fetchSubmodules');
    insecureSsl := CkJsonObject_IntOf(jResp,'build.secondarySources[i].insecureSsl');
    location := CkJsonObject__stringOf(jResp,'build.secondarySources[i].location');
    reportBuildStatus := CkJsonObject_IntOf(jResp,'build.secondarySources[i].reportBuildStatus');
    sourceIdentifier := CkJsonObject__stringOf(jResp,'build.secondarySources[i].sourceIdentifier');
    v_type := CkJsonObject__stringOf(jResp,'build.secondarySources[i].type');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'build.secondarySourceVersions');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    sourceIdentifier := CkJsonObject__stringOf(jResp,'build.secondarySourceVersions[i].sourceIdentifier');
    sourceVersion := CkJsonObject__stringOf(jResp,'build.secondarySourceVersions[i].sourceVersion');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'build.vpcConfig.securityGroupIds');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'build.vpcConfig.securityGroupIds[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'build.vpcConfig.subnets');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'build.vpcConfig.subnets[i]');
    i := i + 1;
  end;

// A sample JSON response body parsed by the above code:

// {
//   "build": {
//     "arn": "string",
//     "artifacts": {
//       "artifactIdentifier": "string",
//       "bucketOwnerAccess": "string",
//       "encryptionDisabled": boolean,
//       "location": "string",
//       "md5sum": "string",
//       "overrideArtifactName": boolean,
//       "sha256sum": "string"
//     },
//     "buildBatchArn": "string",
//     "buildComplete": boolean,
//     "buildNumber": number,
//     "buildStatus": "string",
//     "cache": {
//       "location": "string",
//       "modes": [
//         "string"
//       ],
//       "type": "string"
//     },
//     "currentPhase": "string",
//     "debugSession": {
//       "sessionEnabled": boolean,
//       "sessionTarget": "string"
//     },
//     "encryptionKey": "string",
//     "endTime": number,
//     "environment": {
//       "certificate": "string",
//       "computeType": "string",
//       "environmentVariables": [
//         {
//           "name": "string",
//           "type": "string",
//           "value": "string"
//         }
//       ],
//       "image": "string",
//       "imagePullCredentialsType": "string",
//       "privilegedMode": boolean,
//       "registryCredential": {
//         "credential": "string",
//         "credentialProvider": "string"
//       },
//       "type": "string"
//     },
//     "exportedEnvironmentVariables": [
//       {
//         "name": "string",
//         "value": "string"
//       }
//     ],
//     "fileSystemLocations": [
//       {
//         "identifier": "string",
//         "location": "string",
//         "mountOptions": "string",
//         "mountPoint": "string",
//         "type": "string"
//       }
//     ],
//     "id": "string",
//     "initiator": "string",
//     "logs": {
//       "cloudWatchLogs": {
//         "groupName": "string",
//         "status": "string",
//         "streamName": "string"
//       },
//       "cloudWatchLogsArn": "string",
//       "deepLink": "string",
//       "groupName": "string",
//       "s3DeepLink": "string",
//       "s3Logs": {
//         "bucketOwnerAccess": "string",
//         "encryptionDisabled": boolean,
//         "location": "string",
//         "status": "string"
//       },
//       "s3LogsArn": "string",
//       "streamName": "string"
//     },
//     "networkInterface": {
//       "networkInterfaceId": "string",
//       "subnetId": "string"
//     },
//     "phases": [
//       {
//         "contexts": [
//           {
//             "message": "string",
//             "statusCode": "string"
//           }
//         ],
//         "durationInSeconds": number,
//         "endTime": number,
//         "phaseStatus": "string",
//         "phaseType": "string",
//         "startTime": number
//       }
//     ],
//     "projectName": "string",
//     "queuedTimeoutInMinutes": number,
//     "reportArns": [
//       "string"
//     ],
//     "resolvedSourceVersion": "string",
//     "secondaryArtifacts": [
//       {
//         "artifactIdentifier": "string",
//         "bucketOwnerAccess": "string",
//         "encryptionDisabled": boolean,
//         "location": "string",
//         "md5sum": "string",
//         "overrideArtifactName": boolean,
//         "sha256sum": "string"
//       }
//     ],
//     "secondarySources": [
//       {
//         "auth": {
//           "resource": "string",
//           "type": "string"
//         },
//         "buildspec": "string",
//         "buildStatusConfig": {
//           "context": "string",
//           "targetUrl": "string"
//         },
//         "gitCloneDepth": number,
//         "gitSubmodulesConfig": {
//           "fetchSubmodules": boolean
//         },
//         "insecureSsl": boolean,
//         "location": "string",
//         "reportBuildStatus": boolean,
//         "sourceIdentifier": "string",
//         "type": "string"
//       }
//     ],
//     "secondarySourceVersions": [
//       {
//         "sourceIdentifier": "string",
//         "sourceVersion": "string"
//       }
//     ],
//     "serviceRole": "string",
//     "source": {
//       "auth": {
//         "resource": "string",
//         "type": "string"
//       },
//       "buildspec": "string",
//       "buildStatusConfig": {
//         "context": "string",
//         "targetUrl": "string"
//       },
//       "gitCloneDepth": number,
//       "gitSubmodulesConfig": {
//         "fetchSubmodules": boolean
//       },
//       "insecureSsl": boolean,
//       "location": "string",
//       "reportBuildStatus": boolean,
//       "sourceIdentifier": "string",
//       "type": "string"
//     },
//     "sourceVersion": "string",
//     "startTime": number,
//     "timeoutInMinutes": number,
//     "vpcConfig": {
//       "securityGroupIds": [
//         "string"
//       ],
//       "subnets": [
//         "string"
//       ],
//       "vpcId": "string"
//     }
//   }
// }

CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);