Chilkat Online Tools

UpdateBranch unicodeC Example

Amplify

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

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    HCkAuthAwsW authAws;
    HCkJsonObjectW json;
    HCkStringBuilderW sbRequestBody;
    HCkStringBuilderW sbResponseBody;
    int respStatusCode;
    HCkJsonObjectW jResp;
    const wchar_t *strVal;
    const wchar_t *ActiveJobId;
    const wchar_t *BackendEnvironmentArn;
    const wchar_t *BasicAuthCredentials;
    const wchar_t *BranchArn;
    const wchar_t *BranchName;
    const wchar_t *BuildSpec;
    int CreateTime;
    const wchar_t *Description;
    const wchar_t *DestinationBranch;
    const wchar_t *DisplayName;
    int EnableAutoBuild;
    int EnableBasicAuth;
    int EnableNotification;
    int EnablePerformanceMode;
    int EnablePullRequestPreview;
    const wchar_t *v_String;
    const wchar_t *Framework;
    const wchar_t *PullRequestEnvironmentName;
    const wchar_t *SourceBranch;
    const wchar_t *Stage;
    const wchar_t *TagsString;
    const wchar_t *ThumbnailUrl;
    const wchar_t *TotalNumberOfJobs;
    const wchar_t *Ttl;
    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;
    }

    // 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

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"backendEnvironmentArn",L"string");
    CkJsonObjectW_UpdateString(json,L"basicAuthCredentials",L"string");
    CkJsonObjectW_UpdateString(json,L"buildSpec",L"string");
    CkJsonObjectW_UpdateString(json,L"description",L"string");
    CkJsonObjectW_UpdateString(json,L"displayName",L"string");
    CkJsonObjectW_UpdateInt(json,L"enableAutoBuild",123);
    CkJsonObjectW_UpdateInt(json,L"enableBasicAuth",123);
    CkJsonObjectW_UpdateInt(json,L"enableNotification",123);
    CkJsonObjectW_UpdateInt(json,L"enablePerformanceMode",123);
    CkJsonObjectW_UpdateInt(json,L"enablePullRequestPreview",123);
    CkJsonObjectW_UpdateString(json,L"environmentVariables.string",L"string");
    CkJsonObjectW_UpdateString(json,L"framework",L"string");
    CkJsonObjectW_UpdateString(json,L"pullRequestEnvironmentName",L"string");
    CkJsonObjectW_UpdateString(json,L"stage",L"string");
    CkJsonObjectW_UpdateString(json,L"ttl",L"string");

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

    // {
    //   "backendEnvironmentArn": "string",
    //   "basicAuthCredentials": "string",
    //   "buildSpec": "string",
    //   "description": "string",
    //   "displayName": "string",
    //   "enableAutoBuild": boolean,
    //   "enableBasicAuth": boolean,
    //   "enableNotification": boolean,
    //   "enablePerformanceMode": boolean,
    //   "enablePullRequestPreview": boolean,
    //   "environmentVariables": {
    //     "string": "string"
    //   },
    //   "framework": "string",
    //   "pullRequestEnvironmentName": "string",
    //   "stage": "string",
    //   "ttl": "string"
    // }

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

    sbRequestBody = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(json,sbRequestBody);
    sbResponseBody = CkStringBuilderW_Create();
    success = CkRestW_FullRequestSb(rest,L"POST",L"/apps/{appId}/branches/{branchName}",sbRequestBody,sbResponseBody);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkAuthAwsW_Dispose(authAws);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        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);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        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.

    ActiveJobId = CkJsonObjectW_stringOf(jResp,L"branch.activeJobId");
    BackendEnvironmentArn = CkJsonObjectW_stringOf(jResp,L"branch.backendEnvironmentArn");
    BasicAuthCredentials = CkJsonObjectW_stringOf(jResp,L"branch.basicAuthCredentials");
    BranchArn = CkJsonObjectW_stringOf(jResp,L"branch.branchArn");
    BranchName = CkJsonObjectW_stringOf(jResp,L"branch.branchName");
    BuildSpec = CkJsonObjectW_stringOf(jResp,L"branch.buildSpec");
    CreateTime = CkJsonObjectW_IntOf(jResp,L"branch.createTime");
    Description = CkJsonObjectW_stringOf(jResp,L"branch.description");
    DestinationBranch = CkJsonObjectW_stringOf(jResp,L"branch.destinationBranch");
    DisplayName = CkJsonObjectW_stringOf(jResp,L"branch.displayName");
    EnableAutoBuild = CkJsonObjectW_IntOf(jResp,L"branch.enableAutoBuild");
    EnableBasicAuth = CkJsonObjectW_IntOf(jResp,L"branch.enableBasicAuth");
    EnableNotification = CkJsonObjectW_IntOf(jResp,L"branch.enableNotification");
    EnablePerformanceMode = CkJsonObjectW_IntOf(jResp,L"branch.enablePerformanceMode");
    EnablePullRequestPreview = CkJsonObjectW_IntOf(jResp,L"branch.enablePullRequestPreview");
    v_String = CkJsonObjectW_stringOf(jResp,L"branch.environmentVariables.string");
    Framework = CkJsonObjectW_stringOf(jResp,L"branch.framework");
    PullRequestEnvironmentName = CkJsonObjectW_stringOf(jResp,L"branch.pullRequestEnvironmentName");
    SourceBranch = CkJsonObjectW_stringOf(jResp,L"branch.sourceBranch");
    Stage = CkJsonObjectW_stringOf(jResp,L"branch.stage");
    TagsString = CkJsonObjectW_stringOf(jResp,L"branch.tags.string");
    ThumbnailUrl = CkJsonObjectW_stringOf(jResp,L"branch.thumbnailUrl");
    TotalNumberOfJobs = CkJsonObjectW_stringOf(jResp,L"branch.totalNumberOfJobs");
    Ttl = CkJsonObjectW_stringOf(jResp,L"branch.ttl");
    UpdateTime = CkJsonObjectW_IntOf(jResp,L"branch.updateTime");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"branch.associatedResources");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        strVal = CkJsonObjectW_stringOf(jResp,L"branch.associatedResources[i]");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"branch.customDomains");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        strVal = CkJsonObjectW_stringOf(jResp,L"branch.customDomains[i]");
        i = i + 1;
    }

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

    // {
    //   "branch": {
    //     "activeJobId": "string",
    //     "associatedResources": [
    //       "string"
    //     ],
    //     "backendEnvironmentArn": "string",
    //     "basicAuthCredentials": "string",
    //     "branchArn": "string",
    //     "branchName": "string",
    //     "buildSpec": "string",
    //     "createTime": number,
    //     "customDomains": [
    //       "string"
    //     ],
    //     "description": "string",
    //     "destinationBranch": "string",
    //     "displayName": "string",
    //     "enableAutoBuild": boolean,
    //     "enableBasicAuth": boolean,
    //     "enableNotification": boolean,
    //     "enablePerformanceMode": boolean,
    //     "enablePullRequestPreview": boolean,
    //     "environmentVariables": {
    //       "string": "string"
    //     },
    //     "framework": "string",
    //     "pullRequestEnvironmentName": "string",
    //     "sourceBranch": "string",
    //     "stage": "string",
    //     "tags": {
    //       "string": "string"
    //     },
    //     "thumbnailUrl": "string",
    //     "totalNumberOfJobs": "string",
    //     "ttl": "string",
    //     "updateTime": number
    //   }
    // }


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

    }