Chilkat Online Tools

BatchGetDeployments Swift3 Example

AWS CodeDeploy

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

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

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

    // {
    //   "deploymentIds": [
    //     "string"
    //   ]
    // }

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

    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 additionalDeploymentStatusInfo: String?
    var applicationName: String?
    var Enabled: Int
    var ActionOnTimeout: String?
    var WaitTimeInMinutes: Int
    var Action: String?
    var TerminateBlueInstancesOnDeploymentSuccessAction: String?
    var TerminationWaitTimeInMinutes: Int
    var completeTime: Int
    var computePlatform: String?
    var createTime: Int
    var creator: String?
    var deploymentConfigName: String?
    var deploymentGroupName: String?
    var deploymentId: String?
    var Failed: Int
    var InProgress: Int
    var Pending: Int
    var Ready: Int
    var Skipped: Int
    var Succeeded: Int
    var DeploymentOption: String?
    var DeploymentType: String?
    var description: String?
    var Code: String?
    var Message: String?
    var externalId: String?
    var fileExistsBehavior: String?
    var ignoreApplicationStopFailures: Int
    var instanceTerminationWaitTimeStarted: Int
    var Content: String?
    var Sha256: String?
    var CommitId: String?
    var Repository: String?
    var RevisionType: String?
    var Bucket: String?
    var BundleType: String?
    var ETag: String?
    var Key: String?
    var Version: String?
    var StringContent: String?
    var StringSha256: String?
    var AutoUpdateOutdatedInstancesRootDeploymentId: String?
    var AppSpecContentContent: String?
    var AppSpecContentSha256: String?
    var GitHubLocationCommitId: String?
    var GitHubLocationRepository: String?
    var revisionRevisionType: String?
    var S3LocationBucket: String?
    var S3LocationBundleType: String?
    var S3LocationETag: String?
    var S3LocationKey: String?
    var S3LocationVersion: String?
    var RollbackDeploymentId: String?
    var RollbackMessage: String?
    var RollbackTriggeringDeploymentId: String?
    var startTime: Int
    var status: String?
    var updateOutdatedInstancesOnly: Int
    var j: Int
    var count_j: Int
    var strVal: String?
    var name: String?
    var k: Int
    var count_k: Int
    var v_Type: String?
    var Value: String?

    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "deploymentsInfo").intValue
    while i < count_i {
        jResp.i = i
        additionalDeploymentStatusInfo = jResp.string(of: "deploymentsInfo[i].additionalDeploymentStatusInfo")
        applicationName = jResp.string(of: "deploymentsInfo[i].applicationName")
        Enabled = jResp.int(of: "deploymentsInfo[i].autoRollbackConfiguration.enabled").intValue
        ActionOnTimeout = jResp.string(of: "deploymentsInfo[i].blueGreenDeploymentConfiguration.deploymentReadyOption.actionOnTimeout")
        WaitTimeInMinutes = jResp.int(of: "deploymentsInfo[i].blueGreenDeploymentConfiguration.deploymentReadyOption.waitTimeInMinutes").intValue
        Action = jResp.string(of: "deploymentsInfo[i].blueGreenDeploymentConfiguration.greenFleetProvisioningOption.action")
        TerminateBlueInstancesOnDeploymentSuccessAction = jResp.string(of: "deploymentsInfo[i].blueGreenDeploymentConfiguration.terminateBlueInstancesOnDeploymentSuccess.action")
        TerminationWaitTimeInMinutes = jResp.int(of: "deploymentsInfo[i].blueGreenDeploymentConfiguration.terminateBlueInstancesOnDeploymentSuccess.terminationWaitTimeInMinutes").intValue
        completeTime = jResp.int(of: "deploymentsInfo[i].completeTime").intValue
        computePlatform = jResp.string(of: "deploymentsInfo[i].computePlatform")
        createTime = jResp.int(of: "deploymentsInfo[i].createTime").intValue
        creator = jResp.string(of: "deploymentsInfo[i].creator")
        deploymentConfigName = jResp.string(of: "deploymentsInfo[i].deploymentConfigName")
        deploymentGroupName = jResp.string(of: "deploymentsInfo[i].deploymentGroupName")
        deploymentId = jResp.string(of: "deploymentsInfo[i].deploymentId")
        Failed = jResp.int(of: "deploymentsInfo[i].deploymentOverview.Failed").intValue
        InProgress = jResp.int(of: "deploymentsInfo[i].deploymentOverview.InProgress").intValue
        Pending = jResp.int(of: "deploymentsInfo[i].deploymentOverview.Pending").intValue
        Ready = jResp.int(of: "deploymentsInfo[i].deploymentOverview.Ready").intValue
        Skipped = jResp.int(of: "deploymentsInfo[i].deploymentOverview.Skipped").intValue
        Succeeded = jResp.int(of: "deploymentsInfo[i].deploymentOverview.Succeeded").intValue
        DeploymentOption = jResp.string(of: "deploymentsInfo[i].deploymentStyle.deploymentOption")
        DeploymentType = jResp.string(of: "deploymentsInfo[i].deploymentStyle.deploymentType")
        description = jResp.string(of: "deploymentsInfo[i].description")
        Code = jResp.string(of: "deploymentsInfo[i].errorInformation.code")
        Message = jResp.string(of: "deploymentsInfo[i].errorInformation.message")
        externalId = jResp.string(of: "deploymentsInfo[i].externalId")
        fileExistsBehavior = jResp.string(of: "deploymentsInfo[i].fileExistsBehavior")
        ignoreApplicationStopFailures = jResp.int(of: "deploymentsInfo[i].ignoreApplicationStopFailures").intValue
        instanceTerminationWaitTimeStarted = jResp.int(of: "deploymentsInfo[i].instanceTerminationWaitTimeStarted").intValue
        Content = jResp.string(of: "deploymentsInfo[i].previousRevision.appSpecContent.content")
        Sha256 = jResp.string(of: "deploymentsInfo[i].previousRevision.appSpecContent.sha256")
        CommitId = jResp.string(of: "deploymentsInfo[i].previousRevision.gitHubLocation.commitId")
        Repository = jResp.string(of: "deploymentsInfo[i].previousRevision.gitHubLocation.repository")
        RevisionType = jResp.string(of: "deploymentsInfo[i].previousRevision.revisionType")
        Bucket = jResp.string(of: "deploymentsInfo[i].previousRevision.s3Location.bucket")
        BundleType = jResp.string(of: "deploymentsInfo[i].previousRevision.s3Location.bundleType")
        ETag = jResp.string(of: "deploymentsInfo[i].previousRevision.s3Location.eTag")
        Key = jResp.string(of: "deploymentsInfo[i].previousRevision.s3Location.key")
        Version = jResp.string(of: "deploymentsInfo[i].previousRevision.s3Location.version")
        StringContent = jResp.string(of: "deploymentsInfo[i].previousRevision.string.content")
        StringSha256 = jResp.string(of: "deploymentsInfo[i].previousRevision.string.sha256")
        AutoUpdateOutdatedInstancesRootDeploymentId = jResp.string(of: "deploymentsInfo[i].relatedDeployments.autoUpdateOutdatedInstancesRootDeploymentId")
        AppSpecContentContent = jResp.string(of: "deploymentsInfo[i].revision.appSpecContent.content")
        AppSpecContentSha256 = jResp.string(of: "deploymentsInfo[i].revision.appSpecContent.sha256")
        GitHubLocationCommitId = jResp.string(of: "deploymentsInfo[i].revision.gitHubLocation.commitId")
        GitHubLocationRepository = jResp.string(of: "deploymentsInfo[i].revision.gitHubLocation.repository")
        revisionRevisionType = jResp.string(of: "deploymentsInfo[i].revision.revisionType")
        S3LocationBucket = jResp.string(of: "deploymentsInfo[i].revision.s3Location.bucket")
        S3LocationBundleType = jResp.string(of: "deploymentsInfo[i].revision.s3Location.bundleType")
        S3LocationETag = jResp.string(of: "deploymentsInfo[i].revision.s3Location.eTag")
        S3LocationKey = jResp.string(of: "deploymentsInfo[i].revision.s3Location.key")
        S3LocationVersion = jResp.string(of: "deploymentsInfo[i].revision.s3Location.version")
        StringContent = jResp.string(of: "deploymentsInfo[i].revision.string.content")
        StringSha256 = jResp.string(of: "deploymentsInfo[i].revision.string.sha256")
        RollbackDeploymentId = jResp.string(of: "deploymentsInfo[i].rollbackInfo.rollbackDeploymentId")
        RollbackMessage = jResp.string(of: "deploymentsInfo[i].rollbackInfo.rollbackMessage")
        RollbackTriggeringDeploymentId = jResp.string(of: "deploymentsInfo[i].rollbackInfo.rollbackTriggeringDeploymentId")
        startTime = jResp.int(of: "deploymentsInfo[i].startTime").intValue
        status = jResp.string(of: "deploymentsInfo[i].status")
        updateOutdatedInstancesOnly = jResp.int(of: "deploymentsInfo[i].updateOutdatedInstancesOnly").intValue
        j = 0
        count_j = jResp.size(ofArray: "deploymentsInfo[i].autoRollbackConfiguration.events").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "deploymentsInfo[i].autoRollbackConfiguration.events[j]")
            j = j + 1
        }

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

        j = 0
        count_j = jResp.size(ofArray: "deploymentsInfo[i].loadBalancerInfo.elbInfoList").intValue
        while j < count_j {
            jResp.j = j
            name = jResp.string(of: "deploymentsInfo[i].loadBalancerInfo.elbInfoList[j].name")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "deploymentsInfo[i].loadBalancerInfo.targetGroupInfoList").intValue
        while j < count_j {
            jResp.j = j
            name = jResp.string(of: "deploymentsInfo[i].loadBalancerInfo.targetGroupInfoList[j].name")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "deploymentsInfo[i].loadBalancerInfo.targetGroupPairInfoList").intValue
        while j < count_j {
            jResp.j = j
            k = 0
            count_k = jResp.size(ofArray: "deploymentsInfo[i].loadBalancerInfo.targetGroupPairInfoList[j].prodTrafficRoute.listenerArns").intValue
            while k < count_k {
                jResp.k = k
                strVal = jResp.string(of: "deploymentsInfo[i].loadBalancerInfo.targetGroupPairInfoList[j].prodTrafficRoute.listenerArns[k]")
                k = k + 1
            }

            k = 0
            count_k = jResp.size(ofArray: "deploymentsInfo[i].loadBalancerInfo.targetGroupPairInfoList[j].targetGroups").intValue
            while k < count_k {
                jResp.k = k
                name = jResp.string(of: "deploymentsInfo[i].loadBalancerInfo.targetGroupPairInfoList[j].targetGroups[k].name")
                k = k + 1
            }

            k = 0
            count_k = jResp.size(ofArray: "deploymentsInfo[i].loadBalancerInfo.targetGroupPairInfoList[j].testTrafficRoute.listenerArns").intValue
            while k < count_k {
                jResp.k = k
                strVal = jResp.string(of: "deploymentsInfo[i].loadBalancerInfo.targetGroupPairInfoList[j].testTrafficRoute.listenerArns[k]")
                k = k + 1
            }

            j = j + 1
        }

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

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

        j = 0
        count_j = jResp.size(ofArray: "deploymentsInfo[i].targetInstances.ec2TagSet.ec2TagSetList").intValue
        while j < count_j {
            jResp.j = j
            k = 0
            count_k = jResp.size(ofArray: "deploymentsInfo[i].targetInstances.ec2TagSet.ec2TagSetList[j]").intValue
            while k < count_k {
                jResp.k = k
                Key = jResp.string(of: "deploymentsInfo[i].targetInstances.ec2TagSet.ec2TagSetList[j][k].Key")
                v_Type = jResp.string(of: "deploymentsInfo[i].targetInstances.ec2TagSet.ec2TagSetList[j][k].Type")
                Value = jResp.string(of: "deploymentsInfo[i].targetInstances.ec2TagSet.ec2TagSetList[j][k].Value")
                k = k + 1
            }

            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "deploymentsInfo[i].targetInstances.tagFilters").intValue
        while j < count_j {
            jResp.j = j
            Key = jResp.string(of: "deploymentsInfo[i].targetInstances.tagFilters[j].Key")
            v_Type = jResp.string(of: "deploymentsInfo[i].targetInstances.tagFilters[j].Type")
            Value = jResp.string(of: "deploymentsInfo[i].targetInstances.tagFilters[j].Value")
            j = j + 1
        }

        i = i + 1
    }

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

    // {
    //   "deploymentsInfo": [
    //     {
    //       "additionalDeploymentStatusInfo": "string",
    //       "applicationName": "string",
    //       "autoRollbackConfiguration": {
    //         "enabled": boolean,
    //         "events": [
    //           "string"
    //         ]
    //       },
    //       "blueGreenDeploymentConfiguration": {
    //         "deploymentReadyOption": {
    //           "actionOnTimeout": "string",
    //           "waitTimeInMinutes": number
    //         },
    //         "greenFleetProvisioningOption": {
    //           "action": "string"
    //         },
    //         "terminateBlueInstancesOnDeploymentSuccess": {
    //           "action": "string",
    //           "terminationWaitTimeInMinutes": number
    //         }
    //       },
    //       "completeTime": number,
    //       "computePlatform": "string",
    //       "createTime": number,
    //       "creator": "string",
    //       "deploymentConfigName": "string",
    //       "deploymentGroupName": "string",
    //       "deploymentId": "string",
    //       "deploymentOverview": {
    //         "Failed": number,
    //         "InProgress": number,
    //         "Pending": number,
    //         "Ready": number,
    //         "Skipped": number,
    //         "Succeeded": number
    //       },
    //       "deploymentStatusMessages": [
    //         "string"
    //       ],
    //       "deploymentStyle": {
    //         "deploymentOption": "string",
    //         "deploymentType": "string"
    //       },
    //       "description": "string",
    //       "errorInformation": {
    //         "code": "string",
    //         "message": "string"
    //       },
    //       "externalId": "string",
    //       "fileExistsBehavior": "string",
    //       "ignoreApplicationStopFailures": boolean,
    //       "instanceTerminationWaitTimeStarted": boolean,
    //       "loadBalancerInfo": {
    //         "elbInfoList": [
    //           {
    //             "name": "string"
    //           }
    //         ],
    //         "targetGroupInfoList": [
    //           {
    //             "name": "string"
    //           }
    //         ],
    //         "targetGroupPairInfoList": [
    //           {
    //             "prodTrafficRoute": {
    //               "listenerArns": [
    //                 "string"
    //               ]
    //             },
    //             "targetGroups": [
    //               {
    //                 "name": "string"
    //               }
    //             ],
    //             "testTrafficRoute": {
    //               "listenerArns": [
    //                 "string"
    //               ]
    //             }
    //           }
    //         ]
    //       },
    //       "previousRevision": {
    //         "appSpecContent": {
    //           "content": "string",
    //           "sha256": "string"
    //         },
    //         "gitHubLocation": {
    //           "commitId": "string",
    //           "repository": "string"
    //         },
    //         "revisionType": "string",
    //         "s3Location": {
    //           "bucket": "string",
    //           "bundleType": "string",
    //           "eTag": "string",
    //           "key": "string",
    //           "version": "string"
    //         },
    //         "string": {
    //           "content": "string",
    //           "sha256": "string"
    //         }
    //       },
    //       "relatedDeployments": {
    //         "autoUpdateOutdatedInstancesDeploymentIds": [
    //           "string"
    //         ],
    //         "autoUpdateOutdatedInstancesRootDeploymentId": "string"
    //       },
    //       "revision": {
    //         "appSpecContent": {
    //           "content": "string",
    //           "sha256": "string"
    //         },
    //         "gitHubLocation": {
    //           "commitId": "string",
    //           "repository": "string"
    //         },
    //         "revisionType": "string",
    //         "s3Location": {
    //           "bucket": "string",
    //           "bundleType": "string",
    //           "eTag": "string",
    //           "key": "string",
    //           "version": "string"
    //         },
    //         "string": {
    //           "content": "string",
    //           "sha256": "string"
    //         }
    //       },
    //       "rollbackInfo": {
    //         "rollbackDeploymentId": "string",
    //         "rollbackMessage": "string",
    //         "rollbackTriggeringDeploymentId": "string"
    //       },
    //       "startTime": number,
    //       "status": "string",
    //       "targetInstances": {
    //         "autoScalingGroups": [
    //           "string"
    //         ],
    //         "ec2TagSet": {
    //           "ec2TagSetList": [
    //             [
    //               {
    //                 "Key": "string",
    //                 "Type": "string",
    //                 "Value": "string"
    //               }
    //             ]
    //           ]
    //         },
    //         "tagFilters": [
    //           {
    //             "Key": "string",
    //             "Type": "string",
    //             "Value": "string"
    //           }
    //         ]
    //       },
    //       "updateOutdatedInstancesOnly": boolean
    //     }
    //   ]
    // }

}