Chilkat Online Tools

BatchGetProjects 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("names[0]","string");

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

    // {
    //   "names": [
    //     "string"
    //   ]
    // }

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

    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 *Name = 0;
    const char *NamespaceType = 0;
    int OverrideArtifactName;
    const char *Packaging = 0;
    const char *Path = 0;
    const char *v_Type = 0;
    int BadgeEnabled;
    const char *BadgeRequestUrl = 0;
    const char *BatchReportMode = 0;
    int CombineArtifacts;
    int MaximumBuildsAllowed;
    const char *ServiceRole = 0;
    int TimeoutInMins;
    const char *cacheLocation = 0;
    const char *cacheType = 0;
    int concurrentBuildLimit;
    int created;
    const char *description = 0;
    const char *encryptionKey = 0;
    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;
    int lastModified;
    const char *GroupName = 0;
    const char *Status = 0;
    const char *StreamName = 0;
    const char *S3LogsBucketOwnerAccess = 0;
    int S3LogsEncryptionDisabled;
    const char *S3LogsLocation = 0;
    const char *S3LogsStatus = 0;
    const char *name = 0;
    const char *projectVisibility = 0;
    const char *publicProjectAlias = 0;
    int queuedTimeoutInMinutes;
    const char *resourceAccessRole = 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 timeoutInMinutes;
    const char *VpcId = 0;
    const char *BranchFilter = 0;
    const char *BuildType = 0;
    int LastModifiedSecret;
    const char *PayloadUrl = 0;
    const char *Secret = 0;
    const char *v_Url = 0;
    int j;
    int count_j;
    const char *strVal = 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;
    const char *artifactIdentifier = 0;
    const char *bucketOwnerAccess = 0;
    int encryptionDisabled;
    const char *namespaceType = 0;
    int overrideArtifactName;
    const char *packaging = 0;
    const char *path = 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;
    const char *key = 0;
    int k;
    int count_k;
    int excludeMatchedPattern;
    const char *pattern = 0;

    int i = 0;
    int count_i = jResp.SizeOfArray("projects");
    while (i < count_i) {
        jResp.put_I(i);
        arn = jResp.stringOf("projects[i].arn");
        ArtifactIdentifier = jResp.stringOf("projects[i].artifacts.artifactIdentifier");
        BucketOwnerAccess = jResp.stringOf("projects[i].artifacts.bucketOwnerAccess");
        EncryptionDisabled = jResp.IntOf("projects[i].artifacts.encryptionDisabled");
        Location = jResp.stringOf("projects[i].artifacts.location");
        Name = jResp.stringOf("projects[i].artifacts.name");
        NamespaceType = jResp.stringOf("projects[i].artifacts.namespaceType");
        OverrideArtifactName = jResp.IntOf("projects[i].artifacts.overrideArtifactName");
        Packaging = jResp.stringOf("projects[i].artifacts.packaging");
        Path = jResp.stringOf("projects[i].artifacts.path");
        v_Type = jResp.stringOf("projects[i].artifacts.type");
        BadgeEnabled = jResp.IntOf("projects[i].badge.badgeEnabled");
        BadgeRequestUrl = jResp.stringOf("projects[i].badge.badgeRequestUrl");
        BatchReportMode = jResp.stringOf("projects[i].buildBatchConfig.batchReportMode");
        CombineArtifacts = jResp.IntOf("projects[i].buildBatchConfig.combineArtifacts");
        MaximumBuildsAllowed = jResp.IntOf("projects[i].buildBatchConfig.restrictions.maximumBuildsAllowed");
        ServiceRole = jResp.stringOf("projects[i].buildBatchConfig.serviceRole");
        TimeoutInMins = jResp.IntOf("projects[i].buildBatchConfig.timeoutInMins");
        cacheLocation = jResp.stringOf("projects[i].cache.location");
        cacheType = jResp.stringOf("projects[i].cache.type");
        concurrentBuildLimit = jResp.IntOf("projects[i].concurrentBuildLimit");
        created = jResp.IntOf("projects[i].created");
        description = jResp.stringOf("projects[i].description");
        encryptionKey = jResp.stringOf("projects[i].encryptionKey");
        Certificate = jResp.stringOf("projects[i].environment.certificate");
        ComputeType = jResp.stringOf("projects[i].environment.computeType");
        Image = jResp.stringOf("projects[i].environment.image");
        ImagePullCredentialsType = jResp.stringOf("projects[i].environment.imagePullCredentialsType");
        PrivilegedMode = jResp.IntOf("projects[i].environment.privilegedMode");
        Credential = jResp.stringOf("projects[i].environment.registryCredential.credential");
        CredentialProvider = jResp.stringOf("projects[i].environment.registryCredential.credentialProvider");
        environmentType = jResp.stringOf("projects[i].environment.type");
        lastModified = jResp.IntOf("projects[i].lastModified");
        GroupName = jResp.stringOf("projects[i].logsConfig.cloudWatchLogs.groupName");
        Status = jResp.stringOf("projects[i].logsConfig.cloudWatchLogs.status");
        StreamName = jResp.stringOf("projects[i].logsConfig.cloudWatchLogs.streamName");
        S3LogsBucketOwnerAccess = jResp.stringOf("projects[i].logsConfig.s3Logs.bucketOwnerAccess");
        S3LogsEncryptionDisabled = jResp.IntOf("projects[i].logsConfig.s3Logs.encryptionDisabled");
        S3LogsLocation = jResp.stringOf("projects[i].logsConfig.s3Logs.location");
        S3LogsStatus = jResp.stringOf("projects[i].logsConfig.s3Logs.status");
        name = jResp.stringOf("projects[i].name");
        projectVisibility = jResp.stringOf("projects[i].projectVisibility");
        publicProjectAlias = jResp.stringOf("projects[i].publicProjectAlias");
        queuedTimeoutInMinutes = jResp.IntOf("projects[i].queuedTimeoutInMinutes");
        resourceAccessRole = jResp.stringOf("projects[i].resourceAccessRole");
        serviceRole = jResp.stringOf("projects[i].serviceRole");
        Resource = jResp.stringOf("projects[i].source.auth.resource");
        AuthType = jResp.stringOf("projects[i].source.auth.type");
        Buildspec = jResp.stringOf("projects[i].source.buildspec");
        Context = jResp.stringOf("projects[i].source.buildStatusConfig.context");
        TargetUrl = jResp.stringOf("projects[i].source.buildStatusConfig.targetUrl");
        GitCloneDepth = jResp.IntOf("projects[i].source.gitCloneDepth");
        FetchSubmodules = jResp.IntOf("projects[i].source.gitSubmodulesConfig.fetchSubmodules");
        InsecureSsl = jResp.IntOf("projects[i].source.insecureSsl");
        sourceLocation = jResp.stringOf("projects[i].source.location");
        ReportBuildStatus = jResp.IntOf("projects[i].source.reportBuildStatus");
        SourceIdentifier = jResp.stringOf("projects[i].source.sourceIdentifier");
        sourceType = jResp.stringOf("projects[i].source.type");
        sourceVersion = jResp.stringOf("projects[i].sourceVersion");
        timeoutInMinutes = jResp.IntOf("projects[i].timeoutInMinutes");
        VpcId = jResp.stringOf("projects[i].vpcConfig.vpcId");
        BranchFilter = jResp.stringOf("projects[i].webhook.branchFilter");
        BuildType = jResp.stringOf("projects[i].webhook.buildType");
        LastModifiedSecret = jResp.IntOf("projects[i].webhook.lastModifiedSecret");
        PayloadUrl = jResp.stringOf("projects[i].webhook.payloadUrl");
        Secret = jResp.stringOf("projects[i].webhook.secret");
        v_Url = jResp.stringOf("projects[i].webhook.url");
        j = 0;
        count_j = jResp.SizeOfArray("projects[i].buildBatchConfig.restrictions.computeTypesAllowed");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf("projects[i].buildBatchConfig.restrictions.computeTypesAllowed[j]");
            j = j + 1;
        }

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

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

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

        j = 0;
        count_j = jResp.SizeOfArray("projects[i].secondaryArtifacts");
        while (j < count_j) {
            jResp.put_J(j);
            artifactIdentifier = jResp.stringOf("projects[i].secondaryArtifacts[j].artifactIdentifier");
            bucketOwnerAccess = jResp.stringOf("projects[i].secondaryArtifacts[j].bucketOwnerAccess");
            encryptionDisabled = jResp.IntOf("projects[i].secondaryArtifacts[j].encryptionDisabled");
            location = jResp.stringOf("projects[i].secondaryArtifacts[j].location");
            name = jResp.stringOf("projects[i].secondaryArtifacts[j].name");
            namespaceType = jResp.stringOf("projects[i].secondaryArtifacts[j].namespaceType");
            overrideArtifactName = jResp.IntOf("projects[i].secondaryArtifacts[j].overrideArtifactName");
            packaging = jResp.stringOf("projects[i].secondaryArtifacts[j].packaging");
            path = jResp.stringOf("projects[i].secondaryArtifacts[j].path");
            v_type = jResp.stringOf("projects[i].secondaryArtifacts[j].type");
            j = j + 1;
        }

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

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

        j = 0;
        count_j = jResp.SizeOfArray("projects[i].tags");
        while (j < count_j) {
            jResp.put_J(j);
            key = jResp.stringOf("projects[i].tags[j].key");
            value = jResp.stringOf("projects[i].tags[j].value");
            j = j + 1;
        }

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

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

        j = 0;
        count_j = jResp.SizeOfArray("projects[i].webhook.filterGroups");
        while (j < count_j) {
            jResp.put_J(j);
            k = 0;
            count_k = jResp.SizeOfArray("projects[i].webhook.filterGroups[j]");
            while (k < count_k) {
                jResp.put_K(k);
                excludeMatchedPattern = jResp.IntOf("projects[i].webhook.filterGroups[j][k].excludeMatchedPattern");
                pattern = jResp.stringOf("projects[i].webhook.filterGroups[j][k].pattern");
                v_type = jResp.stringOf("projects[i].webhook.filterGroups[j][k].type");
                k = k + 1;
            }

            j = j + 1;
        }

        i = i + 1;
    }

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

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

    // {
    //   "projects": [
    //     {
    //       "arn": "string",
    //       "artifacts": {
    //         "artifactIdentifier": "string",
    //         "bucketOwnerAccess": "string",
    //         "encryptionDisabled": boolean,
    //         "location": "string",
    //         "name": "string",
    //         "namespaceType": "string",
    //         "overrideArtifactName": boolean,
    //         "packaging": "string",
    //         "path": "string",
    //         "type": "string"
    //       },
    //       "badge": {
    //         "badgeEnabled": boolean,
    //         "badgeRequestUrl": "string"
    //       },
    //       "buildBatchConfig": {
    //         "batchReportMode": "string",
    //         "combineArtifacts": boolean,
    //         "restrictions": {
    //           "computeTypesAllowed": [
    //             "string"
    //           ],
    //           "maximumBuildsAllowed": number
    //         },
    //         "serviceRole": "string",
    //         "timeoutInMins": number
    //       },
    //       "cache": {
    //         "location": "string",
    //         "modes": [
    //           "string"
    //         ],
    //         "type": "string"
    //       },
    //       "concurrentBuildLimit": number,
    //       "created": number,
    //       "description": "string",
    //       "encryptionKey": "string",
    //       "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"
    //         }
    //       ],
    //       "lastModified": number,
    //       "logsConfig": {
    //         "cloudWatchLogs": {
    //           "groupName": "string",
    //           "status": "string",
    //           "streamName": "string"
    //         },
    //         "s3Logs": {
    //           "bucketOwnerAccess": "string",
    //           "encryptionDisabled": boolean,
    //           "location": "string",
    //           "status": "string"
    //         }
    //       },
    //       "name": "string",
    //       "projectVisibility": "string",
    //       "publicProjectAlias": "string",
    //       "queuedTimeoutInMinutes": number,
    //       "resourceAccessRole": "string",
    //       "secondaryArtifacts": [
    //         {
    //           "artifactIdentifier": "string",
    //           "bucketOwnerAccess": "string",
    //           "encryptionDisabled": boolean,
    //           "location": "string",
    //           "name": "string",
    //           "namespaceType": "string",
    //           "overrideArtifactName": boolean,
    //           "packaging": "string",
    //           "path": "string",
    //           "type": "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",
    //       "tags": [
    //         {
    //           "key": "string",
    //           "value": "string"
    //         }
    //       ],
    //       "timeoutInMinutes": number,
    //       "vpcConfig": {
    //         "securityGroupIds": [
    //           "string"
    //         ],
    //         "subnets": [
    //           "string"
    //         ],
    //         "vpcId": "string"
    //       },
    //       "webhook": {
    //         "branchFilter": "string",
    //         "buildType": "string",
    //         "filterGroups": [
    //           [
    //             {
    //               "excludeMatchedPattern": boolean,
    //               "pattern": "string",
    //               "type": "string"
    //             }
    //           ]
    //         ],
    //         "lastModifiedSecret": number,
    //         "payloadUrl": "string",
    //         "secret": "string",
    //         "url": "string"
    //       }
    //     }
    //   ],
    //   "projectsNotFound": [
    //     "string"
    //   ]
    // }
    }