Chilkat Online Tools

DeleteApp unicodeC Example

Amplify

#include <C_CkRestW.h>
#include <C_CkAuthAwsW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    HCkAuthAwsW authAws;
    HCkStringBuilderW sbResponseBody;
    int respStatusCode;
    HCkJsonObjectW jResp;
    const wchar_t *strVal;
    const wchar_t *condition;
    const wchar_t *source;
    const wchar_t *status;
    const wchar_t *target;
    const wchar_t *AppArn;
    const wchar_t *AppId;
    const wchar_t *BasicAuthCredentials;
    const wchar_t *BuildSpec;
    int EnableAutoBuild;
    int EnableBasicAuth;
    int EnablePerformanceMode;
    int EnablePullRequestPreview;
    const wchar_t *v_String;
    const wchar_t *Framework;
    const wchar_t *PullRequestEnvironmentName;
    const wchar_t *Stage;
    const wchar_t *appBasicAuthCredentials;
    const wchar_t *appBuildSpec;
    int CreateTime;
    const wchar_t *CustomHeaders;
    const wchar_t *DefaultDomain;
    const wchar_t *Description;
    int EnableAutoBranchCreation;
    int appEnableBasicAuth;
    int EnableBranchAutoBuild;
    int EnableBranchAutoDeletion;
    const wchar_t *EnvironmentVariablesString;
    const wchar_t *IamServiceRoleArn;
    const wchar_t *Name;
    const wchar_t *Platform;
    const wchar_t *BranchName;
    int LastDeployTime;
    const wchar_t *Status;
    const wchar_t *ThumbnailUrl;
    const wchar_t *Repository;
    const wchar_t *RepositoryCloneMethod;
    const wchar_t *TagsString;
    int UpdateTime;
    int i;
    int count_i;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    rest = CkRestW_Create();

    authAws = CkAuthAwsW_Create();
    CkAuthAwsW_putAccessKey(authAws,L"AWS_ACCESS_KEY");
    CkAuthAwsW_putSecretKey(authAws,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.)
    CkAuthAwsW_putRegion(authAws,L"us-west-2");
    CkAuthAwsW_putServiceName(authAws,L"amplify");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    CkRestW_SetAuthAws(rest,authAws);

    // URL: https://amplify.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = CkRestW_Connect(rest,L"amplify.us-west-2.amazonaws.com",443,TRUE,TRUE);
    if (success != TRUE) {
        wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkAuthAwsW_Dispose(authAws);
        return;
    }

    CkRestW_AddHeader(rest,L"Content-Type",L"application/x-amz-json-1.1");
    CkRestW_AddHeader(rest,L"X-Amz-Target",L"DeleteApp");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkRestW_FullRequestNoBodySb(rest,L"DELETE",L"/apps/{appId}",sbResponseBody);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkAuthAwsW_Dispose(authAws);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    respStatusCode = CkRestW_getResponseStatusCode(rest);
    wprintf(L"response status code = %d\n",respStatusCode);
    if (respStatusCode != 200) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkRestW_responseHeader(rest));
        wprintf(L"Response Body:\n");
        wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponseBody));
        CkRestW_Dispose(rest);
        CkAuthAwsW_Dispose(authAws);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,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.

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

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


    CkRestW_Dispose(rest);
    CkAuthAwsW_Dispose(authAws);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }