Chilkat Online Tools

GetPortfolioSummary unicodeCpp Example

Migration Hub Strategy Recommendations

#include <CkRestW.h>
#include <CkAuthAwsW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.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"migrationhub-strategy");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://migrationhub-strategy.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect(L"migrationhub-strategy.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;
    }

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

    CkStringBuilderW sbResponseBody;
    success = rest.FullRequestNoBodySb(L"GET",L"/get-portfolio-summary",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.

    int count;
    const wchar_t *severity = 0;
    const wchar_t *strategy = 0;
    const wchar_t *appType = 0;
    const wchar_t *ServerOsType = 0;

    const wchar_t *S3Bucket = jResp.stringOf(L"assessmentSummary.antipatternReportS3Object.s3Bucket");
    const wchar_t *S3key = jResp.stringOf(L"assessmentSummary.antipatternReportS3Object.s3key");
    const wchar_t *AntipatternReportStatus = jResp.stringOf(L"assessmentSummary.antipatternReportStatus");
    const wchar_t *AntipatternReportStatusMessage = jResp.stringOf(L"assessmentSummary.antipatternReportStatusMessage");
    int LastAnalyzedTimestamp = jResp.IntOf(L"assessmentSummary.lastAnalyzedTimestamp");
    int i = 0;
    int count_i = jResp.SizeOfArray(L"assessmentSummary.listAntipatternSeveritySummary");
    while (i < count_i) {
        jResp.put_I(i);
        count = jResp.IntOf(L"assessmentSummary.listAntipatternSeveritySummary[i].count");
        severity = jResp.stringOf(L"assessmentSummary.listAntipatternSeveritySummary[i].severity");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"assessmentSummary.listApplicationComponentStrategySummary");
    while (i < count_i) {
        jResp.put_I(i);
        count = jResp.IntOf(L"assessmentSummary.listApplicationComponentStrategySummary[i].count");
        strategy = jResp.stringOf(L"assessmentSummary.listApplicationComponentStrategySummary[i].strategy");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"assessmentSummary.listApplicationComponentSummary");
    while (i < count_i) {
        jResp.put_I(i);
        appType = jResp.stringOf(L"assessmentSummary.listApplicationComponentSummary[i].appType");
        count = jResp.IntOf(L"assessmentSummary.listApplicationComponentSummary[i].count");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"assessmentSummary.listServerStrategySummary");
    while (i < count_i) {
        jResp.put_I(i);
        count = jResp.IntOf(L"assessmentSummary.listServerStrategySummary[i].count");
        strategy = jResp.stringOf(L"assessmentSummary.listServerStrategySummary[i].strategy");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"assessmentSummary.listServerSummary");
    while (i < count_i) {
        jResp.put_I(i);
        count = jResp.IntOf(L"assessmentSummary.listServerSummary[i].count");
        ServerOsType = jResp.stringOf(L"assessmentSummary.listServerSummary[i].ServerOsType");
        i = i + 1;
    }

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

    // {
    //   "assessmentSummary": {
    //     "antipatternReportS3Object": {
    //       "s3Bucket": "string",
    //       "s3key": "string"
    //     },
    //     "antipatternReportStatus": "string",
    //     "antipatternReportStatusMessage": "string",
    //     "lastAnalyzedTimestamp": number,
    //     "listAntipatternSeveritySummary": [
    //       {
    //         "count": number,
    //         "severity": "string"
    //       }
    //     ],
    //     "listApplicationComponentStrategySummary": [
    //       {
    //         "count": number,
    //         "strategy": "string"
    //       }
    //     ],
    //     "listApplicationComponentSummary": [
    //       {
    //         "appType": "string",
    //         "count": number
    //       }
    //     ],
    //     "listServerStrategySummary": [
    //       {
    //         "count": number,
    //         "strategy": "string"
    //       }
    //     ],
    //     "listServerSummary": [
    //       {
    //         "count": number,
    //         "ServerOsType": "string"
    //       }
    //     ]
    //   }
    // }
    }