StopBuild unicodeCpp Example
#include <CkRestW.h>
#include <CkAuthAwsW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>
void ChilkatSample(void)
{
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkRestW rest;
bool success;
CkAuthAwsW authAws;
authAws.put_AccessKey(L"AWS_ACCESS_KEY");
authAws.put_SecretKey(L"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.)
authAws.put_Region(L"us-west-2");
authAws.put_ServiceName(L"codebuild");
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.SetAuthAws(authAws);
// URL: https://codebuild.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = rest.Connect(L"codebuild.us-west-2.amazonaws.com",443,true,true);
if (success != true) {
wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
wprintf(L"%s\n",rest.lastErrorText());
return;
}
// 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
CkJsonObjectW json;
json.UpdateString(L"id",L"string");
// The JSON request body created by the above code:
// {
// "id": "string"
// }
rest.AddHeader(L"Content-Type",L"application/x-amz-json-1.1");
rest.AddHeader(L"X-Amz-Target",L"CodeBuild_20161006.StopBuild");
CkStringBuilderW sbRequestBody;
json.EmitSb(sbRequestBody);
CkStringBuilderW sbResponseBody;
success = rest.FullRequestSb(L"POST",L"/",sbRequestBody,sbResponseBody);
if (success != true) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
int respStatusCode = rest.get_ResponseStatusCode();
wprintf(L"response status code = %d\n",respStatusCode);
if (respStatusCode != 200) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",rest.responseHeader());
wprintf(L"Response Body:\n");
wprintf(L"%s\n",sbResponseBody.getAsString());
return;
}
CkJsonObjectW jResp;
jResp.LoadSb(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
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
// See this example explaining how this memory should be used: const char * functions.
const wchar_t *strVal = 0;
const wchar_t *name = 0;
const wchar_t *v_type = 0;
const wchar_t *value = 0;
const wchar_t *identifier = 0;
const wchar_t *location = 0;
const wchar_t *mountOptions = 0;
const wchar_t *mountPoint = 0;
int durationInSeconds;
int endTime;
const wchar_t *phaseStatus = 0;
const wchar_t *phaseType = 0;
int startTime;
int j;
int count_j;
const wchar_t *message = 0;
const wchar_t *statusCode = 0;
const wchar_t *artifactIdentifier = 0;
const wchar_t *bucketOwnerAccess = 0;
int encryptionDisabled;
const wchar_t *md5sum = 0;
int overrideArtifactName;
const wchar_t *sha256sum = 0;
const wchar_t *authResource = 0;
const wchar_t *authType = 0;
const wchar_t *buildspec = 0;
const wchar_t *buildStatusConfigContext = 0;
const wchar_t *buildStatusConfigTargetUrl = 0;
int gitCloneDepth;
int gitSubmodulesConfigFetchSubmodules;
int insecureSsl;
int reportBuildStatus;
const wchar_t *sourceIdentifier = 0;
const wchar_t *sourceVersion = 0;
const wchar_t *Arn = jResp.stringOf(L"build.arn");
const wchar_t *ArtifactIdentifier = jResp.stringOf(L"build.artifacts.artifactIdentifier");
const wchar_t *BucketOwnerAccess = jResp.stringOf(L"build.artifacts.bucketOwnerAccess");
int EncryptionDisabled = jResp.IntOf(L"build.artifacts.encryptionDisabled");
const wchar_t *Location = jResp.stringOf(L"build.artifacts.location");
const wchar_t *Md5sum = jResp.stringOf(L"build.artifacts.md5sum");
int OverrideArtifactName = jResp.IntOf(L"build.artifacts.overrideArtifactName");
const wchar_t *Sha256sum = jResp.stringOf(L"build.artifacts.sha256sum");
const wchar_t *BuildBatchArn = jResp.stringOf(L"build.buildBatchArn");
int BuildComplete = jResp.IntOf(L"build.buildComplete");
int BuildNumber = jResp.IntOf(L"build.buildNumber");
const wchar_t *BuildStatus = jResp.stringOf(L"build.buildStatus");
const wchar_t *CacheLocation = jResp.stringOf(L"build.cache.location");
const wchar_t *v_Type = jResp.stringOf(L"build.cache.type");
const wchar_t *CurrentPhase = jResp.stringOf(L"build.currentPhase");
int SessionEnabled = jResp.IntOf(L"build.debugSession.sessionEnabled");
const wchar_t *SessionTarget = jResp.stringOf(L"build.debugSession.sessionTarget");
const wchar_t *EncryptionKey = jResp.stringOf(L"build.encryptionKey");
int EndTime = jResp.IntOf(L"build.endTime");
const wchar_t *Certificate = jResp.stringOf(L"build.environment.certificate");
const wchar_t *ComputeType = jResp.stringOf(L"build.environment.computeType");
const wchar_t *Image = jResp.stringOf(L"build.environment.image");
const wchar_t *ImagePullCredentialsType = jResp.stringOf(L"build.environment.imagePullCredentialsType");
int PrivilegedMode = jResp.IntOf(L"build.environment.privilegedMode");
const wchar_t *Credential = jResp.stringOf(L"build.environment.registryCredential.credential");
const wchar_t *CredentialProvider = jResp.stringOf(L"build.environment.registryCredential.credentialProvider");
const wchar_t *EnvironmentType = jResp.stringOf(L"build.environment.type");
const wchar_t *Id = jResp.stringOf(L"build.id");
const wchar_t *Initiator = jResp.stringOf(L"build.initiator");
const wchar_t *GroupName = jResp.stringOf(L"build.logs.cloudWatchLogs.groupName");
const wchar_t *Status = jResp.stringOf(L"build.logs.cloudWatchLogs.status");
const wchar_t *StreamName = jResp.stringOf(L"build.logs.cloudWatchLogs.streamName");
const wchar_t *CloudWatchLogsArn = jResp.stringOf(L"build.logs.cloudWatchLogsArn");
const wchar_t *DeepLink = jResp.stringOf(L"build.logs.deepLink");
const wchar_t *LogsGroupName = jResp.stringOf(L"build.logs.groupName");
const wchar_t *S3DeepLink = jResp.stringOf(L"build.logs.s3DeepLink");
const wchar_t *S3LogsBucketOwnerAccess = jResp.stringOf(L"build.logs.s3Logs.bucketOwnerAccess");
int S3LogsEncryptionDisabled = jResp.IntOf(L"build.logs.s3Logs.encryptionDisabled");
const wchar_t *S3LogsLocation = jResp.stringOf(L"build.logs.s3Logs.location");
const wchar_t *S3LogsStatus = jResp.stringOf(L"build.logs.s3Logs.status");
const wchar_t *S3LogsArn = jResp.stringOf(L"build.logs.s3LogsArn");
const wchar_t *LogsStreamName = jResp.stringOf(L"build.logs.streamName");
const wchar_t *NetworkInterfaceId = jResp.stringOf(L"build.networkInterface.networkInterfaceId");
const wchar_t *SubnetId = jResp.stringOf(L"build.networkInterface.subnetId");
const wchar_t *ProjectName = jResp.stringOf(L"build.projectName");
int QueuedTimeoutInMinutes = jResp.IntOf(L"build.queuedTimeoutInMinutes");
const wchar_t *ResolvedSourceVersion = jResp.stringOf(L"build.resolvedSourceVersion");
const wchar_t *ServiceRole = jResp.stringOf(L"build.serviceRole");
const wchar_t *Resource = jResp.stringOf(L"build.source.auth.resource");
const wchar_t *AuthType = jResp.stringOf(L"build.source.auth.type");
const wchar_t *Buildspec = jResp.stringOf(L"build.source.buildspec");
const wchar_t *Context = jResp.stringOf(L"build.source.buildStatusConfig.context");
const wchar_t *TargetUrl = jResp.stringOf(L"build.source.buildStatusConfig.targetUrl");
int GitCloneDepth = jResp.IntOf(L"build.source.gitCloneDepth");
int FetchSubmodules = jResp.IntOf(L"build.source.gitSubmodulesConfig.fetchSubmodules");
int InsecureSsl = jResp.IntOf(L"build.source.insecureSsl");
const wchar_t *SourceLocation = jResp.stringOf(L"build.source.location");
int ReportBuildStatus = jResp.IntOf(L"build.source.reportBuildStatus");
const wchar_t *SourceIdentifier = jResp.stringOf(L"build.source.sourceIdentifier");
const wchar_t *SourceType = jResp.stringOf(L"build.source.type");
const wchar_t *SourceVersion = jResp.stringOf(L"build.sourceVersion");
int StartTime = jResp.IntOf(L"build.startTime");
int TimeoutInMinutes = jResp.IntOf(L"build.timeoutInMinutes");
const wchar_t *VpcId = jResp.stringOf(L"build.vpcConfig.vpcId");
int i = 0;
int count_i = jResp.SizeOfArray(L"build.cache.modes");
while (i < count_i) {
jResp.put_I(i);
strVal = jResp.stringOf(L"build.cache.modes[i]");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"build.environment.environmentVariables");
while (i < count_i) {
jResp.put_I(i);
name = jResp.stringOf(L"build.environment.environmentVariables[i].name");
v_type = jResp.stringOf(L"build.environment.environmentVariables[i].type");
value = jResp.stringOf(L"build.environment.environmentVariables[i].value");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"build.exportedEnvironmentVariables");
while (i < count_i) {
jResp.put_I(i);
name = jResp.stringOf(L"build.exportedEnvironmentVariables[i].name");
value = jResp.stringOf(L"build.exportedEnvironmentVariables[i].value");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"build.fileSystemLocations");
while (i < count_i) {
jResp.put_I(i);
identifier = jResp.stringOf(L"build.fileSystemLocations[i].identifier");
location = jResp.stringOf(L"build.fileSystemLocations[i].location");
mountOptions = jResp.stringOf(L"build.fileSystemLocations[i].mountOptions");
mountPoint = jResp.stringOf(L"build.fileSystemLocations[i].mountPoint");
v_type = jResp.stringOf(L"build.fileSystemLocations[i].type");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"build.phases");
while (i < count_i) {
jResp.put_I(i);
durationInSeconds = jResp.IntOf(L"build.phases[i].durationInSeconds");
endTime = jResp.IntOf(L"build.phases[i].endTime");
phaseStatus = jResp.stringOf(L"build.phases[i].phaseStatus");
phaseType = jResp.stringOf(L"build.phases[i].phaseType");
startTime = jResp.IntOf(L"build.phases[i].startTime");
j = 0;
count_j = jResp.SizeOfArray(L"build.phases[i].contexts");
while (j < count_j) {
jResp.put_J(j);
message = jResp.stringOf(L"build.phases[i].contexts[j].message");
statusCode = jResp.stringOf(L"build.phases[i].contexts[j].statusCode");
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"build.reportArns");
while (i < count_i) {
jResp.put_I(i);
strVal = jResp.stringOf(L"build.reportArns[i]");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"build.secondaryArtifacts");
while (i < count_i) {
jResp.put_I(i);
artifactIdentifier = jResp.stringOf(L"build.secondaryArtifacts[i].artifactIdentifier");
bucketOwnerAccess = jResp.stringOf(L"build.secondaryArtifacts[i].bucketOwnerAccess");
encryptionDisabled = jResp.IntOf(L"build.secondaryArtifacts[i].encryptionDisabled");
location = jResp.stringOf(L"build.secondaryArtifacts[i].location");
md5sum = jResp.stringOf(L"build.secondaryArtifacts[i].md5sum");
overrideArtifactName = jResp.IntOf(L"build.secondaryArtifacts[i].overrideArtifactName");
sha256sum = jResp.stringOf(L"build.secondaryArtifacts[i].sha256sum");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"build.secondarySources");
while (i < count_i) {
jResp.put_I(i);
authResource = jResp.stringOf(L"build.secondarySources[i].auth.resource");
authType = jResp.stringOf(L"build.secondarySources[i].auth.type");
buildspec = jResp.stringOf(L"build.secondarySources[i].buildspec");
buildStatusConfigContext = jResp.stringOf(L"build.secondarySources[i].buildStatusConfig.context");
buildStatusConfigTargetUrl = jResp.stringOf(L"build.secondarySources[i].buildStatusConfig.targetUrl");
gitCloneDepth = jResp.IntOf(L"build.secondarySources[i].gitCloneDepth");
gitSubmodulesConfigFetchSubmodules = jResp.IntOf(L"build.secondarySources[i].gitSubmodulesConfig.fetchSubmodules");
insecureSsl = jResp.IntOf(L"build.secondarySources[i].insecureSsl");
location = jResp.stringOf(L"build.secondarySources[i].location");
reportBuildStatus = jResp.IntOf(L"build.secondarySources[i].reportBuildStatus");
sourceIdentifier = jResp.stringOf(L"build.secondarySources[i].sourceIdentifier");
v_type = jResp.stringOf(L"build.secondarySources[i].type");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"build.secondarySourceVersions");
while (i < count_i) {
jResp.put_I(i);
sourceIdentifier = jResp.stringOf(L"build.secondarySourceVersions[i].sourceIdentifier");
sourceVersion = jResp.stringOf(L"build.secondarySourceVersions[i].sourceVersion");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"build.vpcConfig.securityGroupIds");
while (i < count_i) {
jResp.put_I(i);
strVal = jResp.stringOf(L"build.vpcConfig.securityGroupIds[i]");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"build.vpcConfig.subnets");
while (i < count_i) {
jResp.put_I(i);
strVal = jResp.stringOf(L"build.vpcConfig.subnets[i]");
i = i + 1;
}
// 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"
// }
// }
// }
}