ScheduleRun C Example
#include <C_CkRest.h>
#include <C_CkAuthAws.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>
void ChilkatSample(void)
{
HCkRest rest;
BOOL success;
HCkAuthAws authAws;
HCkJsonObject json;
HCkStringBuilder sbRequestBody;
HCkStringBuilder sbResponseBody;
int respStatusCode;
HCkJsonObject jResp;
const char *strVal;
const char *attribute;
const char *operator;
int j;
int count_j;
const char *AppUpload;
const char *Arn;
const char *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 char *DevicePoolArn;
int MatchedDevicesCount;
int MaxDevices;
int EventCount;
int JobTimeoutMinutes;
const char *Locale;
int Latitude;
int Longitude;
const char *Message;
const char *Name;
const char *NetworkProfileArn;
const char *Description;
int DownlinkBandwidthBits;
int DownlinkDelayMs;
int DownlinkJitterMs;
int DownlinkLossPercent;
const char *NetworkProfileName;
const char *v_Type;
int UplinkBandwidthBits;
int UplinkDelayMs;
int UplinkJitterMs;
int UplinkLossPercent;
const char *ParsingResultUrl;
const char *Platform;
int Bluetooth;
int Gps;
int Nfc;
int Wifi;
const char *Result;
const char *ResultCode;
int Seed;
int SkipAppResign;
int Started;
const char *Status;
int runStopped;
const char *TestSpecArn;
int TotalJobs;
const char *runType;
const char *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 = CkRest_Create();
authAws = CkAuthAws_Create();
CkAuthAws_putAccessKey(authAws,"AWS_ACCESS_KEY");
CkAuthAws_putSecretKey(authAws,"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.)
CkAuthAws_putRegion(authAws,"us-west-2");
CkAuthAws_putServiceName(authAws,"devicefarm");
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest_SetAuthAws(rest,authAws);
// URL: https://devicefarm.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = CkRest_Connect(rest,"devicefarm.us-west-2.amazonaws.com",443,TRUE,TRUE);
if (success != TRUE) {
printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkAuthAws_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 = CkJsonObject_Create();
CkJsonObject_UpdateString(json,"appArn","string");
CkJsonObject_UpdateString(json,"configuration.auxiliaryApps[0]","string");
CkJsonObject_UpdateString(json,"configuration.billingMethod","string");
CkJsonObject_UpdateString(json,"configuration.customerArtifactPaths.androidPaths[0]","string");
CkJsonObject_UpdateString(json,"configuration.customerArtifactPaths.deviceHostPaths[0]","string");
CkJsonObject_UpdateString(json,"configuration.customerArtifactPaths.iosPaths[0]","string");
CkJsonObject_UpdateString(json,"configuration.extraDataPackageArn","string");
CkJsonObject_UpdateString(json,"configuration.locale","string");
CkJsonObject_UpdateInt(json,"configuration.location.latitude",123);
CkJsonObject_UpdateInt(json,"configuration.location.longitude",123);
CkJsonObject_UpdateString(json,"configuration.networkProfileArn","string");
CkJsonObject_UpdateInt(json,"configuration.radios.bluetooth",123);
CkJsonObject_UpdateInt(json,"configuration.radios.gps",123);
CkJsonObject_UpdateInt(json,"configuration.radios.nfc",123);
CkJsonObject_UpdateInt(json,"configuration.radios.wifi",123);
CkJsonObject_UpdateString(json,"configuration.vpceConfigurationArns[0]","string");
CkJsonObject_UpdateString(json,"devicePoolArn","string");
CkJsonObject_UpdateString(json,"deviceSelectionConfiguration.filters[0].attribute","string");
CkJsonObject_UpdateString(json,"deviceSelectionConfiguration.filters[0].operator","string");
CkJsonObject_UpdateString(json,"deviceSelectionConfiguration.filters[0].values[0]","string");
CkJsonObject_UpdateInt(json,"deviceSelectionConfiguration.maxDevices",123);
CkJsonObject_UpdateInt(json,"executionConfiguration.accountsCleanup",123);
CkJsonObject_UpdateInt(json,"executionConfiguration.appPackagesCleanup",123);
CkJsonObject_UpdateInt(json,"executionConfiguration.jobTimeoutMinutes",123);
CkJsonObject_UpdateInt(json,"executionConfiguration.skipAppResign",123);
CkJsonObject_UpdateInt(json,"executionConfiguration.videoCapture",123);
CkJsonObject_UpdateString(json,"name","string");
CkJsonObject_UpdateString(json,"projectArn","string");
CkJsonObject_UpdateString(json,"test.filter","string");
CkJsonObject_UpdateString(json,"test.parameters.string","string");
CkJsonObject_UpdateString(json,"test.testPackageArn","string");
CkJsonObject_UpdateString(json,"test.testSpecArn","string");
CkJsonObject_UpdateString(json,"test.type","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"
// }
// }
CkRest_AddHeader(rest,"Content-Type","application/x-amz-json-1.1");
CkRest_AddHeader(rest,"X-Amz-Target","DeviceFarm_20150623.ScheduleRun");
sbRequestBody = CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);
sbResponseBody = CkStringBuilder_Create();
success = CkRest_FullRequestSb(rest,"POST","/",sbRequestBody,sbResponseBody);
if (success != TRUE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
return;
}
respStatusCode = CkRest_getResponseStatusCode(rest);
printf("response status code = %d\n",respStatusCode);
if (respStatusCode != 200) {
printf("Response Header:\n");
printf("%s\n",CkRest_responseHeader(rest));
printf("Response Body:\n");
printf("%s\n",CkStringBuilder_getAsString(sbResponseBody));
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
return;
}
jResp = CkJsonObject_Create();
CkJsonObject_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 = CkJsonObject_stringOf(jResp,"run.appUpload");
Arn = CkJsonObject_stringOf(jResp,"run.arn");
BillingMethod = CkJsonObject_stringOf(jResp,"run.billingMethod");
CompletedJobs = CkJsonObject_IntOf(jResp,"run.completedJobs");
Errored = CkJsonObject_IntOf(jResp,"run.counters.errored");
Failed = CkJsonObject_IntOf(jResp,"run.counters.failed");
Passed = CkJsonObject_IntOf(jResp,"run.counters.passed");
Skipped = CkJsonObject_IntOf(jResp,"run.counters.skipped");
Stopped = CkJsonObject_IntOf(jResp,"run.counters.stopped");
Total = CkJsonObject_IntOf(jResp,"run.counters.total");
Warned = CkJsonObject_IntOf(jResp,"run.counters.warned");
Created = CkJsonObject_IntOf(jResp,"run.created");
Metered = CkJsonObject_IntOf(jResp,"run.deviceMinutes.metered");
DeviceMinutesTotal = CkJsonObject_IntOf(jResp,"run.deviceMinutes.total");
Unmetered = CkJsonObject_IntOf(jResp,"run.deviceMinutes.unmetered");
DevicePoolArn = CkJsonObject_stringOf(jResp,"run.devicePoolArn");
MatchedDevicesCount = CkJsonObject_IntOf(jResp,"run.deviceSelectionResult.matchedDevicesCount");
MaxDevices = CkJsonObject_IntOf(jResp,"run.deviceSelectionResult.maxDevices");
EventCount = CkJsonObject_IntOf(jResp,"run.eventCount");
JobTimeoutMinutes = CkJsonObject_IntOf(jResp,"run.jobTimeoutMinutes");
Locale = CkJsonObject_stringOf(jResp,"run.locale");
Latitude = CkJsonObject_IntOf(jResp,"run.location.latitude");
Longitude = CkJsonObject_IntOf(jResp,"run.location.longitude");
Message = CkJsonObject_stringOf(jResp,"run.message");
Name = CkJsonObject_stringOf(jResp,"run.name");
NetworkProfileArn = CkJsonObject_stringOf(jResp,"run.networkProfile.arn");
Description = CkJsonObject_stringOf(jResp,"run.networkProfile.description");
DownlinkBandwidthBits = CkJsonObject_IntOf(jResp,"run.networkProfile.downlinkBandwidthBits");
DownlinkDelayMs = CkJsonObject_IntOf(jResp,"run.networkProfile.downlinkDelayMs");
DownlinkJitterMs = CkJsonObject_IntOf(jResp,"run.networkProfile.downlinkJitterMs");
DownlinkLossPercent = CkJsonObject_IntOf(jResp,"run.networkProfile.downlinkLossPercent");
NetworkProfileName = CkJsonObject_stringOf(jResp,"run.networkProfile.name");
v_Type = CkJsonObject_stringOf(jResp,"run.networkProfile.type");
UplinkBandwidthBits = CkJsonObject_IntOf(jResp,"run.networkProfile.uplinkBandwidthBits");
UplinkDelayMs = CkJsonObject_IntOf(jResp,"run.networkProfile.uplinkDelayMs");
UplinkJitterMs = CkJsonObject_IntOf(jResp,"run.networkProfile.uplinkJitterMs");
UplinkLossPercent = CkJsonObject_IntOf(jResp,"run.networkProfile.uplinkLossPercent");
ParsingResultUrl = CkJsonObject_stringOf(jResp,"run.parsingResultUrl");
Platform = CkJsonObject_stringOf(jResp,"run.platform");
Bluetooth = CkJsonObject_IntOf(jResp,"run.radios.bluetooth");
Gps = CkJsonObject_IntOf(jResp,"run.radios.gps");
Nfc = CkJsonObject_IntOf(jResp,"run.radios.nfc");
Wifi = CkJsonObject_IntOf(jResp,"run.radios.wifi");
Result = CkJsonObject_stringOf(jResp,"run.result");
ResultCode = CkJsonObject_stringOf(jResp,"run.resultCode");
Seed = CkJsonObject_IntOf(jResp,"run.seed");
SkipAppResign = CkJsonObject_IntOf(jResp,"run.skipAppResign");
Started = CkJsonObject_IntOf(jResp,"run.started");
Status = CkJsonObject_stringOf(jResp,"run.status");
runStopped = CkJsonObject_IntOf(jResp,"run.stopped");
TestSpecArn = CkJsonObject_stringOf(jResp,"run.testSpecArn");
TotalJobs = CkJsonObject_IntOf(jResp,"run.totalJobs");
runType = CkJsonObject_stringOf(jResp,"run.type");
WebUrl = CkJsonObject_stringOf(jResp,"run.webUrl");
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"run.customerArtifactPaths.androidPaths");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
strVal = CkJsonObject_stringOf(jResp,"run.customerArtifactPaths.androidPaths[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"run.customerArtifactPaths.deviceHostPaths");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
strVal = CkJsonObject_stringOf(jResp,"run.customerArtifactPaths.deviceHostPaths[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"run.customerArtifactPaths.iosPaths");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
strVal = CkJsonObject_stringOf(jResp,"run.customerArtifactPaths.iosPaths[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"run.deviceSelectionResult.filters");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
attribute = CkJsonObject_stringOf(jResp,"run.deviceSelectionResult.filters[i].attribute");
operator = CkJsonObject_stringOf(jResp,"run.deviceSelectionResult.filters[i].operator");
j = 0;
count_j = CkJsonObject_SizeOfArray(jResp,"run.deviceSelectionResult.filters[i].values");
while (j < count_j) {
CkJsonObject_putJ(jResp,j);
strVal = CkJsonObject_stringOf(jResp,"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"
// }
// }
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkJsonObject_Dispose(json);
CkStringBuilder_Dispose(sbRequestBody);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}