Chilkat Online Tools

BatchGetApplicationRevisions 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("applicationName", value: "string")
    json.update("revisions[0].appSpecContent.content", value: "string")
    json.update("revisions[0].appSpecContent.sha256", value: "string")
    json.update("revisions[0].gitHubLocation.commitId", value: "string")
    json.update("revisions[0].gitHubLocation.repository", value: "string")
    json.update("revisions[0].revisionType", value: "string")
    json.update("revisions[0].s3Location.bucket", value: "string")
    json.update("revisions[0].s3Location.bundleType", value: "string")
    json.update("revisions[0].s3Location.eTag", value: "string")
    json.update("revisions[0].s3Location.key", value: "string")
    json.update("revisions[0].s3Location.version", value: "string")
    json.update("revisions[0].string.content", value: "string")
    json.update("revisions[0].string.sha256", value: "string")

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

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

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

    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 Description: String?
    var FirstUsedTime: Int
    var LastUsedTime: Int
    var RegisterTime: 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 j: Int
    var count_j: Int
    var strVal: String?

    var applicationName: String? = jResp.string(of: "applicationName")
    var errorMessage: String? = jResp.string(of: "errorMessage")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "revisions").intValue
    while i < count_i {
        jResp.i = i
        Description = jResp.string(of: "revisions[i].genericRevisionInfo.description")
        FirstUsedTime = jResp.int(of: "revisions[i].genericRevisionInfo.firstUsedTime").intValue
        LastUsedTime = jResp.int(of: "revisions[i].genericRevisionInfo.lastUsedTime").intValue
        RegisterTime = jResp.int(of: "revisions[i].genericRevisionInfo.registerTime").intValue
        Content = jResp.string(of: "revisions[i].revisionLocation.appSpecContent.content")
        Sha256 = jResp.string(of: "revisions[i].revisionLocation.appSpecContent.sha256")
        CommitId = jResp.string(of: "revisions[i].revisionLocation.gitHubLocation.commitId")
        Repository = jResp.string(of: "revisions[i].revisionLocation.gitHubLocation.repository")
        RevisionType = jResp.string(of: "revisions[i].revisionLocation.revisionType")
        Bucket = jResp.string(of: "revisions[i].revisionLocation.s3Location.bucket")
        BundleType = jResp.string(of: "revisions[i].revisionLocation.s3Location.bundleType")
        ETag = jResp.string(of: "revisions[i].revisionLocation.s3Location.eTag")
        Key = jResp.string(of: "revisions[i].revisionLocation.s3Location.key")
        Version = jResp.string(of: "revisions[i].revisionLocation.s3Location.version")
        StringContent = jResp.string(of: "revisions[i].revisionLocation.string.content")
        StringSha256 = jResp.string(of: "revisions[i].revisionLocation.string.sha256")
        j = 0
        count_j = jResp.size(ofArray: "revisions[i].genericRevisionInfo.deploymentGroups").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "revisions[i].genericRevisionInfo.deploymentGroups[j]")
            j = j + 1
        }

        i = i + 1
    }

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

    // {
    //   "applicationName": "string",
    //   "errorMessage": "string",
    //   "revisions": [
    //     {
    //       "genericRevisionInfo": {
    //         "deploymentGroups": [
    //           "string"
    //         ],
    //         "description": "string",
    //         "firstUsedTime": number,
    //         "lastUsedTime": number,
    //         "registerTime": number
    //       },
    //       "revisionLocation": {
    //         "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"
    //         }
    //       }
    //     }
    //   ]
    // }

}