Chilkat Online Tools

ListRuns unicodeCpp Example

AWS Device Farm

#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"devicefarm");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://devicefarm.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect(L"devicefarm.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"arn",L"string");
    json.UpdateString(L"nextToken",L"string");

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

    // {
    //   "arn": "string",
    //   "nextToken": "string"
    // }

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

    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 *appUpload = 0;
    const wchar_t *arn = 0;
    const wchar_t *billingMethod = 0;
    int completedJobs;
    int Errored;
    int Failed;
    int Passed;
    int Skipped;
    int Stopped;
    int Total;
    int Warned;
    int created;
    int Metered;
    int deviceMinutesTotal;
    int Unmetered;
    const wchar_t *devicePoolArn = 0;
    int MatchedDevicesCount;
    int MaxDevices;
    int eventCount;
    int jobTimeoutMinutes;
    const wchar_t *locale = 0;
    int Latitude;
    int Longitude;
    const wchar_t *message = 0;
    const wchar_t *name = 0;
    const wchar_t *Arn = 0;
    const wchar_t *Description = 0;
    int DownlinkBandwidthBits;
    int DownlinkDelayMs;
    int DownlinkJitterMs;
    int DownlinkLossPercent;
    const wchar_t *Name = 0;
    const wchar_t *v_Type = 0;
    int UplinkBandwidthBits;
    int UplinkDelayMs;
    int UplinkJitterMs;
    int UplinkLossPercent;
    const wchar_t *parsingResultUrl = 0;
    const wchar_t *platform = 0;
    int Bluetooth;
    int Gps;
    int Nfc;
    int Wifi;
    const wchar_t *result = 0;
    const wchar_t *resultCode = 0;
    int seed;
    int skipAppResign;
    int started;
    const wchar_t *status = 0;
    int stopped;
    const wchar_t *testSpecArn = 0;
    int totalJobs;
    const wchar_t *v_type = 0;
    const wchar_t *webUrl = 0;
    int j;
    int count_j;
    const wchar_t *strVal = 0;
    const wchar_t *attribute = 0;
    const wchar_t *operator = 0;
    int k;
    int count_k;

    const wchar_t *nextToken = jResp.stringOf(L"nextToken");
    int i = 0;
    int count_i = jResp.SizeOfArray(L"runs");
    while (i < count_i) {
        jResp.put_I(i);
        appUpload = jResp.stringOf(L"runs[i].appUpload");
        arn = jResp.stringOf(L"runs[i].arn");
        billingMethod = jResp.stringOf(L"runs[i].billingMethod");
        completedJobs = jResp.IntOf(L"runs[i].completedJobs");
        Errored = jResp.IntOf(L"runs[i].counters.errored");
        Failed = jResp.IntOf(L"runs[i].counters.failed");
        Passed = jResp.IntOf(L"runs[i].counters.passed");
        Skipped = jResp.IntOf(L"runs[i].counters.skipped");
        Stopped = jResp.IntOf(L"runs[i].counters.stopped");
        Total = jResp.IntOf(L"runs[i].counters.total");
        Warned = jResp.IntOf(L"runs[i].counters.warned");
        created = jResp.IntOf(L"runs[i].created");
        Metered = jResp.IntOf(L"runs[i].deviceMinutes.metered");
        deviceMinutesTotal = jResp.IntOf(L"runs[i].deviceMinutes.total");
        Unmetered = jResp.IntOf(L"runs[i].deviceMinutes.unmetered");
        devicePoolArn = jResp.stringOf(L"runs[i].devicePoolArn");
        MatchedDevicesCount = jResp.IntOf(L"runs[i].deviceSelectionResult.matchedDevicesCount");
        MaxDevices = jResp.IntOf(L"runs[i].deviceSelectionResult.maxDevices");
        eventCount = jResp.IntOf(L"runs[i].eventCount");
        jobTimeoutMinutes = jResp.IntOf(L"runs[i].jobTimeoutMinutes");
        locale = jResp.stringOf(L"runs[i].locale");
        Latitude = jResp.IntOf(L"runs[i].location.latitude");
        Longitude = jResp.IntOf(L"runs[i].location.longitude");
        message = jResp.stringOf(L"runs[i].message");
        name = jResp.stringOf(L"runs[i].name");
        Arn = jResp.stringOf(L"runs[i].networkProfile.arn");
        Description = jResp.stringOf(L"runs[i].networkProfile.description");
        DownlinkBandwidthBits = jResp.IntOf(L"runs[i].networkProfile.downlinkBandwidthBits");
        DownlinkDelayMs = jResp.IntOf(L"runs[i].networkProfile.downlinkDelayMs");
        DownlinkJitterMs = jResp.IntOf(L"runs[i].networkProfile.downlinkJitterMs");
        DownlinkLossPercent = jResp.IntOf(L"runs[i].networkProfile.downlinkLossPercent");
        Name = jResp.stringOf(L"runs[i].networkProfile.name");
        v_Type = jResp.stringOf(L"runs[i].networkProfile.type");
        UplinkBandwidthBits = jResp.IntOf(L"runs[i].networkProfile.uplinkBandwidthBits");
        UplinkDelayMs = jResp.IntOf(L"runs[i].networkProfile.uplinkDelayMs");
        UplinkJitterMs = jResp.IntOf(L"runs[i].networkProfile.uplinkJitterMs");
        UplinkLossPercent = jResp.IntOf(L"runs[i].networkProfile.uplinkLossPercent");
        parsingResultUrl = jResp.stringOf(L"runs[i].parsingResultUrl");
        platform = jResp.stringOf(L"runs[i].platform");
        Bluetooth = jResp.IntOf(L"runs[i].radios.bluetooth");
        Gps = jResp.IntOf(L"runs[i].radios.gps");
        Nfc = jResp.IntOf(L"runs[i].radios.nfc");
        Wifi = jResp.IntOf(L"runs[i].radios.wifi");
        result = jResp.stringOf(L"runs[i].result");
        resultCode = jResp.stringOf(L"runs[i].resultCode");
        seed = jResp.IntOf(L"runs[i].seed");
        skipAppResign = jResp.IntOf(L"runs[i].skipAppResign");
        started = jResp.IntOf(L"runs[i].started");
        status = jResp.stringOf(L"runs[i].status");
        stopped = jResp.IntOf(L"runs[i].stopped");
        testSpecArn = jResp.stringOf(L"runs[i].testSpecArn");
        totalJobs = jResp.IntOf(L"runs[i].totalJobs");
        v_type = jResp.stringOf(L"runs[i].type");
        webUrl = jResp.stringOf(L"runs[i].webUrl");
        j = 0;
        count_j = jResp.SizeOfArray(L"runs[i].customerArtifactPaths.androidPaths");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf(L"runs[i].customerArtifactPaths.androidPaths[j]");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray(L"runs[i].customerArtifactPaths.deviceHostPaths");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf(L"runs[i].customerArtifactPaths.deviceHostPaths[j]");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray(L"runs[i].customerArtifactPaths.iosPaths");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf(L"runs[i].customerArtifactPaths.iosPaths[j]");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray(L"runs[i].deviceSelectionResult.filters");
        while (j < count_j) {
            jResp.put_J(j);
            attribute = jResp.stringOf(L"runs[i].deviceSelectionResult.filters[j].attribute");
            operator = jResp.stringOf(L"runs[i].deviceSelectionResult.filters[j].operator");
            k = 0;
            count_k = jResp.SizeOfArray(L"runs[i].deviceSelectionResult.filters[j].values");
            while (k < count_k) {
                jResp.put_K(k);
                strVal = jResp.stringOf(L"runs[i].deviceSelectionResult.filters[j].values[k]");
                k = k + 1;
            }

            j = j + 1;
        }

        i = i + 1;
    }

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

    // {
    //   "nextToken": "string",
    //   "runs": [
    //     {
    //       "appUpload": "string",
    //       "arn": "string",
    //       "billingMethod": "string",
    //       "completedJobs": number,
    //       "counters": {
    //         "errored": number,
    //         "failed": number,
    //         "passed": number,
    //         "skipped": number,
    //         "stopped": number,
    //         "total": number,
    //         "warned": number
    //       },
    //       "created": number,
    //       "customerArtifactPaths": {
    //         "androidPaths": [
    //           "string"
    //         ],
    //         "deviceHostPaths": [
    //           "string"
    //         ],
    //         "iosPaths": [
    //           "string"
    //         ]
    //       },
    //       "deviceMinutes": {
    //         "metered": number,
    //         "total": number,
    //         "unmetered": number
    //       },
    //       "devicePoolArn": "string",
    //       "deviceSelectionResult": {
    //         "filters": [
    //           {
    //             "attribute": "string",
    //             "operator": "string",
    //             "values": [
    //               "string"
    //             ]
    //           }
    //         ],
    //         "matchedDevicesCount": number,
    //         "maxDevices": number
    //       },
    //       "eventCount": number,
    //       "jobTimeoutMinutes": number,
    //       "locale": "string",
    //       "location": {
    //         "latitude": number,
    //         "longitude": number
    //       },
    //       "message": "string",
    //       "name": "string",
    //       "networkProfile": {
    //         "arn": "string",
    //         "description": "string",
    //         "downlinkBandwidthBits": number,
    //         "downlinkDelayMs": number,
    //         "downlinkJitterMs": number,
    //         "downlinkLossPercent": number,
    //         "name": "string",
    //         "type": "string",
    //         "uplinkBandwidthBits": number,
    //         "uplinkDelayMs": number,
    //         "uplinkJitterMs": number,
    //         "uplinkLossPercent": number
    //       },
    //       "parsingResultUrl": "string",
    //       "platform": "string",
    //       "radios": {
    //         "bluetooth": boolean,
    //         "gps": boolean,
    //         "nfc": boolean,
    //         "wifi": boolean
    //       },
    //       "result": "string",
    //       "resultCode": "string",
    //       "seed": number,
    //       "skipAppResign": boolean,
    //       "started": number,
    //       "status": "string",
    //       "stopped": number,
    //       "testSpecArn": "string",
    //       "totalJobs": number,
    //       "type": "string",
    //       "webUrl": "string"
    //     }
    //   ]
    // }
    }