Chilkat Online Tools

DeleteApp 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: "DeleteApp")

    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestNoBodySb("DELETE", uriPath: "/apps/{appId}", 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 strVal: String?
    var condition: String?
    var source: String?
    var status: String?
    var target: String?

    var AppArn: String? = jResp.string(of: "app.appArn")
    var AppId: String? = jResp.string(of: "app.appId")
    var BasicAuthCredentials: String? = jResp.string(of: "app.autoBranchCreationConfig.basicAuthCredentials")
    var BuildSpec: String? = jResp.string(of: "app.autoBranchCreationConfig.buildSpec")
    var EnableAutoBuild: Int = jResp.int(of: "app.autoBranchCreationConfig.enableAutoBuild").intValue
    var EnableBasicAuth: Int = jResp.int(of: "app.autoBranchCreationConfig.enableBasicAuth").intValue
    var EnablePerformanceMode: Int = jResp.int(of: "app.autoBranchCreationConfig.enablePerformanceMode").intValue
    var EnablePullRequestPreview: Int = jResp.int(of: "app.autoBranchCreationConfig.enablePullRequestPreview").intValue
    var v_String: String? = jResp.string(of: "app.autoBranchCreationConfig.environmentVariables.string")
    var Framework: String? = jResp.string(of: "app.autoBranchCreationConfig.framework")
    var PullRequestEnvironmentName: String? = jResp.string(of: "app.autoBranchCreationConfig.pullRequestEnvironmentName")
    var Stage: String? = jResp.string(of: "app.autoBranchCreationConfig.stage")
    var appBasicAuthCredentials: String? = jResp.string(of: "app.basicAuthCredentials")
    var appBuildSpec: String? = jResp.string(of: "app.buildSpec")
    var CreateTime: Int = jResp.int(of: "app.createTime").intValue
    var CustomHeaders: String? = jResp.string(of: "app.customHeaders")
    var DefaultDomain: String? = jResp.string(of: "app.defaultDomain")
    var Description: String? = jResp.string(of: "app.description")
    var EnableAutoBranchCreation: Int = jResp.int(of: "app.enableAutoBranchCreation").intValue
    var appEnableBasicAuth: Int = jResp.int(of: "app.enableBasicAuth").intValue
    var EnableBranchAutoBuild: Int = jResp.int(of: "app.enableBranchAutoBuild").intValue
    var EnableBranchAutoDeletion: Int = jResp.int(of: "app.enableBranchAutoDeletion").intValue
    var EnvironmentVariablesString: String? = jResp.string(of: "app.environmentVariables.string")
    var IamServiceRoleArn: String? = jResp.string(of: "app.iamServiceRoleArn")
    var Name: String? = jResp.string(of: "app.name")
    var Platform: String? = jResp.string(of: "app.platform")
    var BranchName: String? = jResp.string(of: "app.productionBranch.branchName")
    var LastDeployTime: Int = jResp.int(of: "app.productionBranch.lastDeployTime").intValue
    var Status: String? = jResp.string(of: "app.productionBranch.status")
    var ThumbnailUrl: String? = jResp.string(of: "app.productionBranch.thumbnailUrl")
    var Repository: String? = jResp.string(of: "app.repository")
    var RepositoryCloneMethod: String? = jResp.string(of: "app.repositoryCloneMethod")
    var TagsString: String? = jResp.string(of: "app.tags.string")
    var UpdateTime: Int = jResp.int(of: "app.updateTime").intValue
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "app.autoBranchCreationPatterns").intValue
    while i < count_i {
        jResp.i = i
        strVal = jResp.string(of: "app.autoBranchCreationPatterns[i]")
        i = i + 1
    }

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

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

    // {
    //   "app": {
    //     "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
    //   }
    // }

}