GetRun unicodeC Example
#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 *strVal;
const wchar_t *attribute;
const wchar_t *operator;
int j;
int count_j;
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 *NetworkProfileArn;
const wchar_t *Description;
int DownlinkBandwidthBits;
int DownlinkDelayMs;
int DownlinkJitterMs;
int DownlinkLossPercent;
const wchar_t *NetworkProfileName;
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 runStopped;
const wchar_t *TestSpecArn;
int TotalJobs;
const wchar_t *runType;
const wchar_t *WebUrl;
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");
// The JSON request body created by the above code:
// {
// "arn": "string"
// }
CkRestW_AddHeader(rest,L"Content-Type",L"application/x-amz-json-1.1");
CkRestW_AddHeader(rest,L"X-Amz-Target",L"DeviceFarm_20150623.GetRun");
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.
AppUpload = CkJsonObjectW_stringOf(jResp,L"run.appUpload");
Arn = CkJsonObjectW_stringOf(jResp,L"run.arn");
BillingMethod = CkJsonObjectW_stringOf(jResp,L"run.billingMethod");
CompletedJobs = CkJsonObjectW_IntOf(jResp,L"run.completedJobs");
Errored = CkJsonObjectW_IntOf(jResp,L"run.counters.errored");
Failed = CkJsonObjectW_IntOf(jResp,L"run.counters.failed");
Passed = CkJsonObjectW_IntOf(jResp,L"run.counters.passed");
Skipped = CkJsonObjectW_IntOf(jResp,L"run.counters.skipped");
Stopped = CkJsonObjectW_IntOf(jResp,L"run.counters.stopped");
Total = CkJsonObjectW_IntOf(jResp,L"run.counters.total");
Warned = CkJsonObjectW_IntOf(jResp,L"run.counters.warned");
Created = CkJsonObjectW_IntOf(jResp,L"run.created");
Metered = CkJsonObjectW_IntOf(jResp,L"run.deviceMinutes.metered");
DeviceMinutesTotal = CkJsonObjectW_IntOf(jResp,L"run.deviceMinutes.total");
Unmetered = CkJsonObjectW_IntOf(jResp,L"run.deviceMinutes.unmetered");
DevicePoolArn = CkJsonObjectW_stringOf(jResp,L"run.devicePoolArn");
MatchedDevicesCount = CkJsonObjectW_IntOf(jResp,L"run.deviceSelectionResult.matchedDevicesCount");
MaxDevices = CkJsonObjectW_IntOf(jResp,L"run.deviceSelectionResult.maxDevices");
EventCount = CkJsonObjectW_IntOf(jResp,L"run.eventCount");
JobTimeoutMinutes = CkJsonObjectW_IntOf(jResp,L"run.jobTimeoutMinutes");
Locale = CkJsonObjectW_stringOf(jResp,L"run.locale");
Latitude = CkJsonObjectW_IntOf(jResp,L"run.location.latitude");
Longitude = CkJsonObjectW_IntOf(jResp,L"run.location.longitude");
Message = CkJsonObjectW_stringOf(jResp,L"run.message");
Name = CkJsonObjectW_stringOf(jResp,L"run.name");
NetworkProfileArn = CkJsonObjectW_stringOf(jResp,L"run.networkProfile.arn");
Description = CkJsonObjectW_stringOf(jResp,L"run.networkProfile.description");
DownlinkBandwidthBits = CkJsonObjectW_IntOf(jResp,L"run.networkProfile.downlinkBandwidthBits");
DownlinkDelayMs = CkJsonObjectW_IntOf(jResp,L"run.networkProfile.downlinkDelayMs");
DownlinkJitterMs = CkJsonObjectW_IntOf(jResp,L"run.networkProfile.downlinkJitterMs");
DownlinkLossPercent = CkJsonObjectW_IntOf(jResp,L"run.networkProfile.downlinkLossPercent");
NetworkProfileName = CkJsonObjectW_stringOf(jResp,L"run.networkProfile.name");
v_Type = CkJsonObjectW_stringOf(jResp,L"run.networkProfile.type");
UplinkBandwidthBits = CkJsonObjectW_IntOf(jResp,L"run.networkProfile.uplinkBandwidthBits");
UplinkDelayMs = CkJsonObjectW_IntOf(jResp,L"run.networkProfile.uplinkDelayMs");
UplinkJitterMs = CkJsonObjectW_IntOf(jResp,L"run.networkProfile.uplinkJitterMs");
UplinkLossPercent = CkJsonObjectW_IntOf(jResp,L"run.networkProfile.uplinkLossPercent");
ParsingResultUrl = CkJsonObjectW_stringOf(jResp,L"run.parsingResultUrl");
Platform = CkJsonObjectW_stringOf(jResp,L"run.platform");
Bluetooth = CkJsonObjectW_IntOf(jResp,L"run.radios.bluetooth");
Gps = CkJsonObjectW_IntOf(jResp,L"run.radios.gps");
Nfc = CkJsonObjectW_IntOf(jResp,L"run.radios.nfc");
Wifi = CkJsonObjectW_IntOf(jResp,L"run.radios.wifi");
Result = CkJsonObjectW_stringOf(jResp,L"run.result");
ResultCode = CkJsonObjectW_stringOf(jResp,L"run.resultCode");
Seed = CkJsonObjectW_IntOf(jResp,L"run.seed");
SkipAppResign = CkJsonObjectW_IntOf(jResp,L"run.skipAppResign");
Started = CkJsonObjectW_IntOf(jResp,L"run.started");
Status = CkJsonObjectW_stringOf(jResp,L"run.status");
runStopped = CkJsonObjectW_IntOf(jResp,L"run.stopped");
TestSpecArn = CkJsonObjectW_stringOf(jResp,L"run.testSpecArn");
TotalJobs = CkJsonObjectW_IntOf(jResp,L"run.totalJobs");
runType = CkJsonObjectW_stringOf(jResp,L"run.type");
WebUrl = CkJsonObjectW_stringOf(jResp,L"run.webUrl");
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"run.customerArtifactPaths.androidPaths");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
strVal = CkJsonObjectW_stringOf(jResp,L"run.customerArtifactPaths.androidPaths[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"run.customerArtifactPaths.deviceHostPaths");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
strVal = CkJsonObjectW_stringOf(jResp,L"run.customerArtifactPaths.deviceHostPaths[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"run.customerArtifactPaths.iosPaths");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
strVal = CkJsonObjectW_stringOf(jResp,L"run.customerArtifactPaths.iosPaths[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"run.deviceSelectionResult.filters");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
attribute = CkJsonObjectW_stringOf(jResp,L"run.deviceSelectionResult.filters[i].attribute");
operator = CkJsonObjectW_stringOf(jResp,L"run.deviceSelectionResult.filters[i].operator");
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"run.deviceSelectionResult.filters[i].values");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
strVal = CkJsonObjectW_stringOf(jResp,L"run.deviceSelectionResult.filters[i].values[j]");
j = j + 1;
}
i = i + 1;
}
// A sample JSON response body parsed by the above code:
// {
// "run": {
// "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);
}