Chilkat Online Tools

UpdatePipeline Swift3 Example

AWS CodePipeline

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

    // URL: https://codepipeline.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.connect("codepipeline.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("pipeline.artifactStore.encryptionKey.id", value: "string")
    json.update("pipeline.artifactStore.encryptionKey.type", value: "string")
    json.update("pipeline.artifactStore.location", value: "string")
    json.update("pipeline.artifactStore.type", value: "string")
    json.update("pipeline.artifactStores.string.encryptionKey.id", value: "string")
    json.update("pipeline.artifactStores.string.encryptionKey.type", value: "string")
    json.update("pipeline.artifactStores.string.location", value: "string")
    json.update("pipeline.artifactStores.string.type", value: "string")
    json.update("pipeline.name", value: "string")
    json.update("pipeline.roleArn", value: "string")
    json.update("pipeline.stages[0].actions[0].actionTypeId.category", value: "string")
    json.update("pipeline.stages[0].actions[0].actionTypeId.owner", value: "string")
    json.update("pipeline.stages[0].actions[0].actionTypeId.provider", value: "string")
    json.update("pipeline.stages[0].actions[0].actionTypeId.version", value: "string")
    json.update("pipeline.stages[0].actions[0].configuration.string", value: "string")
    json.update("pipeline.stages[0].actions[0].inputArtifacts[0].name", value: "string")
    json.update("pipeline.stages[0].actions[0].name", value: "string")
    json.update("pipeline.stages[0].actions[0].namespace", value: "string")
    json.update("pipeline.stages[0].actions[0].outputArtifacts[0].name", value: "string")
    json.update("pipeline.stages[0].actions[0].region", value: "string")
    json.update("pipeline.stages[0].actions[0].roleArn", value: "string")
    json.updateInt("pipeline.stages[0].actions[0].runOrder", value: 123)
    json.update("pipeline.stages[0].blockers[0].name", value: "string")
    json.update("pipeline.stages[0].blockers[0].type", value: "string")
    json.update("pipeline.stages[0].name", value: "string")
    json.updateInt("pipeline.version", value: 123)

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

    // {
    //   "pipeline": {
    //     "artifactStore": {
    //       "encryptionKey": {
    //         "id": "string",
    //         "type": "string"
    //       },
    //       "location": "string",
    //       "type": "string"
    //     },
    //     "artifactStores": {
    //       "string": {
    //         "encryptionKey": {
    //           "id": "string",
    //           "type": "string"
    //         },
    //         "location": "string",
    //         "type": "string"
    //       }
    //     },
    //     "name": "string",
    //     "roleArn": "string",
    //     "stages": [
    //       {
    //         "actions": [
    //           {
    //             "actionTypeId": {
    //               "category": "string",
    //               "owner": "string",
    //               "provider": "string",
    //               "version": "string"
    //             },
    //             "configuration": {
    //               "string": "string"
    //             },
    //             "inputArtifacts": [
    //               {
    //                 "name": "string"
    //               }
    //             ],
    //             "name": "string",
    //             "namespace": "string",
    //             "outputArtifacts": [
    //               {
    //                 "name": "string"
    //               }
    //             ],
    //             "region": "string",
    //             "roleArn": "string",
    //             "runOrder": number
    //           }
    //         ],
    //         "blockers": [
    //           {
    //             "name": "string",
    //             "type": "string"
    //           }
    //         ],
    //         "name": "string"
    //       }
    //     ],
    //     "version": number
    //   }
    // }

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

    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 name: String?
    var j: Int
    var count_j: Int
    var Category: String?
    var Owner: String?
    var Provider: String?
    var actionTypeIdVersion: String?
    var v_String: String?
    var namespace: String?
    var region: String?
    var roleArn: String?
    var runOrder: Int
    var k: Int
    var count_k: Int
    var v_type: String?

    var Id: String? = jResp.string(of: "pipeline.artifactStore.encryptionKey.id")
    var v_Type: String? = jResp.string(of: "pipeline.artifactStore.encryptionKey.type")
    var Location: String? = jResp.string(of: "pipeline.artifactStore.location")
    var ArtifactStoreType: String? = jResp.string(of: "pipeline.artifactStore.type")
    var EncryptionKeyId: String? = jResp.string(of: "pipeline.artifactStores.string.encryptionKey.id")
    var EncryptionKeyType: String? = jResp.string(of: "pipeline.artifactStores.string.encryptionKey.type")
    var StringLocation: String? = jResp.string(of: "pipeline.artifactStores.string.location")
    var StringType: String? = jResp.string(of: "pipeline.artifactStores.string.type")
    var Name: String? = jResp.string(of: "pipeline.name")
    var RoleArn: String? = jResp.string(of: "pipeline.roleArn")
    var Version: Int = jResp.int(of: "pipeline.version").intValue
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "pipeline.stages").intValue
    while i < count_i {
        jResp.i = i
        name = jResp.string(of: "pipeline.stages[i].name")
        j = 0
        count_j = jResp.size(ofArray: "pipeline.stages[i].actions").intValue
        while j < count_j {
            jResp.j = j
            Category = jResp.string(of: "pipeline.stages[i].actions[j].actionTypeId.category")
            Owner = jResp.string(of: "pipeline.stages[i].actions[j].actionTypeId.owner")
            Provider = jResp.string(of: "pipeline.stages[i].actions[j].actionTypeId.provider")
            actionTypeIdVersion = jResp.string(of: "pipeline.stages[i].actions[j].actionTypeId.version")
            v_String = jResp.string(of: "pipeline.stages[i].actions[j].configuration.string")
            name = jResp.string(of: "pipeline.stages[i].actions[j].name")
            namespace = jResp.string(of: "pipeline.stages[i].actions[j].namespace")
            region = jResp.string(of: "pipeline.stages[i].actions[j].region")
            roleArn = jResp.string(of: "pipeline.stages[i].actions[j].roleArn")
            runOrder = jResp.int(of: "pipeline.stages[i].actions[j].runOrder").intValue
            k = 0
            count_k = jResp.size(ofArray: "pipeline.stages[i].actions[j].inputArtifacts").intValue
            while k < count_k {
                jResp.k = k
                name = jResp.string(of: "pipeline.stages[i].actions[j].inputArtifacts[k].name")
                k = k + 1
            }

            k = 0
            count_k = jResp.size(ofArray: "pipeline.stages[i].actions[j].outputArtifacts").intValue
            while k < count_k {
                jResp.k = k
                name = jResp.string(of: "pipeline.stages[i].actions[j].outputArtifacts[k].name")
                k = k + 1
            }

            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "pipeline.stages[i].blockers").intValue
        while j < count_j {
            jResp.j = j
            name = jResp.string(of: "pipeline.stages[i].blockers[j].name")
            v_type = jResp.string(of: "pipeline.stages[i].blockers[j].type")
            j = j + 1
        }

        i = i + 1
    }

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

    // {
    //   "pipeline": {
    //     "artifactStore": {
    //       "encryptionKey": {
    //         "id": "string",
    //         "type": "string"
    //       },
    //       "location": "string",
    //       "type": "string"
    //     },
    //     "artifactStores": {
    //       "string": {
    //         "encryptionKey": {
    //           "id": "string",
    //           "type": "string"
    //         },
    //         "location": "string",
    //         "type": "string"
    //       }
    //     },
    //     "name": "string",
    //     "roleArn": "string",
    //     "stages": [
    //       {
    //         "actions": [
    //           {
    //             "actionTypeId": {
    //               "category": "string",
    //               "owner": "string",
    //               "provider": "string",
    //               "version": "string"
    //             },
    //             "configuration": {
    //               "string": "string"
    //             },
    //             "inputArtifacts": [
    //               {
    //                 "name": "string"
    //               }
    //             ],
    //             "name": "string",
    //             "namespace": "string",
    //             "outputArtifacts": [
    //               {
    //                 "name": "string"
    //               }
    //             ],
    //             "region": "string",
    //             "roleArn": "string",
    //             "runOrder": number
    //           }
    //         ],
    //         "blockers": [
    //           {
    //             "name": "string",
    //             "type": "string"
    //           }
    //         ],
    //         "name": "string"
    //       }
    //     ],
    //     "version": number
    //   }
    // }

}