Chilkat Online Tools

ListServers Swift3 Example

Migration Hub Strategy Recommendations

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
    }

    // 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

    let json = CkoJsonObject()!
    json.update("filterValue", value: "string")
    json.update("groupIdFilter[0].name", value: "string")
    json.update("groupIdFilter[0].value", value: "string")
    json.updateInt("maxResults", value: 123)
    json.update("nextToken", value: "string")
    json.update("serverCriteria", value: "string")
    json.update("sort", value: "string")

    // The JSON request body created by the above code:

    // {
    //   "filterValue": "string",
    //   "groupIdFilter": [
    //     {
    //       "name": "string",
    //       "value": "string"
    //     }
    //   ],
    //   "maxResults": number,
    //   "nextToken": "string",
    //   "serverCriteria": "string",
    //   "sort": "string"
    // }

    rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
    rest.addHeader("X-Amz-Target", value: "ListServers")

    let sbRequestBody = CkoStringBuilder()!
    json.emitSb(sbRequestBody)
    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestSb("POST", uriPath: "/list-servers", requestBody: sbRequestBody, responseBody: 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 S3Bucket: String?
    var S3key: String?
    var antipatternReportStatus: String?
    var antipatternReportStatusMessage: String?
    var dataCollectionStatus: String?
    var id: String?
    var lastAnalyzedTimestamp: Int
    var name: String?
    var Strategy: String?
    var TargetDestination: String?
    var Description: String?
    var Name: String?
    var TranformationToolInstallationLink: String?
    var serverType: String?
    var statusMessage: String?
    var CpuArchitecture: String?
    var FileSystemType: String?
    var v_Type: String?
    var Version: String?
    var j: Int
    var count_j: Int
    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.string(of: "nextToken")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "serverInfos").intValue
    while i < count_i {
        jResp.i = i
        S3Bucket = jResp.string(of: "serverInfos[i].antipatternReportS3Object.s3Bucket")
        S3key = jResp.string(of: "serverInfos[i].antipatternReportS3Object.s3key")
        antipatternReportStatus = jResp.string(of: "serverInfos[i].antipatternReportStatus")
        antipatternReportStatusMessage = jResp.string(of: "serverInfos[i].antipatternReportStatusMessage")
        dataCollectionStatus = jResp.string(of: "serverInfos[i].dataCollectionStatus")
        id = jResp.string(of: "serverInfos[i].id")
        lastAnalyzedTimestamp = jResp.int(of: "serverInfos[i].lastAnalyzedTimestamp").intValue
        name = jResp.string(of: "serverInfos[i].name")
        Strategy = jResp.string(of: "serverInfos[i].recommendationSet.strategy")
        TargetDestination = jResp.string(of: "serverInfos[i].recommendationSet.targetDestination")
        Description = jResp.string(of: "serverInfos[i].recommendationSet.transformationTool.description")
        Name = jResp.string(of: "serverInfos[i].recommendationSet.transformationTool.name")
        TranformationToolInstallationLink = jResp.string(of: "serverInfos[i].recommendationSet.transformationTool.tranformationToolInstallationLink")
        serverType = jResp.string(of: "serverInfos[i].serverType")
        statusMessage = jResp.string(of: "serverInfos[i].statusMessage")
        CpuArchitecture = jResp.string(of: "serverInfos[i].systemInfo.cpuArchitecture")
        FileSystemType = jResp.string(of: "serverInfos[i].systemInfo.fileSystemType")
        v_Type = jResp.string(of: "serverInfos[i].systemInfo.osInfo.type")
        Version = jResp.string(of: "serverInfos[i].systemInfo.osInfo.version")
        j = 0
        count_j = jResp.size(ofArray: "serverInfos[i].applicationComponentStrategySummary").intValue
        while j < count_j {
            jResp.j = j
            count = jResp.int(of: "serverInfos[i].applicationComponentStrategySummary[j].count").intValue
            strategy = jResp.string(of: "serverInfos[i].applicationComponentStrategySummary[j].strategy")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "serverInfos[i].listAntipatternSeveritySummary").intValue
        while j < count_j {
            jResp.j = j
            count = jResp.int(of: "serverInfos[i].listAntipatternSeveritySummary[j].count").intValue
            severity = jResp.string(of: "serverInfos[i].listAntipatternSeveritySummary[j].severity")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "serverInfos[i].systemInfo.networkInfoList").intValue
        while j < count_j {
            jResp.j = j
            interfaceName = jResp.string(of: "serverInfos[i].systemInfo.networkInfoList[j].interfaceName")
            ipAddress = jResp.string(of: "serverInfos[i].systemInfo.networkInfoList[j].ipAddress")
            macAddress = jResp.string(of: "serverInfos[i].systemInfo.networkInfoList[j].macAddress")
            netMask = jResp.string(of: "serverInfos[i].systemInfo.networkInfoList[j].netMask")
            j = j + 1
        }

        i = i + 1
    }

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

    // {
    //   "nextToken": "string",
    //   "serverInfos": [
    //     {
    //       "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"
    //         }
    //       }
    //     }
    //   ]
    // }

}