Chilkat Online Tools

GetApp 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","GetApp");

    CkStringBuilder sbResponseBody;
    success = rest.FullRequestNoBodySb("GET","/apps/{appId}",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 *strVal = 0;
    const char *condition = 0;
    const char *source = 0;
    const char *status = 0;
    const char *target = 0;

    const char *AppArn = jResp.stringOf("app.appArn");
    const char *AppId = jResp.stringOf("app.appId");
    const char *BasicAuthCredentials = jResp.stringOf("app.autoBranchCreationConfig.basicAuthCredentials");
    const char *BuildSpec = jResp.stringOf("app.autoBranchCreationConfig.buildSpec");
    int EnableAutoBuild = jResp.IntOf("app.autoBranchCreationConfig.enableAutoBuild");
    int EnableBasicAuth = jResp.IntOf("app.autoBranchCreationConfig.enableBasicAuth");
    int EnablePerformanceMode = jResp.IntOf("app.autoBranchCreationConfig.enablePerformanceMode");
    int EnablePullRequestPreview = jResp.IntOf("app.autoBranchCreationConfig.enablePullRequestPreview");
    const char *v_String = jResp.stringOf("app.autoBranchCreationConfig.environmentVariables.string");
    const char *Framework = jResp.stringOf("app.autoBranchCreationConfig.framework");
    const char *PullRequestEnvironmentName = jResp.stringOf("app.autoBranchCreationConfig.pullRequestEnvironmentName");
    const char *Stage = jResp.stringOf("app.autoBranchCreationConfig.stage");
    const char *appBasicAuthCredentials = jResp.stringOf("app.basicAuthCredentials");
    const char *appBuildSpec = jResp.stringOf("app.buildSpec");
    int CreateTime = jResp.IntOf("app.createTime");
    const char *CustomHeaders = jResp.stringOf("app.customHeaders");
    const char *DefaultDomain = jResp.stringOf("app.defaultDomain");
    const char *Description = jResp.stringOf("app.description");
    int EnableAutoBranchCreation = jResp.IntOf("app.enableAutoBranchCreation");
    int appEnableBasicAuth = jResp.IntOf("app.enableBasicAuth");
    int EnableBranchAutoBuild = jResp.IntOf("app.enableBranchAutoBuild");
    int EnableBranchAutoDeletion = jResp.IntOf("app.enableBranchAutoDeletion");
    const char *EnvironmentVariablesString = jResp.stringOf("app.environmentVariables.string");
    const char *IamServiceRoleArn = jResp.stringOf("app.iamServiceRoleArn");
    const char *Name = jResp.stringOf("app.name");
    const char *Platform = jResp.stringOf("app.platform");
    const char *BranchName = jResp.stringOf("app.productionBranch.branchName");
    int LastDeployTime = jResp.IntOf("app.productionBranch.lastDeployTime");
    const char *Status = jResp.stringOf("app.productionBranch.status");
    const char *ThumbnailUrl = jResp.stringOf("app.productionBranch.thumbnailUrl");
    const char *Repository = jResp.stringOf("app.repository");
    const char *RepositoryCloneMethod = jResp.stringOf("app.repositoryCloneMethod");
    const char *TagsString = jResp.stringOf("app.tags.string");
    int UpdateTime = jResp.IntOf("app.updateTime");
    int i = 0;
    int count_i = jResp.SizeOfArray("app.autoBranchCreationPatterns");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf("app.autoBranchCreationPatterns[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray("app.customRules");
    while (i < count_i) {
        jResp.put_I(i);
        condition = jResp.stringOf("app.customRules[i].condition");
        source = jResp.stringOf("app.customRules[i].source");
        status = jResp.stringOf("app.customRules[i].status");
        target = jResp.stringOf("app.customRules[i].target");
        i = i + 1;
    }

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

    // {
    //   "app": {
    //     "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
    //   }
    // }
    }