Chilkat Online Tools

GetJob Objective-C Example

Amazon Braket

#import <CkoRest.h>
#import <CkoAuthAws.h>
#import <CkoStringBuilder.h>
#import <CkoJsonObject.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 = @"braket";
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
[rest SetAuthAws: authAws];

// URL: https://braket.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = [rest Connect: @"braket.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;
}

[rest AddHeader: @"Content-Type" value: @"application/x-amz-json-1.1"];
[rest AddHeader: @"X-Amz-Target" value: @"GetJob"];

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestNoBodySb: @"GET" uriPath: @"/job/{jobArn}" sb: 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 *eventType = 0;
NSString *message = 0;
int timeOfEvent;
NSString *channelName = 0;
NSString *contentType = 0;
NSString *S3DataSourceS3Uri = 0;

NSString *Uri = [jResp StringOf: @"algorithmSpecification.containerImage.uri"];
NSString *CompressionType = [jResp StringOf: @"algorithmSpecification.scriptModeConfig.compressionType"];
NSString *EntryPoint = [jResp StringOf: @"algorithmSpecification.scriptModeConfig.entryPoint"];
NSString *S3Uri = [jResp StringOf: @"algorithmSpecification.scriptModeConfig.s3Uri"];
int billableDuration = [[jResp IntOf: @"billableDuration"] intValue];
NSString *LocalPath = [jResp StringOf: @"checkpointConfig.localPath"];
NSString *checkpointConfigS3Uri = [jResp StringOf: @"checkpointConfig.s3Uri"];
int createdAt = [[jResp IntOf: @"createdAt"] intValue];
NSString *Device = [jResp StringOf: @"deviceConfig.device"];
int endedAt = [[jResp IntOf: @"endedAt"] intValue];
NSString *failureReason = [jResp StringOf: @"failureReason"];
NSString *v_String = [jResp StringOf: @"hyperParameters.string"];
int InstanceCount = [[jResp IntOf: @"instanceConfig.instanceCount"] intValue];
NSString *InstanceType = [jResp StringOf: @"instanceConfig.instanceType"];
int VolumeSizeInGb = [[jResp IntOf: @"instanceConfig.volumeSizeInGb"] intValue];
NSString *jobArn = [jResp StringOf: @"jobArn"];
NSString *jobName = [jResp StringOf: @"jobName"];
NSString *KmsKeyId = [jResp StringOf: @"outputDataConfig.kmsKeyId"];
NSString *S3Path = [jResp StringOf: @"outputDataConfig.s3Path"];
NSString *roleArn = [jResp StringOf: @"roleArn"];
int startedAt = [[jResp IntOf: @"startedAt"] intValue];
NSString *status = [jResp StringOf: @"status"];
int MaxRuntimeInSeconds = [[jResp IntOf: @"stoppingCondition.maxRuntimeInSeconds"] intValue];
NSString *tagsString = [jResp StringOf: @"tags.string"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"events"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    eventType = [jResp StringOf: @"events[i].eventType"];
    message = [jResp StringOf: @"events[i].message"];
    timeOfEvent = [[jResp IntOf: @"events[i].timeOfEvent"] intValue];
    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"inputDataConfig"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    channelName = [jResp StringOf: @"inputDataConfig[i].channelName"];
    contentType = [jResp StringOf: @"inputDataConfig[i].contentType"];
    S3DataSourceS3Uri = [jResp StringOf: @"inputDataConfig[i].dataSource.s3DataSource.s3Uri"];
    i = i + 1;
}

// A sample JSON response body parsed by the above code:

// {
//   "algorithmSpecification": {
//     "containerImage": {
//       "uri": "string"
//     },
//     "scriptModeConfig": {
//       "compressionType": "string",
//       "entryPoint": "string",
//       "s3Uri": "string"
//     }
//   },
//   "billableDuration": number,
//   "checkpointConfig": {
//     "localPath": "string",
//     "s3Uri": "string"
//   },
//   "createdAt": number,
//   "deviceConfig": {
//     "device": "string"
//   },
//   "endedAt": number,
//   "events": [
//     {
//       "eventType": "string",
//       "message": "string",
//       "timeOfEvent": number
//     }
//   ],
//   "failureReason": "string",
//   "hyperParameters": {
//     "string": "string"
//   },
//   "inputDataConfig": [
//     {
//       "channelName": "string",
//       "contentType": "string",
//       "dataSource": {
//         "s3DataSource": {
//           "s3Uri": "string"
//         }
//       }
//     }
//   ],
//   "instanceConfig": {
//     "instanceCount": number,
//     "instanceType": "string",
//     "volumeSizeInGb": number
//   },
//   "jobArn": "string",
//   "jobName": "string",
//   "outputDataConfig": {
//     "kmsKeyId": "string",
//     "s3Path": "string"
//   },
//   "roleArn": "string",
//   "startedAt": number,
//   "status": "string",
//   "stoppingCondition": {
//     "maxRuntimeInSeconds": number
//   },
//   "tags": {
//     "string": "string"
//   }
// }