Chilkat Online Tools

BatchGetProjects unicodeCpp Example

AWS CodeBuild

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

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

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

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

    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 *arn = 0;
    const wchar_t *ArtifactIdentifier = 0;
    const wchar_t *BucketOwnerAccess = 0;
    int EncryptionDisabled;
    const wchar_t *Location = 0;
    const wchar_t *Name = 0;
    const wchar_t *NamespaceType = 0;
    int OverrideArtifactName;
    const wchar_t *Packaging = 0;
    const wchar_t *Path = 0;
    const wchar_t *v_Type = 0;
    int BadgeEnabled;
    const wchar_t *BadgeRequestUrl = 0;
    const wchar_t *BatchReportMode = 0;
    int CombineArtifacts;
    int MaximumBuildsAllowed;
    const wchar_t *ServiceRole = 0;
    int TimeoutInMins;
    const wchar_t *cacheLocation = 0;
    const wchar_t *cacheType = 0;
    int concurrentBuildLimit;
    int created;
    const wchar_t *description = 0;
    const wchar_t *encryptionKey = 0;
    const wchar_t *Certificate = 0;
    const wchar_t *ComputeType = 0;
    const wchar_t *Image = 0;
    const wchar_t *ImagePullCredentialsType = 0;
    int PrivilegedMode;
    const wchar_t *Credential = 0;
    const wchar_t *CredentialProvider = 0;
    const wchar_t *environmentType = 0;
    int lastModified;
    const wchar_t *GroupName = 0;
    const wchar_t *Status = 0;
    const wchar_t *StreamName = 0;
    const wchar_t *S3LogsBucketOwnerAccess = 0;
    int S3LogsEncryptionDisabled;
    const wchar_t *S3LogsLocation = 0;
    const wchar_t *S3LogsStatus = 0;
    const wchar_t *name = 0;
    const wchar_t *projectVisibility = 0;
    const wchar_t *publicProjectAlias = 0;
    int queuedTimeoutInMinutes;
    const wchar_t *resourceAccessRole = 0;
    const wchar_t *serviceRole = 0;
    const wchar_t *Resource = 0;
    const wchar_t *AuthType = 0;
    const wchar_t *Buildspec = 0;
    const wchar_t *Context = 0;
    const wchar_t *TargetUrl = 0;
    int GitCloneDepth;
    int FetchSubmodules;
    int InsecureSsl;
    const wchar_t *sourceLocation = 0;
    int ReportBuildStatus;
    const wchar_t *SourceIdentifier = 0;
    const wchar_t *sourceType = 0;
    const wchar_t *sourceVersion = 0;
    int timeoutInMinutes;
    const wchar_t *VpcId = 0;
    const wchar_t *BranchFilter = 0;
    const wchar_t *BuildType = 0;
    int LastModifiedSecret;
    const wchar_t *PayloadUrl = 0;
    const wchar_t *Secret = 0;
    const wchar_t *v_Url = 0;
    int j;
    int count_j;
    const wchar_t *strVal = 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;
    const wchar_t *artifactIdentifier = 0;
    const wchar_t *bucketOwnerAccess = 0;
    int encryptionDisabled;
    const wchar_t *namespaceType = 0;
    int overrideArtifactName;
    const wchar_t *packaging = 0;
    const wchar_t *path = 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 *key = 0;
    int k;
    int count_k;
    int excludeMatchedPattern;
    const wchar_t *pattern = 0;

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

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

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

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

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

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

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

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

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

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

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

            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"projectsNotFound");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"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"
    //   ]
    // }
    }