Chilkat Online Tools

GetApp C Example

Amplify

#include <C_CkRest.h>
#include <C_CkAuthAws.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL success;
    HCkAuthAws authAws;
    HCkStringBuilder sbResponseBody;
    int respStatusCode;
    HCkJsonObject jResp;
    const char *strVal;
    const char *condition;
    const char *source;
    const char *status;
    const char *target;
    const char *AppArn;
    const char *AppId;
    const char *BasicAuthCredentials;
    const char *BuildSpec;
    int EnableAutoBuild;
    int EnableBasicAuth;
    int EnablePerformanceMode;
    int EnablePullRequestPreview;
    const char *v_String;
    const char *Framework;
    const char *PullRequestEnvironmentName;
    const char *Stage;
    const char *appBasicAuthCredentials;
    const char *appBuildSpec;
    int CreateTime;
    const char *CustomHeaders;
    const char *DefaultDomain;
    const char *Description;
    int EnableAutoBranchCreation;
    int appEnableBasicAuth;
    int EnableBranchAutoBuild;
    int EnableBranchAutoDeletion;
    const char *EnvironmentVariablesString;
    const char *IamServiceRoleArn;
    const char *Name;
    const char *Platform;
    const char *BranchName;
    int LastDeployTime;
    const char *Status;
    const char *ThumbnailUrl;
    const char *Repository;
    const char *RepositoryCloneMethod;
    const char *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 = CkRest_Create();

    authAws = CkAuthAws_Create();
    CkAuthAws_putAccessKey(authAws,"AWS_ACCESS_KEY");
    CkAuthAws_putSecretKey(authAws,"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.)
    CkAuthAws_putRegion(authAws,"us-west-2");
    CkAuthAws_putServiceName(authAws,"amplify");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    CkRest_SetAuthAws(rest,authAws);

    // URL: https://amplify.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = CkRest_Connect(rest,"amplify.us-west-2.amazonaws.com",443,TRUE,TRUE);
    if (success != TRUE) {
        printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkAuthAws_Dispose(authAws);
        return;
    }

    CkRest_AddHeader(rest,"Content-Type","application/x-amz-json-1.1");
    CkRest_AddHeader(rest,"X-Amz-Target","GetApp");

    sbResponseBody = CkStringBuilder_Create();
    success = CkRest_FullRequestNoBodySb(rest,"GET","/apps/{appId}",sbResponseBody);
    if (success != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkAuthAws_Dispose(authAws);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    respStatusCode = CkRest_getResponseStatusCode(rest);
    printf("response status code = %d\n",respStatusCode);
    if (respStatusCode != 200) {
        printf("Response Header:\n");
        printf("%s\n",CkRest_responseHeader(rest));
        printf("Response Body:\n");
        printf("%s\n",CkStringBuilder_getAsString(sbResponseBody));
        CkRest_Dispose(rest);
        CkAuthAws_Dispose(authAws);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

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

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


    CkRest_Dispose(rest);
    CkAuthAws_Dispose(authAws);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jResp);

    }