Chilkat Online Tools

BatchGetBuilds C++ Example

AWS CodeBuild

#include <CkRest.h>
#include <CkAuthAws.h>
#include <CkJsonObject.h>
#include <CkStringBuilder.h>

void ChilkatSample(void)
    {
    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkRest rest;
    bool success;

    CkAuthAws authAws;
    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) {
        std::cout << "ConnectFailReason: " << rest.get_ConnectFailReason() << "\r\n";
        std::cout << rest.lastErrorText() << "\r\n";
        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

    CkJsonObject json;
    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.BatchGetBuilds");

    CkStringBuilder sbRequestBody;
    json.EmitSb(sbRequestBody);
    CkStringBuilder sbResponseBody;
    success = rest.FullRequestSb("POST","/",sbRequestBody,sbResponseBody);
    if (success != true) {
        std::cout << rest.lastErrorText() << "\r\n";
        return;
    }

    int respStatusCode = rest.get_ResponseStatusCode();
    std::cout << "response status code = " << respStatusCode << "\r\n";
    if (respStatusCode != 200) {
        std::cout << "Response Header:" << "\r\n";
        std::cout << rest.responseHeader() << "\r\n";
        std::cout << "Response Body:" << "\r\n";
        std::cout << sbResponseBody.getAsString() << "\r\n";
        return;
    }

    CkJsonObject 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 char *arn = 0;
    const char *ArtifactIdentifier = 0;
    const char *BucketOwnerAccess = 0;
    int EncryptionDisabled;
    const char *Location = 0;
    const char *Md5sum = 0;
    int OverrideArtifactName;
    const char *Sha256sum = 0;
    const char *buildBatchArn = 0;
    int buildComplete;
    int buildNumber;
    const char *buildStatus = 0;
    const char *cacheLocation = 0;
    const char *v_Type = 0;
    const char *currentPhase = 0;
    int SessionEnabled;
    const char *SessionTarget = 0;
    const char *encryptionKey = 0;
    int endTime;
    const char *Certificate = 0;
    const char *ComputeType = 0;
    const char *Image = 0;
    const char *ImagePullCredentialsType = 0;
    int PrivilegedMode;
    const char *Credential = 0;
    const char *CredentialProvider = 0;
    const char *environmentType = 0;
    const char *id = 0;
    const char *initiator = 0;
    const char *GroupName = 0;
    const char *Status = 0;
    const char *StreamName = 0;
    const char *CloudWatchLogsArn = 0;
    const char *DeepLink = 0;
    const char *logsGroupName = 0;
    const char *S3DeepLink = 0;
    const char *S3LogsBucketOwnerAccess = 0;
    int S3LogsEncryptionDisabled;
    const char *S3LogsLocation = 0;
    const char *S3LogsStatus = 0;
    const char *S3LogsArn = 0;
    const char *logsStreamName = 0;
    const char *NetworkInterfaceId = 0;
    const char *SubnetId = 0;
    const char *projectName = 0;
    int queuedTimeoutInMinutes;
    const char *resolvedSourceVersion = 0;
    const char *serviceRole = 0;
    const char *Resource = 0;
    const char *AuthType = 0;
    const char *Buildspec = 0;
    const char *Context = 0;
    const char *TargetUrl = 0;
    int GitCloneDepth;
    int FetchSubmodules;
    int InsecureSsl;
    const char *sourceLocation = 0;
    int ReportBuildStatus;
    const char *SourceIdentifier = 0;
    const char *sourceType = 0;
    const char *sourceVersion = 0;
    int startTime;
    int timeoutInMinutes;
    const char *VpcId = 0;
    int j;
    int count_j;
    const char *strVal = 0;
    const char *name = 0;
    const char *v_type = 0;
    const char *value = 0;
    const char *identifier = 0;
    const char *location = 0;
    const char *mountOptions = 0;
    const char *mountPoint = 0;
    int durationInSeconds;
    const char *phaseStatus = 0;
    const char *phaseType = 0;
    int k;
    int count_k;
    const char *message = 0;
    const char *statusCode = 0;
    const char *artifactIdentifier = 0;
    const char *bucketOwnerAccess = 0;
    int encryptionDisabled;
    const char *md5sum = 0;
    int overrideArtifactName;
    const char *sha256sum = 0;
    const char *authResource = 0;
    const char *authType = 0;
    const char *buildspec = 0;
    const char *buildStatusConfigContext = 0;
    const char *buildStatusConfigTargetUrl = 0;
    int gitCloneDepth;
    int gitSubmodulesConfigFetchSubmodules;
    int insecureSsl;
    int reportBuildStatus;
    const char *sourceIdentifier = 0;

    int i = 0;
    int count_i = jResp.SizeOfArray("builds");
    while (i < count_i) {
        jResp.put_I(i);
        arn = jResp.stringOf("builds[i].arn");
        ArtifactIdentifier = jResp.stringOf("builds[i].artifacts.artifactIdentifier");
        BucketOwnerAccess = jResp.stringOf("builds[i].artifacts.bucketOwnerAccess");
        EncryptionDisabled = jResp.IntOf("builds[i].artifacts.encryptionDisabled");
        Location = jResp.stringOf("builds[i].artifacts.location");
        Md5sum = jResp.stringOf("builds[i].artifacts.md5sum");
        OverrideArtifactName = jResp.IntOf("builds[i].artifacts.overrideArtifactName");
        Sha256sum = jResp.stringOf("builds[i].artifacts.sha256sum");
        buildBatchArn = jResp.stringOf("builds[i].buildBatchArn");
        buildComplete = jResp.IntOf("builds[i].buildComplete");
        buildNumber = jResp.IntOf("builds[i].buildNumber");
        buildStatus = jResp.stringOf("builds[i].buildStatus");
        cacheLocation = jResp.stringOf("builds[i].cache.location");
        v_Type = jResp.stringOf("builds[i].cache.type");
        currentPhase = jResp.stringOf("builds[i].currentPhase");
        SessionEnabled = jResp.IntOf("builds[i].debugSession.sessionEnabled");
        SessionTarget = jResp.stringOf("builds[i].debugSession.sessionTarget");
        encryptionKey = jResp.stringOf("builds[i].encryptionKey");
        endTime = jResp.IntOf("builds[i].endTime");
        Certificate = jResp.stringOf("builds[i].environment.certificate");
        ComputeType = jResp.stringOf("builds[i].environment.computeType");
        Image = jResp.stringOf("builds[i].environment.image");
        ImagePullCredentialsType = jResp.stringOf("builds[i].environment.imagePullCredentialsType");
        PrivilegedMode = jResp.IntOf("builds[i].environment.privilegedMode");
        Credential = jResp.stringOf("builds[i].environment.registryCredential.credential");
        CredentialProvider = jResp.stringOf("builds[i].environment.registryCredential.credentialProvider");
        environmentType = jResp.stringOf("builds[i].environment.type");
        id = jResp.stringOf("builds[i].id");
        initiator = jResp.stringOf("builds[i].initiator");
        GroupName = jResp.stringOf("builds[i].logs.cloudWatchLogs.groupName");
        Status = jResp.stringOf("builds[i].logs.cloudWatchLogs.status");
        StreamName = jResp.stringOf("builds[i].logs.cloudWatchLogs.streamName");
        CloudWatchLogsArn = jResp.stringOf("builds[i].logs.cloudWatchLogsArn");
        DeepLink = jResp.stringOf("builds[i].logs.deepLink");
        logsGroupName = jResp.stringOf("builds[i].logs.groupName");
        S3DeepLink = jResp.stringOf("builds[i].logs.s3DeepLink");
        S3LogsBucketOwnerAccess = jResp.stringOf("builds[i].logs.s3Logs.bucketOwnerAccess");
        S3LogsEncryptionDisabled = jResp.IntOf("builds[i].logs.s3Logs.encryptionDisabled");
        S3LogsLocation = jResp.stringOf("builds[i].logs.s3Logs.location");
        S3LogsStatus = jResp.stringOf("builds[i].logs.s3Logs.status");
        S3LogsArn = jResp.stringOf("builds[i].logs.s3LogsArn");
        logsStreamName = jResp.stringOf("builds[i].logs.streamName");
        NetworkInterfaceId = jResp.stringOf("builds[i].networkInterface.networkInterfaceId");
        SubnetId = jResp.stringOf("builds[i].networkInterface.subnetId");
        projectName = jResp.stringOf("builds[i].projectName");
        queuedTimeoutInMinutes = jResp.IntOf("builds[i].queuedTimeoutInMinutes");
        resolvedSourceVersion = jResp.stringOf("builds[i].resolvedSourceVersion");
        serviceRole = jResp.stringOf("builds[i].serviceRole");
        Resource = jResp.stringOf("builds[i].source.auth.resource");
        AuthType = jResp.stringOf("builds[i].source.auth.type");
        Buildspec = jResp.stringOf("builds[i].source.buildspec");
        Context = jResp.stringOf("builds[i].source.buildStatusConfig.context");
        TargetUrl = jResp.stringOf("builds[i].source.buildStatusConfig.targetUrl");
        GitCloneDepth = jResp.IntOf("builds[i].source.gitCloneDepth");
        FetchSubmodules = jResp.IntOf("builds[i].source.gitSubmodulesConfig.fetchSubmodules");
        InsecureSsl = jResp.IntOf("builds[i].source.insecureSsl");
        sourceLocation = jResp.stringOf("builds[i].source.location");
        ReportBuildStatus = jResp.IntOf("builds[i].source.reportBuildStatus");
        SourceIdentifier = jResp.stringOf("builds[i].source.sourceIdentifier");
        sourceType = jResp.stringOf("builds[i].source.type");
        sourceVersion = jResp.stringOf("builds[i].sourceVersion");
        startTime = jResp.IntOf("builds[i].startTime");
        timeoutInMinutes = jResp.IntOf("builds[i].timeoutInMinutes");
        VpcId = jResp.stringOf("builds[i].vpcConfig.vpcId");
        j = 0;
        count_j = jResp.SizeOfArray("builds[i].cache.modes");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf("builds[i].cache.modes[j]");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray("builds[i].environment.environmentVariables");
        while (j < count_j) {
            jResp.put_J(j);
            name = jResp.stringOf("builds[i].environment.environmentVariables[j].name");
            v_type = jResp.stringOf("builds[i].environment.environmentVariables[j].type");
            value = jResp.stringOf("builds[i].environment.environmentVariables[j].value");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray("builds[i].exportedEnvironmentVariables");
        while (j < count_j) {
            jResp.put_J(j);
            name = jResp.stringOf("builds[i].exportedEnvironmentVariables[j].name");
            value = jResp.stringOf("builds[i].exportedEnvironmentVariables[j].value");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray("builds[i].fileSystemLocations");
        while (j < count_j) {
            jResp.put_J(j);
            identifier = jResp.stringOf("builds[i].fileSystemLocations[j].identifier");
            location = jResp.stringOf("builds[i].fileSystemLocations[j].location");
            mountOptions = jResp.stringOf("builds[i].fileSystemLocations[j].mountOptions");
            mountPoint = jResp.stringOf("builds[i].fileSystemLocations[j].mountPoint");
            v_type = jResp.stringOf("builds[i].fileSystemLocations[j].type");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray("builds[i].phases");
        while (j < count_j) {
            jResp.put_J(j);
            durationInSeconds = jResp.IntOf("builds[i].phases[j].durationInSeconds");
            endTime = jResp.IntOf("builds[i].phases[j].endTime");
            phaseStatus = jResp.stringOf("builds[i].phases[j].phaseStatus");
            phaseType = jResp.stringOf("builds[i].phases[j].phaseType");
            startTime = jResp.IntOf("builds[i].phases[j].startTime");
            k = 0;
            count_k = jResp.SizeOfArray("builds[i].phases[j].contexts");
            while (k < count_k) {
                jResp.put_K(k);
                message = jResp.stringOf("builds[i].phases[j].contexts[k].message");
                statusCode = jResp.stringOf("builds[i].phases[j].contexts[k].statusCode");
                k = k + 1;
            }

            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray("builds[i].reportArns");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf("builds[i].reportArns[j]");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray("builds[i].secondaryArtifacts");
        while (j < count_j) {
            jResp.put_J(j);
            artifactIdentifier = jResp.stringOf("builds[i].secondaryArtifacts[j].artifactIdentifier");
            bucketOwnerAccess = jResp.stringOf("builds[i].secondaryArtifacts[j].bucketOwnerAccess");
            encryptionDisabled = jResp.IntOf("builds[i].secondaryArtifacts[j].encryptionDisabled");
            location = jResp.stringOf("builds[i].secondaryArtifacts[j].location");
            md5sum = jResp.stringOf("builds[i].secondaryArtifacts[j].md5sum");
            overrideArtifactName = jResp.IntOf("builds[i].secondaryArtifacts[j].overrideArtifactName");
            sha256sum = jResp.stringOf("builds[i].secondaryArtifacts[j].sha256sum");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray("builds[i].secondarySources");
        while (j < count_j) {
            jResp.put_J(j);
            authResource = jResp.stringOf("builds[i].secondarySources[j].auth.resource");
            authType = jResp.stringOf("builds[i].secondarySources[j].auth.type");
            buildspec = jResp.stringOf("builds[i].secondarySources[j].buildspec");
            buildStatusConfigContext = jResp.stringOf("builds[i].secondarySources[j].buildStatusConfig.context");
            buildStatusConfigTargetUrl = jResp.stringOf("builds[i].secondarySources[j].buildStatusConfig.targetUrl");
            gitCloneDepth = jResp.IntOf("builds[i].secondarySources[j].gitCloneDepth");
            gitSubmodulesConfigFetchSubmodules = jResp.IntOf("builds[i].secondarySources[j].gitSubmodulesConfig.fetchSubmodules");
            insecureSsl = jResp.IntOf("builds[i].secondarySources[j].insecureSsl");
            location = jResp.stringOf("builds[i].secondarySources[j].location");
            reportBuildStatus = jResp.IntOf("builds[i].secondarySources[j].reportBuildStatus");
            sourceIdentifier = jResp.stringOf("builds[i].secondarySources[j].sourceIdentifier");
            v_type = jResp.stringOf("builds[i].secondarySources[j].type");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray("builds[i].secondarySourceVersions");
        while (j < count_j) {
            jResp.put_J(j);
            sourceIdentifier = jResp.stringOf("builds[i].secondarySourceVersions[j].sourceIdentifier");
            sourceVersion = jResp.stringOf("builds[i].secondarySourceVersions[j].sourceVersion");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray("builds[i].vpcConfig.securityGroupIds");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf("builds[i].vpcConfig.securityGroupIds[j]");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray("builds[i].vpcConfig.subnets");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf("builds[i].vpcConfig.subnets[j]");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray("buildsNotFound");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("buildsNotFound[i]");
        i = i + 1;
    }

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

    // {
    //   "builds": [
    //     {
    //       "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"
    //       }
    //     }
    //   ],
    //   "buildsNotFound": [
    //     "string"
    //   ]
    // }
    }