GetComponent 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 = "imagebuilder"
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.setAuthAws(authAws)
// URL: https://imagebuilder.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = rest.connect("imagebuilder.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: "GetComponent")
let sbResponseBody = CkoStringBuilder()!
success = rest.fullRequestNoBodySb("GET", uriPath: "/GetComponent", 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 description: String?
var name: String?
var v_type: String?
var j: Int
var count_j: Int
var strVal: String?
var Arn: String? = jResp.string(of: "component.arn")
var ChangeDescription: String? = jResp.string(of: "component.changeDescription")
var Data: String? = jResp.string(of: "component.data")
var DateCreated: String? = jResp.string(of: "component.dateCreated")
var Description: String? = jResp.string(of: "component.description")
var Encrypted: Int = jResp.int(of: "component.encrypted").intValue
var KmsKeyId: String? = jResp.string(of: "component.kmsKeyId")
var Name: String? = jResp.string(of: "component.name")
var Owner: String? = jResp.string(of: "component.owner")
var Platform: String? = jResp.string(of: "component.platform")
var Reason: String? = jResp.string(of: "component.state.reason")
var Status: String? = jResp.string(of: "component.state.status")
var v_String: String? = jResp.string(of: "component.tags.string")
var v_Type: String? = jResp.string(of: "component.type")
var Version: String? = jResp.string(of: "component.version")
var requestId: String? = jResp.string(of: "requestId")
var i: Int = 0
var count_i: Int = jResp.size(ofArray: "component.parameters").intValue
while i < count_i {
jResp.i = i
description = jResp.string(of: "component.parameters[i].description")
name = jResp.string(of: "component.parameters[i].name")
v_type = jResp.string(of: "component.parameters[i].type")
j = 0
count_j = jResp.size(ofArray: "component.parameters[i].defaultValue").intValue
while j < count_j {
jResp.j = j
strVal = jResp.string(of: "component.parameters[i].defaultValue[j]")
j = j + 1
}
i = i + 1
}
i = 0
count_i = jResp.size(ofArray: "component.supportedOsVersions").intValue
while i < count_i {
jResp.i = i
strVal = jResp.string(of: "component.supportedOsVersions[i]")
i = i + 1
}
// A sample JSON response body parsed by the above code:
// {
// "component": {
// "arn": "string",
// "changeDescription": "string",
// "data": "string",
// "dateCreated": "string",
// "description": "string",
// "encrypted": boolean,
// "kmsKeyId": "string",
// "name": "string",
// "owner": "string",
// "parameters": [
// {
// "defaultValue": [
// "string"
// ],
// "description": "string",
// "name": "string",
// "type": "string"
// }
// ],
// "platform": "string",
// "state": {
// "reason": "string",
// "status": "string"
// },
// "supportedOsVersions": [
// "string"
// ],
// "tags": {
// "string": "string"
// },
// "type": "string",
// "version": "string"
// },
// "requestId": "string"
// }
}