Chilkat Online Tools

CreateApp 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
    }

    // 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("accessToken", value: "string")
    json.update("autoBranchCreationConfig.basicAuthCredentials", value: "string")
    json.update("autoBranchCreationConfig.buildSpec", value: "string")
    json.updateInt("autoBranchCreationConfig.enableAutoBuild", value: 123)
    json.updateInt("autoBranchCreationConfig.enableBasicAuth", value: 123)
    json.updateInt("autoBranchCreationConfig.enablePerformanceMode", value: 123)
    json.updateInt("autoBranchCreationConfig.enablePullRequestPreview", value: 123)
    json.update("autoBranchCreationConfig.environmentVariables.string", value: "string")
    json.update("autoBranchCreationConfig.framework", value: "string")
    json.update("autoBranchCreationConfig.pullRequestEnvironmentName", value: "string")
    json.update("autoBranchCreationConfig.stage", value: "string")
    json.update("autoBranchCreationPatterns[0]", value: "string")
    json.update("basicAuthCredentials", value: "string")
    json.update("buildSpec", value: "string")
    json.update("customHeaders", value: "string")
    json.update("customRules[0].condition", value: "string")
    json.update("customRules[0].source", value: "string")
    json.update("customRules[0].status", value: "string")
    json.update("customRules[0].target", value: "string")
    json.update("description", value: "string")
    json.updateInt("enableAutoBranchCreation", value: 123)
    json.updateInt("enableBasicAuth", value: 123)
    json.updateInt("enableBranchAutoBuild", value: 123)
    json.updateInt("enableBranchAutoDeletion", value: 123)
    json.update("environmentVariables.string", value: "string")
    json.update("iamServiceRoleArn", value: "string")
    json.update("name", value: "string")
    json.update("oauthToken", value: "string")
    json.update("platform", value: "string")
    json.update("repository", value: "string")
    json.update("tags.string", value: "string")

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

    // {
    //   "accessToken": "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",
    //   "customHeaders": "string",
    //   "customRules": [
    //     {
    //       "condition": "string",
    //       "source": "string",
    //       "status": "string",
    //       "target": "string"
    //     }
    //   ],
    //   "description": "string",
    //   "enableAutoBranchCreation": boolean,
    //   "enableBasicAuth": boolean,
    //   "enableBranchAutoBuild": boolean,
    //   "enableBranchAutoDeletion": boolean,
    //   "environmentVariables": {
    //     "string": "string"
    //   },
    //   "iamServiceRoleArn": "string",
    //   "name": "string",
    //   "oauthToken": "string",
    //   "platform": "string",
    //   "repository": "string",
    //   "tags": {
    //     "string": "string"
    //   }
    // }

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

    let sbRequestBody = CkoStringBuilder()!
    json.emitSb(sbRequestBody)
    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestSb("POST", uriPath: "/apps", 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 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
    //   }
    // }

}