GetServerDetails Swift 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 = "migrationhub-strategy"
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.SetAuthAws(authAws)
// URL: https://migrationhub-strategy.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = rest.Connect("migrationhub-strategy.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: "GetServerDetails")
let sbResponseBody = CkoStringBuilder()
success = rest.FullRequestNoBodySb("GET", uriPath: "/get-server-details/{serverId}", 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 id: String?
var name: String?
var count: Int
var strategy: String?
var severity: String?
var interfaceName: String?
var ipAddress: String?
var macAddress: String?
var netMask: String?
var nextToken: String? = jResp.StringOf("nextToken")
var S3Bucket: String? = jResp.StringOf("serverDetail.antipatternReportS3Object.s3Bucket")
var S3key: String? = jResp.StringOf("serverDetail.antipatternReportS3Object.s3key")
var AntipatternReportStatus: String? = jResp.StringOf("serverDetail.antipatternReportStatus")
var AntipatternReportStatusMessage: String? = jResp.StringOf("serverDetail.antipatternReportStatusMessage")
var DataCollectionStatus: String? = jResp.StringOf("serverDetail.dataCollectionStatus")
var Id: String? = jResp.StringOf("serverDetail.id")
var LastAnalyzedTimestamp: Int = jResp.IntOf("serverDetail.lastAnalyzedTimestamp").intValue
var Name: String? = jResp.StringOf("serverDetail.name")
var Strategy: String? = jResp.StringOf("serverDetail.recommendationSet.strategy")
var TargetDestination: String? = jResp.StringOf("serverDetail.recommendationSet.targetDestination")
var Description: String? = jResp.StringOf("serverDetail.recommendationSet.transformationTool.description")
var TransformationToolName: String? = jResp.StringOf("serverDetail.recommendationSet.transformationTool.name")
var TranformationToolInstallationLink: String? = jResp.StringOf("serverDetail.recommendationSet.transformationTool.tranformationToolInstallationLink")
var ServerType: String? = jResp.StringOf("serverDetail.serverType")
var StatusMessage: String? = jResp.StringOf("serverDetail.statusMessage")
var CpuArchitecture: String? = jResp.StringOf("serverDetail.systemInfo.cpuArchitecture")
var FileSystemType: String? = jResp.StringOf("serverDetail.systemInfo.fileSystemType")
var v_Type: String? = jResp.StringOf("serverDetail.systemInfo.osInfo.type")
var Version: String? = jResp.StringOf("serverDetail.systemInfo.osInfo.version")
var i: Int = 0
var count_i: Int = jResp.SizeOfArray("associatedApplications").intValue
while i < count_i {
jResp.I = i
id = jResp.StringOf("associatedApplications[i].id")
name = jResp.StringOf("associatedApplications[i].name")
i = i + 1
}
i = 0
count_i = jResp.SizeOfArray("serverDetail.applicationComponentStrategySummary").intValue
while i < count_i {
jResp.I = i
count = jResp.IntOf("serverDetail.applicationComponentStrategySummary[i].count").intValue
strategy = jResp.StringOf("serverDetail.applicationComponentStrategySummary[i].strategy")
i = i + 1
}
i = 0
count_i = jResp.SizeOfArray("serverDetail.listAntipatternSeveritySummary").intValue
while i < count_i {
jResp.I = i
count = jResp.IntOf("serverDetail.listAntipatternSeveritySummary[i].count").intValue
severity = jResp.StringOf("serverDetail.listAntipatternSeveritySummary[i].severity")
i = i + 1
}
i = 0
count_i = jResp.SizeOfArray("serverDetail.systemInfo.networkInfoList").intValue
while i < count_i {
jResp.I = i
interfaceName = jResp.StringOf("serverDetail.systemInfo.networkInfoList[i].interfaceName")
ipAddress = jResp.StringOf("serverDetail.systemInfo.networkInfoList[i].ipAddress")
macAddress = jResp.StringOf("serverDetail.systemInfo.networkInfoList[i].macAddress")
netMask = jResp.StringOf("serverDetail.systemInfo.networkInfoList[i].netMask")
i = i + 1
}
// A sample JSON response body parsed by the above code:
// {
// "associatedApplications": [
// {
// "id": "string",
// "name": "string"
// }
// ],
// "nextToken": "string",
// "serverDetail": {
// "antipatternReportS3Object": {
// "s3Bucket": "string",
// "s3key": "string"
// },
// "antipatternReportStatus": "string",
// "antipatternReportStatusMessage": "string",
// "applicationComponentStrategySummary": [
// {
// "count": number,
// "strategy": "string"
// }
// ],
// "dataCollectionStatus": "string",
// "id": "string",
// "lastAnalyzedTimestamp": number,
// "listAntipatternSeveritySummary": [
// {
// "count": number,
// "severity": "string"
// }
// ],
// "name": "string",
// "recommendationSet": {
// "strategy": "string",
// "targetDestination": "string",
// "transformationTool": {
// "description": "string",
// "name": "string",
// "tranformationToolInstallationLink": "string"
// }
// },
// "serverType": "string",
// "statusMessage": "string",
// "systemInfo": {
// "cpuArchitecture": "string",
// "fileSystemType": "string",
// "networkInfoList": [
// {
// "interfaceName": "string",
// "ipAddress": "string",
// "macAddress": "string",
// "netMask": "string"
// }
// ],
// "osInfo": {
// "type": "string",
// "version": "string"
// }
// }
// }
// }
}