Chilkat Online Tools

ListApps Swift3 Example

Amplify

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

    // URL: https://amplify.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.connect("amplify.us-west-2.amazonaws.com", port: 443, tls: true, autoReconnect: true)
    if success != true {
        print("ConnectFailReason: \(rest.connectFailReason.intValue)")
        print("\(rest.lastErrorText!)")
        return
    }

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

    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestNoBodySb("GET", uriPath: "/apps", sb: 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 appArn: String?
    var appId: String?
    var BasicAuthCredentials: String?
    var BuildSpec: String?
    var EnableAutoBuild: Int
    var EnableBasicAuth: Int
    var EnablePerformanceMode: Int
    var EnablePullRequestPreview: Int
    var v_String: String?
    var Framework: String?
    var PullRequestEnvironmentName: String?
    var Stage: String?
    var basicAuthCredentials: String?
    var buildSpec: String?
    var createTime: Int
    var customHeaders: String?
    var defaultDomain: String?
    var description: String?
    var enableAutoBranchCreation: Int
    var enableBasicAuth: Int
    var enableBranchAutoBuild: Int
    var enableBranchAutoDeletion: Int
    var environmentVariablesString: String?
    var iamServiceRoleArn: String?
    var name: String?
    var platform: String?
    var BranchName: String?
    var LastDeployTime: Int
    var Status: String?
    var ThumbnailUrl: String?
    var repository: String?
    var repositoryCloneMethod: String?
    var tagsString: String?
    var updateTime: Int
    var j: Int
    var count_j: Int
    var strVal: String?
    var condition: String?
    var source: String?
    var status: String?
    var target: String?

    var nextToken: String? = jResp.string(of: "nextToken")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "apps").intValue
    while i < count_i {
        jResp.i = i
        appArn = jResp.string(of: "apps[i].appArn")
        appId = jResp.string(of: "apps[i].appId")
        BasicAuthCredentials = jResp.string(of: "apps[i].autoBranchCreationConfig.basicAuthCredentials")
        BuildSpec = jResp.string(of: "apps[i].autoBranchCreationConfig.buildSpec")
        EnableAutoBuild = jResp.int(of: "apps[i].autoBranchCreationConfig.enableAutoBuild").intValue
        EnableBasicAuth = jResp.int(of: "apps[i].autoBranchCreationConfig.enableBasicAuth").intValue
        EnablePerformanceMode = jResp.int(of: "apps[i].autoBranchCreationConfig.enablePerformanceMode").intValue
        EnablePullRequestPreview = jResp.int(of: "apps[i].autoBranchCreationConfig.enablePullRequestPreview").intValue
        v_String = jResp.string(of: "apps[i].autoBranchCreationConfig.environmentVariables.string")
        Framework = jResp.string(of: "apps[i].autoBranchCreationConfig.framework")
        PullRequestEnvironmentName = jResp.string(of: "apps[i].autoBranchCreationConfig.pullRequestEnvironmentName")
        Stage = jResp.string(of: "apps[i].autoBranchCreationConfig.stage")
        basicAuthCredentials = jResp.string(of: "apps[i].basicAuthCredentials")
        buildSpec = jResp.string(of: "apps[i].buildSpec")
        createTime = jResp.int(of: "apps[i].createTime").intValue
        customHeaders = jResp.string(of: "apps[i].customHeaders")
        defaultDomain = jResp.string(of: "apps[i].defaultDomain")
        description = jResp.string(of: "apps[i].description")
        enableAutoBranchCreation = jResp.int(of: "apps[i].enableAutoBranchCreation").intValue
        enableBasicAuth = jResp.int(of: "apps[i].enableBasicAuth").intValue
        enableBranchAutoBuild = jResp.int(of: "apps[i].enableBranchAutoBuild").intValue
        enableBranchAutoDeletion = jResp.int(of: "apps[i].enableBranchAutoDeletion").intValue
        environmentVariablesString = jResp.string(of: "apps[i].environmentVariables.string")
        iamServiceRoleArn = jResp.string(of: "apps[i].iamServiceRoleArn")
        name = jResp.string(of: "apps[i].name")
        platform = jResp.string(of: "apps[i].platform")
        BranchName = jResp.string(of: "apps[i].productionBranch.branchName")
        LastDeployTime = jResp.int(of: "apps[i].productionBranch.lastDeployTime").intValue
        Status = jResp.string(of: "apps[i].productionBranch.status")
        ThumbnailUrl = jResp.string(of: "apps[i].productionBranch.thumbnailUrl")
        repository = jResp.string(of: "apps[i].repository")
        repositoryCloneMethod = jResp.string(of: "apps[i].repositoryCloneMethod")
        tagsString = jResp.string(of: "apps[i].tags.string")
        updateTime = jResp.int(of: "apps[i].updateTime").intValue
        j = 0
        count_j = jResp.size(ofArray: "apps[i].autoBranchCreationPatterns").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "apps[i].autoBranchCreationPatterns[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "apps[i].customRules").intValue
        while j < count_j {
            jResp.j = j
            condition = jResp.string(of: "apps[i].customRules[j].condition")
            source = jResp.string(of: "apps[i].customRules[j].source")
            status = jResp.string(of: "apps[i].customRules[j].status")
            target = jResp.string(of: "apps[i].customRules[j].target")
            j = j + 1
        }

        i = i + 1
    }

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

    // {
    //   "apps": [
    //     {
    //       "appArn": "string",
    //       "appId": "string",
    //       "autoBranchCreationConfig": {
    //         "basicAuthCredentials": "string",
    //         "buildSpec": "string",
    //         "enableAutoBuild": boolean,
    //         "enableBasicAuth": boolean,
    //         "enablePerformanceMode": boolean,
    //         "enablePullRequestPreview": boolean,
    //         "environmentVariables": {
    //           "string": "string"
    //         },
    //         "framework": "string",
    //         "pullRequestEnvironmentName": "string",
    //         "stage": "string"
    //       },
    //       "autoBranchCreationPatterns": [
    //         "string"
    //       ],
    //       "basicAuthCredentials": "string",
    //       "buildSpec": "string",
    //       "createTime": number,
    //       "customHeaders": "string",
    //       "customRules": [
    //         {
    //           "condition": "string",
    //           "source": "string",
    //           "status": "string",
    //           "target": "string"
    //         }
    //       ],
    //       "defaultDomain": "string",
    //       "description": "string",
    //       "enableAutoBranchCreation": boolean,
    //       "enableBasicAuth": boolean,
    //       "enableBranchAutoBuild": boolean,
    //       "enableBranchAutoDeletion": boolean,
    //       "environmentVariables": {
    //         "string": "string"
    //       },
    //       "iamServiceRoleArn": "string",
    //       "name": "string",
    //       "platform": "string",
    //       "productionBranch": {
    //         "branchName": "string",
    //         "lastDeployTime": number,
    //         "status": "string",
    //         "thumbnailUrl": "string"
    //       },
    //       "repository": "string",
    //       "repositoryCloneMethod": "string",
    //       "tags": {
    //         "string": "string"
    //       },
    //       "updateTime": number
    //     }
    //   ],
    //   "nextToken": "string"
    // }

}