Chilkat Online Tools

BatchGetBuildBatches Ruby Example

AWS CodeBuild

require 'chilkat'

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

rest = Chilkat::CkRest.new()

authAws = Chilkat::CkAuthAws.new()
authAws.put_AccessKey("AWS_ACCESS_KEY")
authAws.put_SecretKey("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("us-west-2")
authAws.put_ServiceName("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("codebuild.us-west-2.amazonaws.com",443,true,true)
if (success != true)
    print "ConnectFailReason: " + rest.get_ConnectFailReason().to_s() + "\n";
    print rest.lastErrorText() + "\n";
    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 = Chilkat::CkJsonObject.new()
json.UpdateString("ids[0]","string")

# The JSON request body created by the above code:

# {
#   "ids": [
#     "string"
#   ]
# }

rest.AddHeader("Content-Type","application/x-amz-json-1.1")
rest.AddHeader("X-Amz-Target","CodeBuild_20161006.BatchGetBuildBatches")

sbRequestBody = Chilkat::CkStringBuilder.new()
json.EmitSb(sbRequestBody)
sbResponseBody = Chilkat::CkStringBuilder.new()
success = rest.FullRequestSb("POST","/",sbRequestBody,sbResponseBody)
if (success != true)
    print rest.lastErrorText() + "\n";
    exit
end

respStatusCode = rest.get_ResponseStatusCode()
print "response status code = " + respStatusCode.to_s() + "\n";
if (respStatusCode != 200)
    print "Response Header:" + "\n";
    print rest.responseHeader() + "\n";
    print "Response Body:" + "\n";
    print sbResponseBody.getAsString() + "\n";
    exit
end

jResp = Chilkat::CkJsonObject.new()
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

i = 0
count_i = jResp.SizeOfArray("buildBatches")
while i < count_i
    jResp.put_I(i)
    arn = jResp.stringOf("buildBatches[i].arn")
    ArtifactIdentifier = jResp.stringOf("buildBatches[i].artifacts.artifactIdentifier")
    BucketOwnerAccess = jResp.stringOf("buildBatches[i].artifacts.bucketOwnerAccess")
    EncryptionDisabled = jResp.IntOf("buildBatches[i].artifacts.encryptionDisabled")
    Location = jResp.stringOf("buildBatches[i].artifacts.location")
    Md5sum = jResp.stringOf("buildBatches[i].artifacts.md5sum")
    OverrideArtifactName = jResp.IntOf("buildBatches[i].artifacts.overrideArtifactName")
    Sha256sum = jResp.stringOf("buildBatches[i].artifacts.sha256sum")
    BatchReportMode = jResp.stringOf("buildBatches[i].buildBatchConfig.batchReportMode")
    CombineArtifacts = jResp.IntOf("buildBatches[i].buildBatchConfig.combineArtifacts")
    MaximumBuildsAllowed = jResp.IntOf("buildBatches[i].buildBatchConfig.restrictions.maximumBuildsAllowed")
    ServiceRole = jResp.stringOf("buildBatches[i].buildBatchConfig.serviceRole")
    TimeoutInMins = jResp.IntOf("buildBatches[i].buildBatchConfig.timeoutInMins")
    buildBatchNumber = jResp.IntOf("buildBatches[i].buildBatchNumber")
    buildBatchStatus = jResp.stringOf("buildBatches[i].buildBatchStatus")
    buildTimeoutInMinutes = jResp.IntOf("buildBatches[i].buildTimeoutInMinutes")
    cacheLocation = jResp.stringOf("buildBatches[i].cache.location")
    v_Type = jResp.stringOf("buildBatches[i].cache.type")
    complete = jResp.IntOf("buildBatches[i].complete")
    currentPhase = jResp.stringOf("buildBatches[i].currentPhase")
    debugSessionEnabled = jResp.IntOf("buildBatches[i].debugSessionEnabled")
    encryptionKey = jResp.stringOf("buildBatches[i].encryptionKey")
    endTime = jResp.IntOf("buildBatches[i].endTime")
    Certificate = jResp.stringOf("buildBatches[i].environment.certificate")
    ComputeType = jResp.stringOf("buildBatches[i].environment.computeType")
    Image = jResp.stringOf("buildBatches[i].environment.image")
    ImagePullCredentialsType = jResp.stringOf("buildBatches[i].environment.imagePullCredentialsType")
    PrivilegedMode = jResp.IntOf("buildBatches[i].environment.privilegedMode")
    Credential = jResp.stringOf("buildBatches[i].environment.registryCredential.credential")
    CredentialProvider = jResp.stringOf("buildBatches[i].environment.registryCredential.credentialProvider")
    environmentType = jResp.stringOf("buildBatches[i].environment.type")
    id = jResp.stringOf("buildBatches[i].id")
    initiator = jResp.stringOf("buildBatches[i].initiator")
    GroupName = jResp.stringOf("buildBatches[i].logConfig.cloudWatchLogs.groupName")
    Status = jResp.stringOf("buildBatches[i].logConfig.cloudWatchLogs.status")
    StreamName = jResp.stringOf("buildBatches[i].logConfig.cloudWatchLogs.streamName")
    S3LogsBucketOwnerAccess = jResp.stringOf("buildBatches[i].logConfig.s3Logs.bucketOwnerAccess")
    S3LogsEncryptionDisabled = jResp.IntOf("buildBatches[i].logConfig.s3Logs.encryptionDisabled")
    S3LogsLocation = jResp.stringOf("buildBatches[i].logConfig.s3Logs.location")
    S3LogsStatus = jResp.stringOf("buildBatches[i].logConfig.s3Logs.status")
    projectName = jResp.stringOf("buildBatches[i].projectName")
    queuedTimeoutInMinutes = jResp.IntOf("buildBatches[i].queuedTimeoutInMinutes")
    resolvedSourceVersion = jResp.stringOf("buildBatches[i].resolvedSourceVersion")
    serviceRole = jResp.stringOf("buildBatches[i].serviceRole")
    Resource = jResp.stringOf("buildBatches[i].source.auth.resource")
    AuthType = jResp.stringOf("buildBatches[i].source.auth.type")
    Buildspec = jResp.stringOf("buildBatches[i].source.buildspec")
    Context = jResp.stringOf("buildBatches[i].source.buildStatusConfig.context")
    TargetUrl = jResp.stringOf("buildBatches[i].source.buildStatusConfig.targetUrl")
    GitCloneDepth = jResp.IntOf("buildBatches[i].source.gitCloneDepth")
    FetchSubmodules = jResp.IntOf("buildBatches[i].source.gitSubmodulesConfig.fetchSubmodules")
    InsecureSsl = jResp.IntOf("buildBatches[i].source.insecureSsl")
    sourceLocation = jResp.stringOf("buildBatches[i].source.location")
    ReportBuildStatus = jResp.IntOf("buildBatches[i].source.reportBuildStatus")
    SourceIdentifier = jResp.stringOf("buildBatches[i].source.sourceIdentifier")
    sourceType = jResp.stringOf("buildBatches[i].source.type")
    sourceVersion = jResp.stringOf("buildBatches[i].sourceVersion")
    startTime = jResp.IntOf("buildBatches[i].startTime")
    VpcId = jResp.stringOf("buildBatches[i].vpcConfig.vpcId")
    j = 0
    count_j = jResp.SizeOfArray("buildBatches[i].buildBatchConfig.restrictions.computeTypesAllowed")
    while j < count_j
        jResp.put_J(j)
        strVal = jResp.stringOf("buildBatches[i].buildBatchConfig.restrictions.computeTypesAllowed[j]")
        j = j + 1
    end
    j = 0
    count_j = jResp.SizeOfArray("buildBatches[i].buildGroups")
    while j < count_j
        jResp.put_J(j)
        Arn = jResp.stringOf("buildBatches[i].buildGroups[j].currentBuildSummary.arn")
        BuildStatus = jResp.stringOf("buildBatches[i].buildGroups[j].currentBuildSummary.buildStatus")
        Identifier = jResp.stringOf("buildBatches[i].buildGroups[j].currentBuildSummary.primaryArtifact.identifier")
        PrimaryArtifactLocation = jResp.stringOf("buildBatches[i].buildGroups[j].currentBuildSummary.primaryArtifact.location")
        PrimaryArtifactType = jResp.stringOf("buildBatches[i].buildGroups[j].currentBuildSummary.primaryArtifact.type")
        RequestedOn = jResp.IntOf("buildBatches[i].buildGroups[j].currentBuildSummary.requestedOn")
        identifier = jResp.stringOf("buildBatches[i].buildGroups[j].identifier")
        ignoreFailure = jResp.IntOf("buildBatches[i].buildGroups[j].ignoreFailure")
        k = 0
        count_k = jResp.SizeOfArray("buildBatches[i].buildGroups[j].currentBuildSummary.secondaryArtifacts")
        while k < count_k
            jResp.put_K(k)
            identifier = jResp.stringOf("buildBatches[i].buildGroups[j].currentBuildSummary.secondaryArtifacts[k].identifier")
            location = jResp.stringOf("buildBatches[i].buildGroups[j].currentBuildSummary.secondaryArtifacts[k].location")
            v_type = jResp.stringOf("buildBatches[i].buildGroups[j].currentBuildSummary.secondaryArtifacts[k].type")
            k = k + 1
        end
        k = 0
        count_k = jResp.SizeOfArray("buildBatches[i].buildGroups[j].dependsOn")
        while k < count_k
            jResp.put_K(k)
            strVal = jResp.stringOf("buildBatches[i].buildGroups[j].dependsOn[k]")
            k = k + 1
        end
        k = 0
        count_k = jResp.SizeOfArray("buildBatches[i].buildGroups[j].priorBuildSummaryList")
        while k < count_k
            jResp.put_K(k)
            arn = jResp.stringOf("buildBatches[i].buildGroups[j].priorBuildSummaryList[k].arn")
            buildStatus = jResp.stringOf("buildBatches[i].buildGroups[j].priorBuildSummaryList[k].buildStatus")
            primaryArtifactIdentifier = jResp.stringOf("buildBatches[i].buildGroups[j].priorBuildSummaryList[k].primaryArtifact.identifier")
            primaryArtifactLocation = jResp.stringOf("buildBatches[i].buildGroups[j].priorBuildSummaryList[k].primaryArtifact.location")
            primaryArtifactType = jResp.stringOf("buildBatches[i].buildGroups[j].priorBuildSummaryList[k].primaryArtifact.type")
            requestedOn = jResp.IntOf("buildBatches[i].buildGroups[j].priorBuildSummaryList[k].requestedOn")

            # json1 is a CkJsonObject
            json1 = jResp.ObjectOf("buildBatches[i].buildGroups[j].priorBuildSummaryList[k]")
            i1 = 0
            count_i1 = json1.SizeOfArray("secondaryArtifacts")
            while i1 < count_i1
                json1.put_I(i1)
                identifier = json1.stringOf("secondaryArtifacts[i].identifier")
                location = json1.stringOf("secondaryArtifacts[i].location")
                v_type = json1.stringOf("secondaryArtifacts[i].type")
                i1 = i1 + 1
            end

            k = k + 1
        end
        j = j + 1
    end
    j = 0
    count_j = jResp.SizeOfArray("buildBatches[i].cache.modes")
    while j < count_j
        jResp.put_J(j)
        strVal = jResp.stringOf("buildBatches[i].cache.modes[j]")
        j = j + 1
    end
    j = 0
    count_j = jResp.SizeOfArray("buildBatches[i].environment.environmentVariables")
    while j < count_j
        jResp.put_J(j)
        name = jResp.stringOf("buildBatches[i].environment.environmentVariables[j].name")
        v_type = jResp.stringOf("buildBatches[i].environment.environmentVariables[j].type")
        value = jResp.stringOf("buildBatches[i].environment.environmentVariables[j].value")
        j = j + 1
    end
    j = 0
    count_j = jResp.SizeOfArray("buildBatches[i].fileSystemLocations")
    while j < count_j
        jResp.put_J(j)
        identifier = jResp.stringOf("buildBatches[i].fileSystemLocations[j].identifier")
        location = jResp.stringOf("buildBatches[i].fileSystemLocations[j].location")
        mountOptions = jResp.stringOf("buildBatches[i].fileSystemLocations[j].mountOptions")
        mountPoint = jResp.stringOf("buildBatches[i].fileSystemLocations[j].mountPoint")
        v_type = jResp.stringOf("buildBatches[i].fileSystemLocations[j].type")
        j = j + 1
    end
    j = 0
    count_j = jResp.SizeOfArray("buildBatches[i].phases")
    while j < count_j
        jResp.put_J(j)
        durationInSeconds = jResp.IntOf("buildBatches[i].phases[j].durationInSeconds")
        endTime = jResp.IntOf("buildBatches[i].phases[j].endTime")
        phaseStatus = jResp.stringOf("buildBatches[i].phases[j].phaseStatus")
        phaseType = jResp.stringOf("buildBatches[i].phases[j].phaseType")
        startTime = jResp.IntOf("buildBatches[i].phases[j].startTime")
        k = 0
        count_k = jResp.SizeOfArray("buildBatches[i].phases[j].contexts")
        while k < count_k
            jResp.put_K(k)
            message = jResp.stringOf("buildBatches[i].phases[j].contexts[k].message")
            statusCode = jResp.stringOf("buildBatches[i].phases[j].contexts[k].statusCode")
            k = k + 1
        end
        j = j + 1
    end
    j = 0
    count_j = jResp.SizeOfArray("buildBatches[i].secondaryArtifacts")
    while j < count_j
        jResp.put_J(j)
        artifactIdentifier = jResp.stringOf("buildBatches[i].secondaryArtifacts[j].artifactIdentifier")
        bucketOwnerAccess = jResp.stringOf("buildBatches[i].secondaryArtifacts[j].bucketOwnerAccess")
        encryptionDisabled = jResp.IntOf("buildBatches[i].secondaryArtifacts[j].encryptionDisabled")
        location = jResp.stringOf("buildBatches[i].secondaryArtifacts[j].location")
        md5sum = jResp.stringOf("buildBatches[i].secondaryArtifacts[j].md5sum")
        overrideArtifactName = jResp.IntOf("buildBatches[i].secondaryArtifacts[j].overrideArtifactName")
        sha256sum = jResp.stringOf("buildBatches[i].secondaryArtifacts[j].sha256sum")
        j = j + 1
    end
    j = 0
    count_j = jResp.SizeOfArray("buildBatches[i].secondarySources")
    while j < count_j
        jResp.put_J(j)
        authResource = jResp.stringOf("buildBatches[i].secondarySources[j].auth.resource")
        authType = jResp.stringOf("buildBatches[i].secondarySources[j].auth.type")
        buildspec = jResp.stringOf("buildBatches[i].secondarySources[j].buildspec")
        buildStatusConfigContext = jResp.stringOf("buildBatches[i].secondarySources[j].buildStatusConfig.context")
        buildStatusConfigTargetUrl = jResp.stringOf("buildBatches[i].secondarySources[j].buildStatusConfig.targetUrl")
        gitCloneDepth = jResp.IntOf("buildBatches[i].secondarySources[j].gitCloneDepth")
        gitSubmodulesConfigFetchSubmodules = jResp.IntOf("buildBatches[i].secondarySources[j].gitSubmodulesConfig.fetchSubmodules")
        insecureSsl = jResp.IntOf("buildBatches[i].secondarySources[j].insecureSsl")
        location = jResp.stringOf("buildBatches[i].secondarySources[j].location")
        reportBuildStatus = jResp.IntOf("buildBatches[i].secondarySources[j].reportBuildStatus")
        sourceIdentifier = jResp.stringOf("buildBatches[i].secondarySources[j].sourceIdentifier")
        v_type = jResp.stringOf("buildBatches[i].secondarySources[j].type")
        j = j + 1
    end
    j = 0
    count_j = jResp.SizeOfArray("buildBatches[i].secondarySourceVersions")
    while j < count_j
        jResp.put_J(j)
        sourceIdentifier = jResp.stringOf("buildBatches[i].secondarySourceVersions[j].sourceIdentifier")
        sourceVersion = jResp.stringOf("buildBatches[i].secondarySourceVersions[j].sourceVersion")
        j = j + 1
    end
    j = 0
    count_j = jResp.SizeOfArray("buildBatches[i].vpcConfig.securityGroupIds")
    while j < count_j
        jResp.put_J(j)
        strVal = jResp.stringOf("buildBatches[i].vpcConfig.securityGroupIds[j]")
        j = j + 1
    end
    j = 0
    count_j = jResp.SizeOfArray("buildBatches[i].vpcConfig.subnets")
    while j < count_j
        jResp.put_J(j)
        strVal = jResp.stringOf("buildBatches[i].vpcConfig.subnets[j]")
        j = j + 1
    end
    i = i + 1
end
i = 0
count_i = jResp.SizeOfArray("buildBatchesNotFound")
while i < count_i
    jResp.put_I(i)
    strVal = jResp.stringOf("buildBatchesNotFound[i]")
    i = i + 1
end

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

# {
#   "buildBatches": [
#     {
#       "arn": "string",
#       "artifacts": {
#         "artifactIdentifier": "string",
#         "bucketOwnerAccess": "string",
#         "encryptionDisabled": boolean,
#         "location": "string",
#         "md5sum": "string",
#         "overrideArtifactName": boolean,
#         "sha256sum": "string"
#       },
#       "buildBatchConfig": {
#         "batchReportMode": "string",
#         "combineArtifacts": boolean,
#         "restrictions": {
#           "computeTypesAllowed": [
#             "string"
#           ],
#           "maximumBuildsAllowed": number
#         },
#         "serviceRole": "string",
#         "timeoutInMins": number
#       },
#       "buildBatchNumber": number,
#       "buildBatchStatus": "string",
#       "buildGroups": [
#         {
#           "currentBuildSummary": {
#             "arn": "string",
#             "buildStatus": "string",
#             "primaryArtifact": {
#               "identifier": "string",
#               "location": "string",
#               "type": "string"
#             },
#             "requestedOn": number,
#             "secondaryArtifacts": [
#               {
#                 "identifier": "string",
#                 "location": "string",
#                 "type": "string"
#               }
#             ]
#           },
#           "dependsOn": [
#             "string"
#           ],
#           "identifier": "string",
#           "ignoreFailure": boolean,
#           "priorBuildSummaryList": [
#             {
#               "arn": "string",
#               "buildStatus": "string",
#               "primaryArtifact": {
#                 "identifier": "string",
#                 "location": "string",
#                 "type": "string"
#               },
#               "requestedOn": number,
#               "secondaryArtifacts": [
#                 {
#                   "identifier": "string",
#                   "location": "string",
#                   "type": "string"
#                 }
#               ]
#             }
#           ]
#         }
#       ],
#       "buildTimeoutInMinutes": number,
#       "cache": {
#         "location": "string",
#         "modes": [
#           "string"
#         ],
#         "type": "string"
#       },
#       "complete": boolean,
#       "currentPhase": "string",
#       "debugSessionEnabled": boolean,
#       "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"
#       },
#       "fileSystemLocations": [
#         {
#           "identifier": "string",
#           "location": "string",
#           "mountOptions": "string",
#           "mountPoint": "string",
#           "type": "string"
#         }
#       ],
#       "id": "string",
#       "initiator": "string",
#       "logConfig": {
#         "cloudWatchLogs": {
#           "groupName": "string",
#           "status": "string",
#           "streamName": "string"
#         },
#         "s3Logs": {
#           "bucketOwnerAccess": "string",
#           "encryptionDisabled": boolean,
#           "location": "string",
#           "status": "string"
#         }
#       },
#       "phases": [
#         {
#           "contexts": [
#             {
#               "message": "string",
#               "statusCode": "string"
#             }
#           ],
#           "durationInSeconds": number,
#           "endTime": number,
#           "phaseStatus": "string",
#           "phaseType": "string",
#           "startTime": number
#         }
#       ],
#       "projectName": "string",
#       "queuedTimeoutInMinutes": number,
#       "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,
#       "vpcConfig": {
#         "securityGroupIds": [
#           "string"
#         ],
#         "subnets": [
#           "string"
#         ],
#         "vpcId": "string"
#       }
#     }
#   ],
#   "buildBatchesNotFound": [
#     "string"
#   ]
# }