Chilkat Online Tools

ListBranches 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 *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 j;
    int count_j;
    const wchar_t *strVal;
    const wchar_t *nextToken;
    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"ListBranches");

    sbResponseBody = CkStringBuilderW_Create();
    success = CkRestW_FullRequestNoBodySb(rest,L"GET",L"/apps/{appId}/branches",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.

    nextToken = CkJsonObjectW_stringOf(jResp,L"nextToken");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"branches");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        activeJobId = CkJsonObjectW_stringOf(jResp,L"branches[i].activeJobId");
        backendEnvironmentArn = CkJsonObjectW_stringOf(jResp,L"branches[i].backendEnvironmentArn");
        basicAuthCredentials = CkJsonObjectW_stringOf(jResp,L"branches[i].basicAuthCredentials");
        branchArn = CkJsonObjectW_stringOf(jResp,L"branches[i].branchArn");
        branchName = CkJsonObjectW_stringOf(jResp,L"branches[i].branchName");
        buildSpec = CkJsonObjectW_stringOf(jResp,L"branches[i].buildSpec");
        createTime = CkJsonObjectW_IntOf(jResp,L"branches[i].createTime");
        description = CkJsonObjectW_stringOf(jResp,L"branches[i].description");
        destinationBranch = CkJsonObjectW_stringOf(jResp,L"branches[i].destinationBranch");
        displayName = CkJsonObjectW_stringOf(jResp,L"branches[i].displayName");
        enableAutoBuild = CkJsonObjectW_IntOf(jResp,L"branches[i].enableAutoBuild");
        enableBasicAuth = CkJsonObjectW_IntOf(jResp,L"branches[i].enableBasicAuth");
        enableNotification = CkJsonObjectW_IntOf(jResp,L"branches[i].enableNotification");
        enablePerformanceMode = CkJsonObjectW_IntOf(jResp,L"branches[i].enablePerformanceMode");
        enablePullRequestPreview = CkJsonObjectW_IntOf(jResp,L"branches[i].enablePullRequestPreview");
        v_String = CkJsonObjectW_stringOf(jResp,L"branches[i].environmentVariables.string");
        framework = CkJsonObjectW_stringOf(jResp,L"branches[i].framework");
        pullRequestEnvironmentName = CkJsonObjectW_stringOf(jResp,L"branches[i].pullRequestEnvironmentName");
        sourceBranch = CkJsonObjectW_stringOf(jResp,L"branches[i].sourceBranch");
        stage = CkJsonObjectW_stringOf(jResp,L"branches[i].stage");
        tagsString = CkJsonObjectW_stringOf(jResp,L"branches[i].tags.string");
        thumbnailUrl = CkJsonObjectW_stringOf(jResp,L"branches[i].thumbnailUrl");
        totalNumberOfJobs = CkJsonObjectW_stringOf(jResp,L"branches[i].totalNumberOfJobs");
        ttl = CkJsonObjectW_stringOf(jResp,L"branches[i].ttl");
        updateTime = CkJsonObjectW_IntOf(jResp,L"branches[i].updateTime");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"branches[i].associatedResources");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"branches[i].associatedResources[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"branches[i].customDomains");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"branches[i].customDomains[j]");
            j = j + 1;
        }

        i = i + 1;
    }

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

    // {
    //   "branches": [
    //     {
    //       "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
    //     }
    //   ],
    //   "nextToken": "string"
    // }


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

    }