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