Chilkat Online Tools

DescribeEventDetails unicodeCpp Example

AWS Health

#include <CkRestW.h>
#include <CkAuthAwsW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>

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

    CkRestW rest;
    bool success;

    CkAuthAwsW authAws;
    authAws.put_AccessKey(L"AWS_ACCESS_KEY");
    authAws.put_SecretKey(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.)
    authAws.put_Region(L"us-west-2");
    authAws.put_ServiceName(L"health");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://health.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect(L"health.us-west-2.amazonaws.com",443,true,true);
    if (success != true) {
        wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
        wprintf(L"%s\n",rest.lastErrorText());
        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

    CkJsonObjectW json;
    json.UpdateString(L"eventArns[0]",L"string");
    json.UpdateString(L"locale",L"string");

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

    // {
    //   "eventArns": [
    //     "string"
    //   ],
    //   "locale": "string"
    // }

    rest.AddHeader(L"Content-Type",L"application/x-amz-json-1.1");
    rest.AddHeader(L"X-Amz-Target",L"AWSHealth_20160804.DescribeEventDetails");

    CkStringBuilderW sbRequestBody;
    json.EmitSb(sbRequestBody);
    CkStringBuilderW sbResponseBody;
    success = rest.FullRequestSb(L"POST",L"/",sbRequestBody,sbResponseBody);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    int respStatusCode = rest.get_ResponseStatusCode();
    wprintf(L"response status code = %d\n",respStatusCode);
    if (respStatusCode != 200) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",rest.responseHeader());
        wprintf(L"Response Body:\n");
        wprintf(L"%s\n",sbResponseBody.getAsString());
        return;
    }

    CkJsonObjectW jResp;
    jResp.LoadSb(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.

    const wchar_t *errorMessage = 0;
    const wchar_t *errorName = 0;
    const wchar_t *eventArn = 0;
    const wchar_t *Arn = 0;
    const wchar_t *AvailabilityZone = 0;
    int EndTime;
    const wchar_t *EventScopeCode = 0;
    const wchar_t *EventTypeCategory = 0;
    const wchar_t *EventTypeCode = 0;
    int LastUpdatedTime;
    const wchar_t *Region = 0;
    const wchar_t *Service = 0;
    int StartTime;
    const wchar_t *StatusCode = 0;
    const wchar_t *LatestDescription = 0;
    const wchar_t *v_String = 0;

    int i = 0;
    int count_i = jResp.SizeOfArray(L"failedSet");
    while (i < count_i) {
        jResp.put_I(i);
        errorMessage = jResp.stringOf(L"failedSet[i].errorMessage");
        errorName = jResp.stringOf(L"failedSet[i].errorName");
        eventArn = jResp.stringOf(L"failedSet[i].eventArn");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"successfulSet");
    while (i < count_i) {
        jResp.put_I(i);
        Arn = jResp.stringOf(L"successfulSet[i].event.arn");
        AvailabilityZone = jResp.stringOf(L"successfulSet[i].event.availabilityZone");
        EndTime = jResp.IntOf(L"successfulSet[i].event.endTime");
        EventScopeCode = jResp.stringOf(L"successfulSet[i].event.eventScopeCode");
        EventTypeCategory = jResp.stringOf(L"successfulSet[i].event.eventTypeCategory");
        EventTypeCode = jResp.stringOf(L"successfulSet[i].event.eventTypeCode");
        LastUpdatedTime = jResp.IntOf(L"successfulSet[i].event.lastUpdatedTime");
        Region = jResp.stringOf(L"successfulSet[i].event.region");
        Service = jResp.stringOf(L"successfulSet[i].event.service");
        StartTime = jResp.IntOf(L"successfulSet[i].event.startTime");
        StatusCode = jResp.stringOf(L"successfulSet[i].event.statusCode");
        LatestDescription = jResp.stringOf(L"successfulSet[i].eventDescription.latestDescription");
        v_String = jResp.stringOf(L"successfulSet[i].eventMetadata.string");
        i = i + 1;
    }

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

    // {
    //   "failedSet": [
    //     {
    //       "errorMessage": "string",
    //       "errorName": "string",
    //       "eventArn": "string"
    //     }
    //   ],
    //   "successfulSet": [
    //     {
    //       "event": {
    //         "arn": "string",
    //         "availabilityZone": "string",
    //         "endTime": number,
    //         "eventScopeCode": "string",
    //         "eventTypeCategory": "string",
    //         "eventTypeCode": "string",
    //         "lastUpdatedTime": number,
    //         "region": "string",
    //         "service": "string",
    //         "startTime": number,
    //         "statusCode": "string"
    //       },
    //       "eventDescription": {
    //         "latestDescription": "string"
    //       },
    //       "eventMetadata": {
    //         "string": "string"
    //       }
    //     }
    //   ]
    // }
    }