Chilkat Online Tools

ListApps unicodeCpp Example

Amplify

#include <CkRestW.h>
#include <CkAuthAwsW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.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"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(L"amplify.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;
    }

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

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

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

        j = 0;
        count_j = jResp.SizeOfArray(L"apps[i].customRules");
        while (j < count_j) {
            jResp.put_J(j);
            condition = jResp.stringOf(L"apps[i].customRules[j].condition");
            source = jResp.stringOf(L"apps[i].customRules[j].source");
            status = jResp.stringOf(L"apps[i].customRules[j].status");
            target = jResp.stringOf(L"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"
    // }
    }