Chilkat Online Tools

CreateApp unicodeCpp Example

Amplify

#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"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;
    }

    // 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"accessToken",L"string");
    json.UpdateString(L"autoBranchCreationConfig.basicAuthCredentials",L"string");
    json.UpdateString(L"autoBranchCreationConfig.buildSpec",L"string");
    json.UpdateInt(L"autoBranchCreationConfig.enableAutoBuild",123);
    json.UpdateInt(L"autoBranchCreationConfig.enableBasicAuth",123);
    json.UpdateInt(L"autoBranchCreationConfig.enablePerformanceMode",123);
    json.UpdateInt(L"autoBranchCreationConfig.enablePullRequestPreview",123);
    json.UpdateString(L"autoBranchCreationConfig.environmentVariables.string",L"string");
    json.UpdateString(L"autoBranchCreationConfig.framework",L"string");
    json.UpdateString(L"autoBranchCreationConfig.pullRequestEnvironmentName",L"string");
    json.UpdateString(L"autoBranchCreationConfig.stage",L"string");
    json.UpdateString(L"autoBranchCreationPatterns[0]",L"string");
    json.UpdateString(L"basicAuthCredentials",L"string");
    json.UpdateString(L"buildSpec",L"string");
    json.UpdateString(L"customHeaders",L"string");
    json.UpdateString(L"customRules[0].condition",L"string");
    json.UpdateString(L"customRules[0].source",L"string");
    json.UpdateString(L"customRules[0].status",L"string");
    json.UpdateString(L"customRules[0].target",L"string");
    json.UpdateString(L"description",L"string");
    json.UpdateInt(L"enableAutoBranchCreation",123);
    json.UpdateInt(L"enableBasicAuth",123);
    json.UpdateInt(L"enableBranchAutoBuild",123);
    json.UpdateInt(L"enableBranchAutoDeletion",123);
    json.UpdateString(L"environmentVariables.string",L"string");
    json.UpdateString(L"iamServiceRoleArn",L"string");
    json.UpdateString(L"name",L"string");
    json.UpdateString(L"oauthToken",L"string");
    json.UpdateString(L"platform",L"string");
    json.UpdateString(L"repository",L"string");
    json.UpdateString(L"tags.string",L"string");

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

    // {
    //   "accessToken": "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",
    //   "customHeaders": "string",
    //   "customRules": [
    //     {
    //       "condition": "string",
    //       "source": "string",
    //       "status": "string",
    //       "target": "string"
    //     }
    //   ],
    //   "description": "string",
    //   "enableAutoBranchCreation": boolean,
    //   "enableBasicAuth": boolean,
    //   "enableBranchAutoBuild": boolean,
    //   "enableBranchAutoDeletion": boolean,
    //   "environmentVariables": {
    //     "string": "string"
    //   },
    //   "iamServiceRoleArn": "string",
    //   "name": "string",
    //   "oauthToken": "string",
    //   "platform": "string",
    //   "repository": "string",
    //   "tags": {
    //     "string": "string"
    //   }
    // }

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

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

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