Chilkat Online Tools

DescribeDataset unicodeC Example

AWS IoT Analytics

#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 *actionName;
    const wchar_t *ExecutionRoleArn;
    const wchar_t *Image;
    const wchar_t *ComputeType;
    int VolumeSizeInGB;
    const wchar_t *SqlQuery;
    int j;
    int count_j;
    const wchar_t *DatasetName;
    int doubleValue;
    const wchar_t *name;
    const wchar_t *FileName;
    const wchar_t *stringValue;
    int OffsetSeconds;
    const wchar_t *TimeExpression;
    const wchar_t *InputName;
    const wchar_t *RoleArn;
    const wchar_t *Bucket;
    const wchar_t *DatabaseName;
    const wchar_t *TableName;
    const wchar_t *Key;
    const wchar_t *S3DestinationConfigurationRoleArn;
    const wchar_t *entryName;
    int TimeoutInMinutes;
    const wchar_t *ruleName;
    const wchar_t *datasetName;
    const wchar_t *Expression;
    const wchar_t *Arn;
    int CreationTime;
    int LastUpdateTime;
    const wchar_t *Name;
    int NumberOfDays;
    int Unlimited;
    const wchar_t *Status;
    int MaxVersions;
    int VersioningConfigurationUnlimited;
    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"iotanalytics");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    CkRestW_SetAuthAws(rest,authAws);

    // URL: https://iotanalytics.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = CkRestW_Connect(rest,L"iotanalytics.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"DescribeDataset");

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

    Arn = CkJsonObjectW_stringOf(jResp,L"dataset.arn");
    CreationTime = CkJsonObjectW_IntOf(jResp,L"dataset.creationTime");
    LastUpdateTime = CkJsonObjectW_IntOf(jResp,L"dataset.lastUpdateTime");
    Name = CkJsonObjectW_stringOf(jResp,L"dataset.name");
    NumberOfDays = CkJsonObjectW_IntOf(jResp,L"dataset.retentionPeriod.numberOfDays");
    Unlimited = CkJsonObjectW_IntOf(jResp,L"dataset.retentionPeriod.unlimited");
    Status = CkJsonObjectW_stringOf(jResp,L"dataset.status");
    MaxVersions = CkJsonObjectW_IntOf(jResp,L"dataset.versioningConfiguration.maxVersions");
    VersioningConfigurationUnlimited = CkJsonObjectW_IntOf(jResp,L"dataset.versioningConfiguration.unlimited");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"dataset.actions");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        actionName = CkJsonObjectW_stringOf(jResp,L"dataset.actions[i].actionName");
        ExecutionRoleArn = CkJsonObjectW_stringOf(jResp,L"dataset.actions[i].containerAction.executionRoleArn");
        Image = CkJsonObjectW_stringOf(jResp,L"dataset.actions[i].containerAction.image");
        ComputeType = CkJsonObjectW_stringOf(jResp,L"dataset.actions[i].containerAction.resourceConfiguration.computeType");
        VolumeSizeInGB = CkJsonObjectW_IntOf(jResp,L"dataset.actions[i].containerAction.resourceConfiguration.volumeSizeInGB");
        SqlQuery = CkJsonObjectW_stringOf(jResp,L"dataset.actions[i].queryAction.sqlQuery");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"dataset.actions[i].containerAction.variables");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            DatasetName = CkJsonObjectW_stringOf(jResp,L"dataset.actions[i].containerAction.variables[j].datasetContentVersionValue.datasetName");
            doubleValue = CkJsonObjectW_IntOf(jResp,L"dataset.actions[i].containerAction.variables[j].doubleValue");
            name = CkJsonObjectW_stringOf(jResp,L"dataset.actions[i].containerAction.variables[j].name");
            FileName = CkJsonObjectW_stringOf(jResp,L"dataset.actions[i].containerAction.variables[j].outputFileUriValue.fileName");
            stringValue = CkJsonObjectW_stringOf(jResp,L"dataset.actions[i].containerAction.variables[j].stringValue");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"dataset.actions[i].queryAction.filters");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            OffsetSeconds = CkJsonObjectW_IntOf(jResp,L"dataset.actions[i].queryAction.filters[j].deltaTime.offsetSeconds");
            TimeExpression = CkJsonObjectW_stringOf(jResp,L"dataset.actions[i].queryAction.filters[j].deltaTime.timeExpression");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"dataset.contentDeliveryRules");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        InputName = CkJsonObjectW_stringOf(jResp,L"dataset.contentDeliveryRules[i].destination.iotEventsDestinationConfiguration.inputName");
        RoleArn = CkJsonObjectW_stringOf(jResp,L"dataset.contentDeliveryRules[i].destination.iotEventsDestinationConfiguration.roleArn");
        Bucket = CkJsonObjectW_stringOf(jResp,L"dataset.contentDeliveryRules[i].destination.s3DestinationConfiguration.bucket");
        DatabaseName = CkJsonObjectW_stringOf(jResp,L"dataset.contentDeliveryRules[i].destination.s3DestinationConfiguration.glueConfiguration.databaseName");
        TableName = CkJsonObjectW_stringOf(jResp,L"dataset.contentDeliveryRules[i].destination.s3DestinationConfiguration.glueConfiguration.tableName");
        Key = CkJsonObjectW_stringOf(jResp,L"dataset.contentDeliveryRules[i].destination.s3DestinationConfiguration.key");
        S3DestinationConfigurationRoleArn = CkJsonObjectW_stringOf(jResp,L"dataset.contentDeliveryRules[i].destination.s3DestinationConfiguration.roleArn");
        entryName = CkJsonObjectW_stringOf(jResp,L"dataset.contentDeliveryRules[i].entryName");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"dataset.lateDataRules");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        TimeoutInMinutes = CkJsonObjectW_IntOf(jResp,L"dataset.lateDataRules[i].ruleConfiguration.deltaTimeSessionWindowConfiguration.timeoutInMinutes");
        ruleName = CkJsonObjectW_stringOf(jResp,L"dataset.lateDataRules[i].ruleName");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"dataset.triggers");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        datasetName = CkJsonObjectW_stringOf(jResp,L"dataset.triggers[i].dataset.name");
        Expression = CkJsonObjectW_stringOf(jResp,L"dataset.triggers[i].schedule.expression");
        i = i + 1;
    }

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

    // {
    //   "dataset": {
    //     "actions": [
    //       {
    //         "actionName": "string",
    //         "containerAction": {
    //           "executionRoleArn": "string",
    //           "image": "string",
    //           "resourceConfiguration": {
    //             "computeType": "string",
    //             "volumeSizeInGB": number
    //           },
    //           "variables": [
    //             {
    //               "datasetContentVersionValue": {
    //                 "datasetName": "string"
    //               },
    //               "doubleValue": number,
    //               "name": "string",
    //               "outputFileUriValue": {
    //                 "fileName": "string"
    //               },
    //               "stringValue": "string"
    //             }
    //           ]
    //         },
    //         "queryAction": {
    //           "filters": [
    //             {
    //               "deltaTime": {
    //                 "offsetSeconds": number,
    //                 "timeExpression": "string"
    //               }
    //             }
    //           ],
    //           "sqlQuery": "string"
    //         }
    //       }
    //     ],
    //     "arn": "string",
    //     "contentDeliveryRules": [
    //       {
    //         "destination": {
    //           "iotEventsDestinationConfiguration": {
    //             "inputName": "string",
    //             "roleArn": "string"
    //           },
    //           "s3DestinationConfiguration": {
    //             "bucket": "string",
    //             "glueConfiguration": {
    //               "databaseName": "string",
    //               "tableName": "string"
    //             },
    //             "key": "string",
    //             "roleArn": "string"
    //           }
    //         },
    //         "entryName": "string"
    //       }
    //     ],
    //     "creationTime": number,
    //     "lastUpdateTime": number,
    //     "lateDataRules": [
    //       {
    //         "ruleConfiguration": {
    //           "deltaTimeSessionWindowConfiguration": {
    //             "timeoutInMinutes": number
    //           }
    //         },
    //         "ruleName": "string"
    //       }
    //     ],
    //     "name": "string",
    //     "retentionPeriod": {
    //       "numberOfDays": number,
    //       "unlimited": boolean
    //     },
    //     "status": "string",
    //     "triggers": [
    //       {
    //         "dataset": {
    //           "name": "string"
    //         },
    //         "schedule": {
    //           "expression": "string"
    //         }
    //       }
    //     ],
    //     "versioningConfiguration": {
    //       "maxVersions": number,
    //       "unlimited": boolean
    //     }
    //   }
    // }


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

    }