Chilkat Online Tools

ListApps C++ Example

Amplify

#include <CkRest.h>
#include <CkAuthAws.h>
#include <CkStringBuilder.h>
#include <CkJsonObject.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("amplify");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://amplify.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect("amplify.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;
    }

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

    CkStringBuilder sbResponseBody;
    success = rest.FullRequestNoBodySb("GET","/apps",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 *appArn = 0;
    const char *appId = 0;
    const char *BasicAuthCredentials = 0;
    const char *BuildSpec = 0;
    int EnableAutoBuild;
    int EnableBasicAuth;
    int EnablePerformanceMode;
    int EnablePullRequestPreview;
    const char *v_String = 0;
    const char *Framework = 0;
    const char *PullRequestEnvironmentName = 0;
    const char *Stage = 0;
    const char *basicAuthCredentials = 0;
    const char *buildSpec = 0;
    int createTime;
    const char *customHeaders = 0;
    const char *defaultDomain = 0;
    const char *description = 0;
    int enableAutoBranchCreation;
    int enableBasicAuth;
    int enableBranchAutoBuild;
    int enableBranchAutoDeletion;
    const char *environmentVariablesString = 0;
    const char *iamServiceRoleArn = 0;
    const char *name = 0;
    const char *platform = 0;
    const char *BranchName = 0;
    int LastDeployTime;
    const char *Status = 0;
    const char *ThumbnailUrl = 0;
    const char *repository = 0;
    const char *repositoryCloneMethod = 0;
    const char *tagsString = 0;
    int updateTime;
    int j;
    int count_j;
    const char *strVal = 0;
    const char *condition = 0;
    const char *source = 0;
    const char *status = 0;
    const char *target = 0;

    const char *nextToken = jResp.stringOf("nextToken");
    int i = 0;
    int count_i = jResp.SizeOfArray("apps");
    while (i < count_i) {
        jResp.put_I(i);
        appArn = jResp.stringOf("apps[i].appArn");
        appId = jResp.stringOf("apps[i].appId");
        BasicAuthCredentials = jResp.stringOf("apps[i].autoBranchCreationConfig.basicAuthCredentials");
        BuildSpec = jResp.stringOf("apps[i].autoBranchCreationConfig.buildSpec");
        EnableAutoBuild = jResp.IntOf("apps[i].autoBranchCreationConfig.enableAutoBuild");
        EnableBasicAuth = jResp.IntOf("apps[i].autoBranchCreationConfig.enableBasicAuth");
        EnablePerformanceMode = jResp.IntOf("apps[i].autoBranchCreationConfig.enablePerformanceMode");
        EnablePullRequestPreview = jResp.IntOf("apps[i].autoBranchCreationConfig.enablePullRequestPreview");
        v_String = jResp.stringOf("apps[i].autoBranchCreationConfig.environmentVariables.string");
        Framework = jResp.stringOf("apps[i].autoBranchCreationConfig.framework");
        PullRequestEnvironmentName = jResp.stringOf("apps[i].autoBranchCreationConfig.pullRequestEnvironmentName");
        Stage = jResp.stringOf("apps[i].autoBranchCreationConfig.stage");
        basicAuthCredentials = jResp.stringOf("apps[i].basicAuthCredentials");
        buildSpec = jResp.stringOf("apps[i].buildSpec");
        createTime = jResp.IntOf("apps[i].createTime");
        customHeaders = jResp.stringOf("apps[i].customHeaders");
        defaultDomain = jResp.stringOf("apps[i].defaultDomain");
        description = jResp.stringOf("apps[i].description");
        enableAutoBranchCreation = jResp.IntOf("apps[i].enableAutoBranchCreation");
        enableBasicAuth = jResp.IntOf("apps[i].enableBasicAuth");
        enableBranchAutoBuild = jResp.IntOf("apps[i].enableBranchAutoBuild");
        enableBranchAutoDeletion = jResp.IntOf("apps[i].enableBranchAutoDeletion");
        environmentVariablesString = jResp.stringOf("apps[i].environmentVariables.string");
        iamServiceRoleArn = jResp.stringOf("apps[i].iamServiceRoleArn");
        name = jResp.stringOf("apps[i].name");
        platform = jResp.stringOf("apps[i].platform");
        BranchName = jResp.stringOf("apps[i].productionBranch.branchName");
        LastDeployTime = jResp.IntOf("apps[i].productionBranch.lastDeployTime");
        Status = jResp.stringOf("apps[i].productionBranch.status");
        ThumbnailUrl = jResp.stringOf("apps[i].productionBranch.thumbnailUrl");
        repository = jResp.stringOf("apps[i].repository");
        repositoryCloneMethod = jResp.stringOf("apps[i].repositoryCloneMethod");
        tagsString = jResp.stringOf("apps[i].tags.string");
        updateTime = jResp.IntOf("apps[i].updateTime");
        j = 0;
        count_j = jResp.SizeOfArray("apps[i].autoBranchCreationPatterns");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf("apps[i].autoBranchCreationPatterns[j]");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray("apps[i].customRules");
        while (j < count_j) {
            jResp.put_J(j);
            condition = jResp.stringOf("apps[i].customRules[j].condition");
            source = jResp.stringOf("apps[i].customRules[j].source");
            status = jResp.stringOf("apps[i].customRules[j].status");
            target = jResp.stringOf("apps[i].customRules[j].target");
            j = j + 1;
        }

        i = i + 1;
    }

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

    // {
    //   "apps": [
    //     {
    //       "appArn": "string",
    //       "appId": "string",
    //       "autoBranchCreationConfig": {
    //         "basicAuthCredentials": "string",
    //         "buildSpec": "string",
    //         "enableAutoBuild": boolean,
    //         "enableBasicAuth": boolean,
    //         "enablePerformanceMode": boolean,
    //         "enablePullRequestPreview": boolean,
    //         "environmentVariables": {
    //           "string": "string"
    //         },
    //         "framework": "string",
    //         "pullRequestEnvironmentName": "string",
    //         "stage": "string"
    //       },
    //       "autoBranchCreationPatterns": [
    //         "string"
    //       ],
    //       "basicAuthCredentials": "string",
    //       "buildSpec": "string",
    //       "createTime": number,
    //       "customHeaders": "string",
    //       "customRules": [
    //         {
    //           "condition": "string",
    //           "source": "string",
    //           "status": "string",
    //           "target": "string"
    //         }
    //       ],
    //       "defaultDomain": "string",
    //       "description": "string",
    //       "enableAutoBranchCreation": boolean,
    //       "enableBasicAuth": boolean,
    //       "enableBranchAutoBuild": boolean,
    //       "enableBranchAutoDeletion": boolean,
    //       "environmentVariables": {
    //         "string": "string"
    //       },
    //       "iamServiceRoleArn": "string",
    //       "name": "string",
    //       "platform": "string",
    //       "productionBranch": {
    //         "branchName": "string",
    //         "lastDeployTime": number,
    //         "status": "string",
    //         "thumbnailUrl": "string"
    //       },
    //       "repository": "string",
    //       "repositoryCloneMethod": "string",
    //       "tags": {
    //         "string": "string"
    //       },
    //       "updateTime": number
    //     }
    //   ],
    //   "nextToken": "string"
    // }
    }