StopBuild PureBasic Example
IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkRest.pb"
IncludeFile "CkAuthAws.pb"
Procedure ChilkatExample()
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
rest.i = CkRest::ckCreate()
If rest.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i
authAws.i = CkAuthAws::ckCreate()
If authAws.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkAuthAws::setCkAccessKey(authAws, "AWS_ACCESS_KEY")
CkAuthAws::setCkSecretKey(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::setCkRegion(authAws, "us-west-2")
CkAuthAws::setCkServiceName(authAws, "codebuild")
; SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest::ckSetAuthAws(rest,authAws)
; URL: https://codebuild.us-west-2.amazonaws.com/
; Use the same region as specified above.
success = CkRest::ckConnect(rest,"codebuild.us-west-2.amazonaws.com",443,1,1)
If success <> 1
Debug "ConnectFailReason: " + Str(CkRest::ckConnectFailReason(rest))
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
ProcedureReturn
EndIf
; 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.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckUpdateString(json,"id","string")
; The JSON request body created by the above code:
; {
; "id": "string"
; }
CkRest::ckAddHeader(rest,"Content-Type","application/x-amz-json-1.1")
CkRest::ckAddHeader(rest,"X-Amz-Target","CodeBuild_20161006.StopBuild")
sbRequestBody.i = CkStringBuilder::ckCreate()
If sbRequestBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckEmitSb(json,sbRequestBody)
sbResponseBody.i = CkStringBuilder::ckCreate()
If sbResponseBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkRest::ckFullRequestSb(rest,"POST","/",sbRequestBody,sbResponseBody)
If success <> 1
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
CkStringBuilder::ckDispose(sbResponseBody)
ProcedureReturn
EndIf
respStatusCode.i = CkRest::ckResponseStatusCode(rest)
Debug "response status code = " + Str(respStatusCode)
If respStatusCode <> 200
Debug "Response Header:"
Debug CkRest::ckResponseHeader(rest)
Debug "Response Body:"
Debug CkStringBuilder::ckGetAsString(sbResponseBody)
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
CkStringBuilder::ckDispose(sbResponseBody)
ProcedureReturn
EndIf
jResp.i = CkJsonObject::ckCreate()
If jResp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoadSb(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
strVal.s
name.s
v_type.s
value.s
identifier.s
location.s
mountOptions.s
mountPoint.s
durationInSeconds.i
endTime.i
phaseStatus.s
phaseType.s
startTime.i
j.i
count_j.i
message.s
statusCode.s
artifactIdentifier.s
bucketOwnerAccess.s
encryptionDisabled.i
md5sum.s
overrideArtifactName.i
sha256sum.s
authResource.s
authType.s
buildspec.s
buildStatusConfigContext.s
buildStatusConfigTargetUrl.s
gitCloneDepth.i
gitSubmodulesConfigFetchSubmodules.i
insecureSsl.i
reportBuildStatus.i
sourceIdentifier.s
sourceVersion.s
Arn.s = CkJsonObject::ckStringOf(jResp,"build.arn")
ArtifactIdentifier.s = CkJsonObject::ckStringOf(jResp,"build.artifacts.artifactIdentifier")
BucketOwnerAccess.s = CkJsonObject::ckStringOf(jResp,"build.artifacts.bucketOwnerAccess")
EncryptionDisabled.i = CkJsonObject::ckIntOf(jResp,"build.artifacts.encryptionDisabled")
Location.s = CkJsonObject::ckStringOf(jResp,"build.artifacts.location")
Md5sum.s = CkJsonObject::ckStringOf(jResp,"build.artifacts.md5sum")
OverrideArtifactName.i = CkJsonObject::ckIntOf(jResp,"build.artifacts.overrideArtifactName")
Sha256sum.s = CkJsonObject::ckStringOf(jResp,"build.artifacts.sha256sum")
BuildBatchArn.s = CkJsonObject::ckStringOf(jResp,"build.buildBatchArn")
BuildComplete.i = CkJsonObject::ckIntOf(jResp,"build.buildComplete")
BuildNumber.i = CkJsonObject::ckIntOf(jResp,"build.buildNumber")
BuildStatus.s = CkJsonObject::ckStringOf(jResp,"build.buildStatus")
CacheLocation.s = CkJsonObject::ckStringOf(jResp,"build.cache.location")
v_Type.s = CkJsonObject::ckStringOf(jResp,"build.cache.type")
CurrentPhase.s = CkJsonObject::ckStringOf(jResp,"build.currentPhase")
SessionEnabled.i = CkJsonObject::ckIntOf(jResp,"build.debugSession.sessionEnabled")
SessionTarget.s = CkJsonObject::ckStringOf(jResp,"build.debugSession.sessionTarget")
EncryptionKey.s = CkJsonObject::ckStringOf(jResp,"build.encryptionKey")
EndTime.i = CkJsonObject::ckIntOf(jResp,"build.endTime")
Certificate.s = CkJsonObject::ckStringOf(jResp,"build.environment.certificate")
ComputeType.s = CkJsonObject::ckStringOf(jResp,"build.environment.computeType")
Image.s = CkJsonObject::ckStringOf(jResp,"build.environment.image")
ImagePullCredentialsType.s = CkJsonObject::ckStringOf(jResp,"build.environment.imagePullCredentialsType")
PrivilegedMode.i = CkJsonObject::ckIntOf(jResp,"build.environment.privilegedMode")
Credential.s = CkJsonObject::ckStringOf(jResp,"build.environment.registryCredential.credential")
CredentialProvider.s = CkJsonObject::ckStringOf(jResp,"build.environment.registryCredential.credentialProvider")
EnvironmentType.s = CkJsonObject::ckStringOf(jResp,"build.environment.type")
Id.s = CkJsonObject::ckStringOf(jResp,"build.id")
Initiator.s = CkJsonObject::ckStringOf(jResp,"build.initiator")
GroupName.s = CkJsonObject::ckStringOf(jResp,"build.logs.cloudWatchLogs.groupName")
Status.s = CkJsonObject::ckStringOf(jResp,"build.logs.cloudWatchLogs.status")
StreamName.s = CkJsonObject::ckStringOf(jResp,"build.logs.cloudWatchLogs.streamName")
CloudWatchLogsArn.s = CkJsonObject::ckStringOf(jResp,"build.logs.cloudWatchLogsArn")
DeepLink.s = CkJsonObject::ckStringOf(jResp,"build.logs.deepLink")
LogsGroupName.s = CkJsonObject::ckStringOf(jResp,"build.logs.groupName")
S3DeepLink.s = CkJsonObject::ckStringOf(jResp,"build.logs.s3DeepLink")
S3LogsBucketOwnerAccess.s = CkJsonObject::ckStringOf(jResp,"build.logs.s3Logs.bucketOwnerAccess")
S3LogsEncryptionDisabled.i = CkJsonObject::ckIntOf(jResp,"build.logs.s3Logs.encryptionDisabled")
S3LogsLocation.s = CkJsonObject::ckStringOf(jResp,"build.logs.s3Logs.location")
S3LogsStatus.s = CkJsonObject::ckStringOf(jResp,"build.logs.s3Logs.status")
S3LogsArn.s = CkJsonObject::ckStringOf(jResp,"build.logs.s3LogsArn")
LogsStreamName.s = CkJsonObject::ckStringOf(jResp,"build.logs.streamName")
NetworkInterfaceId.s = CkJsonObject::ckStringOf(jResp,"build.networkInterface.networkInterfaceId")
SubnetId.s = CkJsonObject::ckStringOf(jResp,"build.networkInterface.subnetId")
ProjectName.s = CkJsonObject::ckStringOf(jResp,"build.projectName")
QueuedTimeoutInMinutes.i = CkJsonObject::ckIntOf(jResp,"build.queuedTimeoutInMinutes")
ResolvedSourceVersion.s = CkJsonObject::ckStringOf(jResp,"build.resolvedSourceVersion")
ServiceRole.s = CkJsonObject::ckStringOf(jResp,"build.serviceRole")
Resource.s = CkJsonObject::ckStringOf(jResp,"build.source.auth.resource")
AuthType.s = CkJsonObject::ckStringOf(jResp,"build.source.auth.type")
Buildspec.s = CkJsonObject::ckStringOf(jResp,"build.source.buildspec")
Context.s = CkJsonObject::ckStringOf(jResp,"build.source.buildStatusConfig.context")
TargetUrl.s = CkJsonObject::ckStringOf(jResp,"build.source.buildStatusConfig.targetUrl")
GitCloneDepth.i = CkJsonObject::ckIntOf(jResp,"build.source.gitCloneDepth")
FetchSubmodules.i = CkJsonObject::ckIntOf(jResp,"build.source.gitSubmodulesConfig.fetchSubmodules")
InsecureSsl.i = CkJsonObject::ckIntOf(jResp,"build.source.insecureSsl")
SourceLocation.s = CkJsonObject::ckStringOf(jResp,"build.source.location")
ReportBuildStatus.i = CkJsonObject::ckIntOf(jResp,"build.source.reportBuildStatus")
SourceIdentifier.s = CkJsonObject::ckStringOf(jResp,"build.source.sourceIdentifier")
SourceType.s = CkJsonObject::ckStringOf(jResp,"build.source.type")
SourceVersion.s = CkJsonObject::ckStringOf(jResp,"build.sourceVersion")
StartTime.i = CkJsonObject::ckIntOf(jResp,"build.startTime")
TimeoutInMinutes.i = CkJsonObject::ckIntOf(jResp,"build.timeoutInMinutes")
VpcId.s = CkJsonObject::ckStringOf(jResp,"build.vpcConfig.vpcId")
i.i = 0
count_i.i = CkJsonObject::ckSizeOfArray(jResp,"build.cache.modes")
While i < count_i
CkJsonObject::setCkI(jResp, i)
strVal = CkJsonObject::ckStringOf(jResp,"build.cache.modes[i]")
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"build.environment.environmentVariables")
While i < count_i
CkJsonObject::setCkI(jResp, i)
name = CkJsonObject::ckStringOf(jResp,"build.environment.environmentVariables[i].name")
v_type = CkJsonObject::ckStringOf(jResp,"build.environment.environmentVariables[i].type")
value = CkJsonObject::ckStringOf(jResp,"build.environment.environmentVariables[i].value")
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"build.exportedEnvironmentVariables")
While i < count_i
CkJsonObject::setCkI(jResp, i)
name = CkJsonObject::ckStringOf(jResp,"build.exportedEnvironmentVariables[i].name")
value = CkJsonObject::ckStringOf(jResp,"build.exportedEnvironmentVariables[i].value")
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"build.fileSystemLocations")
While i < count_i
CkJsonObject::setCkI(jResp, i)
identifier = CkJsonObject::ckStringOf(jResp,"build.fileSystemLocations[i].identifier")
location = CkJsonObject::ckStringOf(jResp,"build.fileSystemLocations[i].location")
mountOptions = CkJsonObject::ckStringOf(jResp,"build.fileSystemLocations[i].mountOptions")
mountPoint = CkJsonObject::ckStringOf(jResp,"build.fileSystemLocations[i].mountPoint")
v_type = CkJsonObject::ckStringOf(jResp,"build.fileSystemLocations[i].type")
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"build.phases")
While i < count_i
CkJsonObject::setCkI(jResp, i)
durationInSeconds = CkJsonObject::ckIntOf(jResp,"build.phases[i].durationInSeconds")
endTime = CkJsonObject::ckIntOf(jResp,"build.phases[i].endTime")
phaseStatus = CkJsonObject::ckStringOf(jResp,"build.phases[i].phaseStatus")
phaseType = CkJsonObject::ckStringOf(jResp,"build.phases[i].phaseType")
startTime = CkJsonObject::ckIntOf(jResp,"build.phases[i].startTime")
j = 0
count_j = CkJsonObject::ckSizeOfArray(jResp,"build.phases[i].contexts")
While j < count_j
CkJsonObject::setCkJ(jResp, j)
message = CkJsonObject::ckStringOf(jResp,"build.phases[i].contexts[j].message")
statusCode = CkJsonObject::ckStringOf(jResp,"build.phases[i].contexts[j].statusCode")
j = j + 1
Wend
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"build.reportArns")
While i < count_i
CkJsonObject::setCkI(jResp, i)
strVal = CkJsonObject::ckStringOf(jResp,"build.reportArns[i]")
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"build.secondaryArtifacts")
While i < count_i
CkJsonObject::setCkI(jResp, i)
artifactIdentifier = CkJsonObject::ckStringOf(jResp,"build.secondaryArtifacts[i].artifactIdentifier")
bucketOwnerAccess = CkJsonObject::ckStringOf(jResp,"build.secondaryArtifacts[i].bucketOwnerAccess")
encryptionDisabled = CkJsonObject::ckIntOf(jResp,"build.secondaryArtifacts[i].encryptionDisabled")
location = CkJsonObject::ckStringOf(jResp,"build.secondaryArtifacts[i].location")
md5sum = CkJsonObject::ckStringOf(jResp,"build.secondaryArtifacts[i].md5sum")
overrideArtifactName = CkJsonObject::ckIntOf(jResp,"build.secondaryArtifacts[i].overrideArtifactName")
sha256sum = CkJsonObject::ckStringOf(jResp,"build.secondaryArtifacts[i].sha256sum")
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"build.secondarySources")
While i < count_i
CkJsonObject::setCkI(jResp, i)
authResource = CkJsonObject::ckStringOf(jResp,"build.secondarySources[i].auth.resource")
authType = CkJsonObject::ckStringOf(jResp,"build.secondarySources[i].auth.type")
buildspec = CkJsonObject::ckStringOf(jResp,"build.secondarySources[i].buildspec")
buildStatusConfigContext = CkJsonObject::ckStringOf(jResp,"build.secondarySources[i].buildStatusConfig.context")
buildStatusConfigTargetUrl = CkJsonObject::ckStringOf(jResp,"build.secondarySources[i].buildStatusConfig.targetUrl")
gitCloneDepth = CkJsonObject::ckIntOf(jResp,"build.secondarySources[i].gitCloneDepth")
gitSubmodulesConfigFetchSubmodules = CkJsonObject::ckIntOf(jResp,"build.secondarySources[i].gitSubmodulesConfig.fetchSubmodules")
insecureSsl = CkJsonObject::ckIntOf(jResp,"build.secondarySources[i].insecureSsl")
location = CkJsonObject::ckStringOf(jResp,"build.secondarySources[i].location")
reportBuildStatus = CkJsonObject::ckIntOf(jResp,"build.secondarySources[i].reportBuildStatus")
sourceIdentifier = CkJsonObject::ckStringOf(jResp,"build.secondarySources[i].sourceIdentifier")
v_type = CkJsonObject::ckStringOf(jResp,"build.secondarySources[i].type")
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"build.secondarySourceVersions")
While i < count_i
CkJsonObject::setCkI(jResp, i)
sourceIdentifier = CkJsonObject::ckStringOf(jResp,"build.secondarySourceVersions[i].sourceIdentifier")
sourceVersion = CkJsonObject::ckStringOf(jResp,"build.secondarySourceVersions[i].sourceVersion")
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"build.vpcConfig.securityGroupIds")
While i < count_i
CkJsonObject::setCkI(jResp, i)
strVal = CkJsonObject::ckStringOf(jResp,"build.vpcConfig.securityGroupIds[i]")
i = i + 1
Wend
i = 0
count_i = CkJsonObject::ckSizeOfArray(jResp,"build.vpcConfig.subnets")
While i < count_i
CkJsonObject::setCkI(jResp, i)
strVal = CkJsonObject::ckStringOf(jResp,"build.vpcConfig.subnets[i]")
i = i + 1
Wend
; 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::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jResp)
ProcedureReturn
EndProcedure