GetRun Objective-C Example
#import <CkoRest.h>
#import <CkoAuthAws.h>
#import <CkoJsonObject.h>
#import <CkoStringBuilder.h>
#import <NSString.h>
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkoRest *rest = [[CkoRest alloc] init];
BOOL success;
CkoAuthAws *authAws = [[CkoAuthAws alloc] init];
authAws.AccessKey = @"AWS_ACCESS_KEY";
authAws.SecretKey = @"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.Region = @"us-west-2";
authAws.ServiceName = @"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: @"devicefarm.us-west-2.amazonaws.com" port: [NSNumber numberWithInt: 443] tls: YES autoReconnect: YES];
if (success != YES) {
NSLog(@"%@%d",@"ConnectFailReason: ",[rest.ConnectFailReason intValue]);
NSLog(@"%@",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
CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"arn" value: @"string"];
// The JSON request body created by the above code:
// {
// "arn": "string"
// }
[rest AddHeader: @"Content-Type" value: @"application/x-amz-json-1.1"];
[rest AddHeader: @"X-Amz-Target" value: @"DeviceFarm_20150623.GetRun"];
CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[json EmitSb: sbRequestBody];
CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestSb: @"POST" uriPath: @"/" requestBody: sbRequestBody responseBody: sbResponseBody];
if (success != YES) {
NSLog(@"%@",rest.LastErrorText);
return;
}
int respStatusCode = [rest.ResponseStatusCode intValue];
NSLog(@"%@%d",@"response status code = ",respStatusCode);
if (respStatusCode != 200) {
NSLog(@"%@",@"Response Header:");
NSLog(@"%@",rest.ResponseHeader);
NSLog(@"%@",@"Response Body:");
NSLog(@"%@",[sbResponseBody GetAsString]);
return;
}
CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[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
NSString *strVal = 0;
NSString *attribute = 0;
NSString *operator = 0;
int j;
int count_j;
NSString *AppUpload = [jResp StringOf: @"run.appUpload"];
NSString *Arn = [jResp StringOf: @"run.arn"];
NSString *BillingMethod = [jResp StringOf: @"run.billingMethod"];
int CompletedJobs = [[jResp IntOf: @"run.completedJobs"] intValue];
int Errored = [[jResp IntOf: @"run.counters.errored"] intValue];
int Failed = [[jResp IntOf: @"run.counters.failed"] intValue];
int Passed = [[jResp IntOf: @"run.counters.passed"] intValue];
int Skipped = [[jResp IntOf: @"run.counters.skipped"] intValue];
int Stopped = [[jResp IntOf: @"run.counters.stopped"] intValue];
int Total = [[jResp IntOf: @"run.counters.total"] intValue];
int Warned = [[jResp IntOf: @"run.counters.warned"] intValue];
int Created = [[jResp IntOf: @"run.created"] intValue];
int Metered = [[jResp IntOf: @"run.deviceMinutes.metered"] intValue];
int DeviceMinutesTotal = [[jResp IntOf: @"run.deviceMinutes.total"] intValue];
int Unmetered = [[jResp IntOf: @"run.deviceMinutes.unmetered"] intValue];
NSString *DevicePoolArn = [jResp StringOf: @"run.devicePoolArn"];
int MatchedDevicesCount = [[jResp IntOf: @"run.deviceSelectionResult.matchedDevicesCount"] intValue];
int MaxDevices = [[jResp IntOf: @"run.deviceSelectionResult.maxDevices"] intValue];
int EventCount = [[jResp IntOf: @"run.eventCount"] intValue];
int JobTimeoutMinutes = [[jResp IntOf: @"run.jobTimeoutMinutes"] intValue];
NSString *Locale = [jResp StringOf: @"run.locale"];
int Latitude = [[jResp IntOf: @"run.location.latitude"] intValue];
int Longitude = [[jResp IntOf: @"run.location.longitude"] intValue];
NSString *Message = [jResp StringOf: @"run.message"];
NSString *Name = [jResp StringOf: @"run.name"];
NSString *NetworkProfileArn = [jResp StringOf: @"run.networkProfile.arn"];
NSString *Description = [jResp StringOf: @"run.networkProfile.description"];
int DownlinkBandwidthBits = [[jResp IntOf: @"run.networkProfile.downlinkBandwidthBits"] intValue];
int DownlinkDelayMs = [[jResp IntOf: @"run.networkProfile.downlinkDelayMs"] intValue];
int DownlinkJitterMs = [[jResp IntOf: @"run.networkProfile.downlinkJitterMs"] intValue];
int DownlinkLossPercent = [[jResp IntOf: @"run.networkProfile.downlinkLossPercent"] intValue];
NSString *NetworkProfileName = [jResp StringOf: @"run.networkProfile.name"];
NSString *v_Type = [jResp StringOf: @"run.networkProfile.type"];
int UplinkBandwidthBits = [[jResp IntOf: @"run.networkProfile.uplinkBandwidthBits"] intValue];
int UplinkDelayMs = [[jResp IntOf: @"run.networkProfile.uplinkDelayMs"] intValue];
int UplinkJitterMs = [[jResp IntOf: @"run.networkProfile.uplinkJitterMs"] intValue];
int UplinkLossPercent = [[jResp IntOf: @"run.networkProfile.uplinkLossPercent"] intValue];
NSString *ParsingResultUrl = [jResp StringOf: @"run.parsingResultUrl"];
NSString *Platform = [jResp StringOf: @"run.platform"];
int Bluetooth = [[jResp IntOf: @"run.radios.bluetooth"] intValue];
int Gps = [[jResp IntOf: @"run.radios.gps"] intValue];
int Nfc = [[jResp IntOf: @"run.radios.nfc"] intValue];
int Wifi = [[jResp IntOf: @"run.radios.wifi"] intValue];
NSString *Result = [jResp StringOf: @"run.result"];
NSString *ResultCode = [jResp StringOf: @"run.resultCode"];
int Seed = [[jResp IntOf: @"run.seed"] intValue];
int SkipAppResign = [[jResp IntOf: @"run.skipAppResign"] intValue];
int Started = [[jResp IntOf: @"run.started"] intValue];
NSString *Status = [jResp StringOf: @"run.status"];
int runStopped = [[jResp IntOf: @"run.stopped"] intValue];
NSString *TestSpecArn = [jResp StringOf: @"run.testSpecArn"];
int TotalJobs = [[jResp IntOf: @"run.totalJobs"] intValue];
NSString *runType = [jResp StringOf: @"run.type"];
NSString *WebUrl = [jResp StringOf: @"run.webUrl"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"run.customerArtifactPaths.androidPaths"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: i];
strVal = [jResp StringOf: @"run.customerArtifactPaths.androidPaths[i]"];
i = i + 1;
}
i = 0;
count_i = [[jResp SizeOfArray: @"run.customerArtifactPaths.deviceHostPaths"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: i];
strVal = [jResp StringOf: @"run.customerArtifactPaths.deviceHostPaths[i]"];
i = i + 1;
}
i = 0;
count_i = [[jResp SizeOfArray: @"run.customerArtifactPaths.iosPaths"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: i];
strVal = [jResp StringOf: @"run.customerArtifactPaths.iosPaths[i]"];
i = i + 1;
}
i = 0;
count_i = [[jResp SizeOfArray: @"run.deviceSelectionResult.filters"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: i];
attribute = [jResp StringOf: @"run.deviceSelectionResult.filters[i].attribute"];
operator = [jResp StringOf: @"run.deviceSelectionResult.filters[i].operator"];
j = 0;
count_j = [[jResp SizeOfArray: @"run.deviceSelectionResult.filters[i].values"] intValue];
while (j < count_j) {
jResp.J = [NSNumber numberWithInt: j];
strVal = [jResp StringOf: @"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"
// }
// }