Chilkat Online Tools

ListRuns Unicode C Example

AWS Device Farm

#include <C_CkRestW.h>
#include <C_CkAuthAwsW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    HCkAuthAwsW authAws;
    HCkJsonObjectW json;
    HCkStringBuilderW sbRequestBody;
    HCkStringBuilderW sbResponseBody;
    int respStatusCode;
    HCkJsonObjectW jResp;
    const wchar_t *appUpload;
    const wchar_t *arn;
    const wchar_t *billingMethod;
    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;
    int MatchedDevicesCount;
    int MaxDevices;
    int eventCount;
    int jobTimeoutMinutes;
    const wchar_t *locale;
    int Latitude;
    int Longitude;
    const wchar_t *message;
    const wchar_t *name;
    const wchar_t *Arn;
    const wchar_t *Description;
    int DownlinkBandwidthBits;
    int DownlinkDelayMs;
    int DownlinkJitterMs;
    int DownlinkLossPercent;
    const wchar_t *Name;
    const wchar_t *v_Type;
    int UplinkBandwidthBits;
    int UplinkDelayMs;
    int UplinkJitterMs;
    int UplinkLossPercent;
    const wchar_t *parsingResultUrl;
    const wchar_t *platform;
    int Bluetooth;
    int Gps;
    int Nfc;
    int Wifi;
    const wchar_t *result;
    const wchar_t *resultCode;
    int seed;
    int skipAppResign;
    int started;
    const wchar_t *status;
    int stopped;
    const wchar_t *testSpecArn;
    int totalJobs;
    const wchar_t *v_type;
    const wchar_t *webUrl;
    int j;
    int count_j;
    const wchar_t *strVal;
    const wchar_t *attribute;
    const wchar_t *operator;
    int k;
    int count_k;
    const wchar_t *nextToken;
    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"devicefarm");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    CkRestW_SetAuthAws(rest,authAws);

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

    // 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

    json = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(json,L"arn",L"string");
    CkJsonObjectW_UpdateString(json,L"nextToken",L"string");

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

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

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

    sbRequestBody = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(json,sbRequestBody);
    sbResponseBody = CkStringBuilderW_Create();
    success = CkRestW_FullRequestSb(rest,L"POST",L"/",sbRequestBody,sbResponseBody);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkAuthAwsW_Dispose(authAws);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        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);
        CkJsonObjectW_Dispose(json);
        CkStringBuilderW_Dispose(sbRequestBody);
        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.

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

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"runs[i].customerArtifactPaths.deviceHostPaths");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"runs[i].customerArtifactPaths.deviceHostPaths[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"runs[i].customerArtifactPaths.iosPaths");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            strVal = CkJsonObjectW_stringOf(jResp,L"runs[i].customerArtifactPaths.iosPaths[j]");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(jResp,L"runs[i].deviceSelectionResult.filters");
        while (j < count_j) {
            CkJsonObjectW_putJ(jResp,j);
            attribute = CkJsonObjectW_stringOf(jResp,L"runs[i].deviceSelectionResult.filters[j].attribute");
            operator = CkJsonObjectW_stringOf(jResp,L"runs[i].deviceSelectionResult.filters[j].operator");
            k = 0;
            count_k = CkJsonObjectW_SizeOfArray(jResp,L"runs[i].deviceSelectionResult.filters[j].values");
            while (k < count_k) {
                CkJsonObjectW_putK(jResp,k);
                strVal = CkJsonObjectW_stringOf(jResp,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"
    //     }
    //   ]
    // }


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

    }