GetJob Swift3 Example
func chilkatTest() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let rest = CkoRest()!
var success: Bool
let authAws = CkoAuthAws()!
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: 443, tls: true, autoReconnect: true)
if success != true {
print("ConnectFailReason: \(rest.connectFailReason.intValue)")
print("\(rest.lastErrorText!)")
return
}
rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
rest.addHeader("X-Amz-Target", value: "GetJob")
let sbResponseBody = CkoStringBuilder()!
success = rest.fullRequestNoBodySb("GET", uriPath: "/job/{jobArn}", sb: sbResponseBody)
if success != true {
print("\(rest.lastErrorText!)")
return
}
var respStatusCode: Int = rest.responseStatusCode.intValue
print("response status code = \(respStatusCode)")
if respStatusCode != 200 {
print("Response Header:")
print("\(rest.responseHeader!)")
print("Response Body:")
print("\(sbResponseBody.getAsString()!)")
return
}
let jResp = CkoJsonObject()!
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
var eventType: String?
var message: String?
var timeOfEvent: Int
var channelName: String?
var contentType: String?
var S3DataSourceS3Uri: String?
var Uri: String? = jResp.string(of: "algorithmSpecification.containerImage.uri")
var CompressionType: String? = jResp.string(of: "algorithmSpecification.scriptModeConfig.compressionType")
var EntryPoint: String? = jResp.string(of: "algorithmSpecification.scriptModeConfig.entryPoint")
var S3Uri: String? = jResp.string(of: "algorithmSpecification.scriptModeConfig.s3Uri")
var billableDuration: Int = jResp.int(of: "billableDuration").intValue
var LocalPath: String? = jResp.string(of: "checkpointConfig.localPath")
var checkpointConfigS3Uri: String? = jResp.string(of: "checkpointConfig.s3Uri")
var createdAt: Int = jResp.int(of: "createdAt").intValue
var Device: String? = jResp.string(of: "deviceConfig.device")
var endedAt: Int = jResp.int(of: "endedAt").intValue
var failureReason: String? = jResp.string(of: "failureReason")
var v_String: String? = jResp.string(of: "hyperParameters.string")
var InstanceCount: Int = jResp.int(of: "instanceConfig.instanceCount").intValue
var InstanceType: String? = jResp.string(of: "instanceConfig.instanceType")
var VolumeSizeInGb: Int = jResp.int(of: "instanceConfig.volumeSizeInGb").intValue
var jobArn: String? = jResp.string(of: "jobArn")
var jobName: String? = jResp.string(of: "jobName")
var KmsKeyId: String? = jResp.string(of: "outputDataConfig.kmsKeyId")
var S3Path: String? = jResp.string(of: "outputDataConfig.s3Path")
var roleArn: String? = jResp.string(of: "roleArn")
var startedAt: Int = jResp.int(of: "startedAt").intValue
var status: String? = jResp.string(of: "status")
var MaxRuntimeInSeconds: Int = jResp.int(of: "stoppingCondition.maxRuntimeInSeconds").intValue
var tagsString: String? = jResp.string(of: "tags.string")
var i: Int = 0
var count_i: Int = jResp.size(ofArray: "events").intValue
while i < count_i {
jResp.i = i
eventType = jResp.string(of: "events[i].eventType")
message = jResp.string(of: "events[i].message")
timeOfEvent = jResp.int(of: "events[i].timeOfEvent").intValue
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "inputDataConfig").intValue
while i < count_i {
jResp.i = i
channelName = jResp.string(of: "inputDataConfig[i].channelName")
contentType = jResp.string(of: "inputDataConfig[i].contentType")
S3DataSourceS3Uri = jResp.string(of: "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"
// }
// }
}