Chilkat Online Tools

ListActionTypes 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("actionOwnerFilter", value: "string")
    json.update("nextToken", value: "string")
    json.update("regionFilter", value: "string")

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

    // {
    //   "actionOwnerFilter": "string",
    //   "nextToken": "string",
    //   "regionFilter": "string"
    // }

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

    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 Category: String?
    var Owner: String?
    var Provider: String?
    var Version: String?
    var MaximumCount: Int
    var MinimumCount: Int
    var outputArtifactDetailsMaximumCount: Int
    var outputArtifactDetailsMinimumCount: Int
    var EntityUrlTemplate: String?
    var ExecutionUrlTemplate: String?
    var RevisionUrlTemplate: String?
    var ThirdPartyConfigurationUrl: String?
    var j: Int
    var count_j: Int
    var description: String?
    var key: Int
    var name: String?
    var queryable: Int
    var required: Int
    var secret: Int
    var v_type: String?

    var nextToken: String? = jResp.string(of: "nextToken")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "actionTypes").intValue
    while i < count_i {
        jResp.i = i
        Category = jResp.string(of: "actionTypes[i].id.category")
        Owner = jResp.string(of: "actionTypes[i].id.owner")
        Provider = jResp.string(of: "actionTypes[i].id.provider")
        Version = jResp.string(of: "actionTypes[i].id.version")
        MaximumCount = jResp.int(of: "actionTypes[i].inputArtifactDetails.maximumCount").intValue
        MinimumCount = jResp.int(of: "actionTypes[i].inputArtifactDetails.minimumCount").intValue
        outputArtifactDetailsMaximumCount = jResp.int(of: "actionTypes[i].outputArtifactDetails.maximumCount").intValue
        outputArtifactDetailsMinimumCount = jResp.int(of: "actionTypes[i].outputArtifactDetails.minimumCount").intValue
        EntityUrlTemplate = jResp.string(of: "actionTypes[i].settings.entityUrlTemplate")
        ExecutionUrlTemplate = jResp.string(of: "actionTypes[i].settings.executionUrlTemplate")
        RevisionUrlTemplate = jResp.string(of: "actionTypes[i].settings.revisionUrlTemplate")
        ThirdPartyConfigurationUrl = jResp.string(of: "actionTypes[i].settings.thirdPartyConfigurationUrl")
        j = 0
        count_j = jResp.size(ofArray: "actionTypes[i].actionConfigurationProperties").intValue
        while j < count_j {
            jResp.j = j
            description = jResp.string(of: "actionTypes[i].actionConfigurationProperties[j].description")
            key = jResp.int(of: "actionTypes[i].actionConfigurationProperties[j].key").intValue
            name = jResp.string(of: "actionTypes[i].actionConfigurationProperties[j].name")
            queryable = jResp.int(of: "actionTypes[i].actionConfigurationProperties[j].queryable").intValue
            required = jResp.int(of: "actionTypes[i].actionConfigurationProperties[j].required").intValue
            secret = jResp.int(of: "actionTypes[i].actionConfigurationProperties[j].secret").intValue
            v_type = jResp.string(of: "actionTypes[i].actionConfigurationProperties[j].type")
            j = j + 1
        }

        i = i + 1
    }

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

    // {
    //   "actionTypes": [
    //     {
    //       "actionConfigurationProperties": [
    //         {
    //           "description": "string",
    //           "key": boolean,
    //           "name": "string",
    //           "queryable": boolean,
    //           "required": boolean,
    //           "secret": boolean,
    //           "type": "string"
    //         }
    //       ],
    //       "id": {
    //         "category": "string",
    //         "owner": "string",
    //         "provider": "string",
    //         "version": "string"
    //       },
    //       "inputArtifactDetails": {
    //         "maximumCount": number,
    //         "minimumCount": number
    //       },
    //       "outputArtifactDetails": {
    //         "maximumCount": number,
    //         "minimumCount": number
    //       },
    //       "settings": {
    //         "entityUrlTemplate": "string",
    //         "executionUrlTemplate": "string",
    //         "revisionUrlTemplate": "string",
    //         "thirdPartyConfigurationUrl": "string"
    //       }
    //     }
    //   ],
    //   "nextToken": "string"
    // }

}