Chilkat Online Tools

DescribeFleets Swift3 Example

Amazon AppStream

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 = "appstream"
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.setAuthAws(authAws)

    // URL: https://appstream2.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.connect("appstream2.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("Names[0]", value: "string")
    json.update("NextToken", value: "string")

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

    // {
    //   "Names": [
    //     "string"
    //   ],
    //   "NextToken": "string"
    // }

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

    let sbRequestBody = CkoStringBuilder()!
    json.emitSb(sbRequestBody)
    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestSb("POST", uriPath: "/", 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 Arn: String?
    var Available: Int
    var Desired: Int
    var InUse: Int
    var Running: Int
    var CreatedTime: Int
    var Description: String?
    var DisconnectTimeoutInSeconds: Int
    var DisplayName: String?
    var DirectoryName: String?
    var OrganizationalUnitDistinguishedName: String?
    var EnableDefaultInternetAccess: Int
    var FleetType: String?
    var IamRoleArn: String?
    var IdleDisconnectTimeoutInSeconds: Int
    var ImageArn: String?
    var ImageName: String?
    var InstanceType: String?
    var MaxConcurrentSessions: Int
    var MaxUserDurationInSeconds: Int
    var Name: String?
    var Platform: String?
    var S3Bucket: String?
    var S3Key: String?
    var State: String?
    var StreamView: String?
    var j: Int
    var count_j: Int
    var ErrorCode: String?
    var ErrorMessage: String?
    var strVal: String?

    var NextToken: String? = jResp.string(of: "NextToken")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "Fleets").intValue
    while i < count_i {
        jResp.i = i
        Arn = jResp.string(of: "Fleets[i].Arn")
        Available = jResp.int(of: "Fleets[i].ComputeCapacityStatus.Available").intValue
        Desired = jResp.int(of: "Fleets[i].ComputeCapacityStatus.Desired").intValue
        InUse = jResp.int(of: "Fleets[i].ComputeCapacityStatus.InUse").intValue
        Running = jResp.int(of: "Fleets[i].ComputeCapacityStatus.Running").intValue
        CreatedTime = jResp.int(of: "Fleets[i].CreatedTime").intValue
        Description = jResp.string(of: "Fleets[i].Description")
        DisconnectTimeoutInSeconds = jResp.int(of: "Fleets[i].DisconnectTimeoutInSeconds").intValue
        DisplayName = jResp.string(of: "Fleets[i].DisplayName")
        DirectoryName = jResp.string(of: "Fleets[i].DomainJoinInfo.DirectoryName")
        OrganizationalUnitDistinguishedName = jResp.string(of: "Fleets[i].DomainJoinInfo.OrganizationalUnitDistinguishedName")
        EnableDefaultInternetAccess = jResp.int(of: "Fleets[i].EnableDefaultInternetAccess").intValue
        FleetType = jResp.string(of: "Fleets[i].FleetType")
        IamRoleArn = jResp.string(of: "Fleets[i].IamRoleArn")
        IdleDisconnectTimeoutInSeconds = jResp.int(of: "Fleets[i].IdleDisconnectTimeoutInSeconds").intValue
        ImageArn = jResp.string(of: "Fleets[i].ImageArn")
        ImageName = jResp.string(of: "Fleets[i].ImageName")
        InstanceType = jResp.string(of: "Fleets[i].InstanceType")
        MaxConcurrentSessions = jResp.int(of: "Fleets[i].MaxConcurrentSessions").intValue
        MaxUserDurationInSeconds = jResp.int(of: "Fleets[i].MaxUserDurationInSeconds").intValue
        Name = jResp.string(of: "Fleets[i].Name")
        Platform = jResp.string(of: "Fleets[i].Platform")
        S3Bucket = jResp.string(of: "Fleets[i].SessionScriptS3Location.S3Bucket")
        S3Key = jResp.string(of: "Fleets[i].SessionScriptS3Location.S3Key")
        State = jResp.string(of: "Fleets[i].State")
        StreamView = jResp.string(of: "Fleets[i].StreamView")
        j = 0
        count_j = jResp.size(ofArray: "Fleets[i].FleetErrors").intValue
        while j < count_j {
            jResp.j = j
            ErrorCode = jResp.string(of: "Fleets[i].FleetErrors[j].ErrorCode")
            ErrorMessage = jResp.string(of: "Fleets[i].FleetErrors[j].ErrorMessage")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "Fleets[i].UsbDeviceFilterStrings").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "Fleets[i].UsbDeviceFilterStrings[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "Fleets[i].VpcConfig.SecurityGroupIds").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "Fleets[i].VpcConfig.SecurityGroupIds[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "Fleets[i].VpcConfig.SubnetIds").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "Fleets[i].VpcConfig.SubnetIds[j]")
            j = j + 1
        }

        i = i + 1
    }

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

    // {
    //   "Fleets": [
    //     {
    //       "Arn": "string",
    //       "ComputeCapacityStatus": {
    //         "Available": number,
    //         "Desired": number,
    //         "InUse": number,
    //         "Running": number
    //       },
    //       "CreatedTime": number,
    //       "Description": "string",
    //       "DisconnectTimeoutInSeconds": number,
    //       "DisplayName": "string",
    //       "DomainJoinInfo": {
    //         "DirectoryName": "string",
    //         "OrganizationalUnitDistinguishedName": "string"
    //       },
    //       "EnableDefaultInternetAccess": boolean,
    //       "FleetErrors": [
    //         {
    //           "ErrorCode": "string",
    //           "ErrorMessage": "string"
    //         }
    //       ],
    //       "FleetType": "string",
    //       "IamRoleArn": "string",
    //       "IdleDisconnectTimeoutInSeconds": number,
    //       "ImageArn": "string",
    //       "ImageName": "string",
    //       "InstanceType": "string",
    //       "MaxConcurrentSessions": number,
    //       "MaxUserDurationInSeconds": number,
    //       "Name": "string",
    //       "Platform": "string",
    //       "SessionScriptS3Location": {
    //         "S3Bucket": "string",
    //         "S3Key": "string"
    //       },
    //       "State": "string",
    //       "StreamView": "string",
    //       "UsbDeviceFilterStrings": [
    //         "string"
    //       ],
    //       "VpcConfig": {
    //         "SecurityGroupIds": [
    //           "string"
    //         ],
    //         "SubnetIds": [
    //           "string"
    //         ]
    //       }
    //     }
    //   ],
    //   "NextToken": "string"
    // }

}