UpdateApp Swift Example
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.UpdateString("accessToken", value: "string")
json.UpdateString("autoBranchCreationConfig.basicAuthCredentials", value: "string")
json.UpdateString("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.UpdateString("autoBranchCreationConfig.environmentVariables.string", value: "string")
json.UpdateString("autoBranchCreationConfig.framework", value: "string")
json.UpdateString("autoBranchCreationConfig.pullRequestEnvironmentName", value: "string")
json.UpdateString("autoBranchCreationConfig.stage", value: "string")
json.UpdateString("autoBranchCreationPatterns[0]", value: "string")
json.UpdateString("basicAuthCredentials", value: "string")
json.UpdateString("buildSpec", value: "string")
json.UpdateString("customHeaders", value: "string")
json.UpdateString("customRules[0].condition", value: "string")
json.UpdateString("customRules[0].source", value: "string")
json.UpdateString("customRules[0].status", value: "string")
json.UpdateString("customRules[0].target", value: "string")
json.UpdateString("description", value: "string")
json.UpdateInt("enableAutoBranchCreation", value: 123)
json.UpdateInt("enableBasicAuth", value: 123)
json.UpdateInt("enableBranchAutoBuild", value: 123)
json.UpdateInt("enableBranchAutoDeletion", value: 123)
json.UpdateString("environmentVariables.string", value: "string")
json.UpdateString("iamServiceRoleArn", value: "string")
json.UpdateString("name", value: "string")
json.UpdateString("oauthToken", value: "string")
json.UpdateString("platform", value: "string")
json.UpdateString("repository", 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"
// }
rest.AddHeader("Content-Type", value: "application/x-amz-json-1.1")
rest.AddHeader("X-Amz-Target", value: "UpdateApp")
let sbRequestBody = CkoStringBuilder()
json.EmitSb(sbRequestBody)
let sbResponseBody = CkoStringBuilder()
success = rest.FullRequestSb("POST", uriPath: "/apps/{appId}", 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.StringOf("app.appArn")
var AppId: String? = jResp.StringOf("app.appId")
var BasicAuthCredentials: String? = jResp.StringOf("app.autoBranchCreationConfig.basicAuthCredentials")
var BuildSpec: String? = jResp.StringOf("app.autoBranchCreationConfig.buildSpec")
var EnableAutoBuild: Int = jResp.IntOf("app.autoBranchCreationConfig.enableAutoBuild").intValue
var EnableBasicAuth: Int = jResp.IntOf("app.autoBranchCreationConfig.enableBasicAuth").intValue
var EnablePerformanceMode: Int = jResp.IntOf("app.autoBranchCreationConfig.enablePerformanceMode").intValue
var EnablePullRequestPreview: Int = jResp.IntOf("app.autoBranchCreationConfig.enablePullRequestPreview").intValue
var v_String: String? = jResp.StringOf("app.autoBranchCreationConfig.environmentVariables.string")
var Framework: String? = jResp.StringOf("app.autoBranchCreationConfig.framework")
var PullRequestEnvironmentName: String? = jResp.StringOf("app.autoBranchCreationConfig.pullRequestEnvironmentName")
var Stage: String? = jResp.StringOf("app.autoBranchCreationConfig.stage")
var appBasicAuthCredentials: String? = jResp.StringOf("app.basicAuthCredentials")
var appBuildSpec: String? = jResp.StringOf("app.buildSpec")
var CreateTime: Int = jResp.IntOf("app.createTime").intValue
var CustomHeaders: String? = jResp.StringOf("app.customHeaders")
var DefaultDomain: String? = jResp.StringOf("app.defaultDomain")
var Description: String? = jResp.StringOf("app.description")
var EnableAutoBranchCreation: Int = jResp.IntOf("app.enableAutoBranchCreation").intValue
var appEnableBasicAuth: Int = jResp.IntOf("app.enableBasicAuth").intValue
var EnableBranchAutoBuild: Int = jResp.IntOf("app.enableBranchAutoBuild").intValue
var EnableBranchAutoDeletion: Int = jResp.IntOf("app.enableBranchAutoDeletion").intValue
var EnvironmentVariablesString: String? = jResp.StringOf("app.environmentVariables.string")
var IamServiceRoleArn: String? = jResp.StringOf("app.iamServiceRoleArn")
var Name: String? = jResp.StringOf("app.name")
var Platform: String? = jResp.StringOf("app.platform")
var BranchName: String? = jResp.StringOf("app.productionBranch.branchName")
var LastDeployTime: Int = jResp.IntOf("app.productionBranch.lastDeployTime").intValue
var Status: String? = jResp.StringOf("app.productionBranch.status")
var ThumbnailUrl: String? = jResp.StringOf("app.productionBranch.thumbnailUrl")
var Repository: String? = jResp.StringOf("app.repository")
var RepositoryCloneMethod: String? = jResp.StringOf("app.repositoryCloneMethod")
var TagsString: String? = jResp.StringOf("app.tags.string")
var UpdateTime: Int = jResp.IntOf("app.updateTime").intValue
var i: Int = 0
var count_i: Int = jResp.SizeOfArray("app.autoBranchCreationPatterns").intValue
while i < count_i {
jResp.I = i
strVal = jResp.StringOf("app.autoBranchCreationPatterns[i]")
i = i + 1
}
i = 0
count_i = jResp.SizeOfArray("app.customRules").intValue
while i < count_i {
jResp.I = i
condition = jResp.StringOf("app.customRules[i].condition")
source = jResp.StringOf("app.customRules[i].source")
status = jResp.StringOf("app.customRules[i].status")
target = jResp.StringOf("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
// }
// }
}