UpdateBranch 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("backendEnvironmentArn", value: "string")
json.UpdateString("basicAuthCredentials", value: "string")
json.UpdateString("buildSpec", value: "string")
json.UpdateString("description", value: "string")
json.UpdateString("displayName", value: "string")
json.UpdateInt("enableAutoBuild", value: 123)
json.UpdateInt("enableBasicAuth", value: 123)
json.UpdateInt("enableNotification", value: 123)
json.UpdateInt("enablePerformanceMode", value: 123)
json.UpdateInt("enablePullRequestPreview", value: 123)
json.UpdateString("environmentVariables.string", value: "string")
json.UpdateString("framework", value: "string")
json.UpdateString("pullRequestEnvironmentName", value: "string")
json.UpdateString("stage", value: "string")
json.UpdateString("ttl", value: "string")
// The JSON request body created by the above code:
// {
// "backendEnvironmentArn": "string",
// "basicAuthCredentials": "string",
// "buildSpec": "string",
// "description": "string",
// "displayName": "string",
// "enableAutoBuild": boolean,
// "enableBasicAuth": boolean,
// "enableNotification": boolean,
// "enablePerformanceMode": boolean,
// "enablePullRequestPreview": boolean,
// "environmentVariables": {
// "string": "string"
// },
// "framework": "string",
// "pullRequestEnvironmentName": "string",
// "stage": "string",
// "ttl": "string"
// }
rest.AddHeader("Content-Type", value: "application/x-amz-json-1.1")
rest.AddHeader("X-Amz-Target", value: "UpdateBranch")
let sbRequestBody = CkoStringBuilder()
json.EmitSb(sbRequestBody)
let sbResponseBody = CkoStringBuilder()
success = rest.FullRequestSb("POST", uriPath: "/apps/{appId}/branches/{branchName}", 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 ActiveJobId: String? = jResp.StringOf("branch.activeJobId")
var BackendEnvironmentArn: String? = jResp.StringOf("branch.backendEnvironmentArn")
var BasicAuthCredentials: String? = jResp.StringOf("branch.basicAuthCredentials")
var BranchArn: String? = jResp.StringOf("branch.branchArn")
var BranchName: String? = jResp.StringOf("branch.branchName")
var BuildSpec: String? = jResp.StringOf("branch.buildSpec")
var CreateTime: Int = jResp.IntOf("branch.createTime").intValue
var Description: String? = jResp.StringOf("branch.description")
var DestinationBranch: String? = jResp.StringOf("branch.destinationBranch")
var DisplayName: String? = jResp.StringOf("branch.displayName")
var EnableAutoBuild: Int = jResp.IntOf("branch.enableAutoBuild").intValue
var EnableBasicAuth: Int = jResp.IntOf("branch.enableBasicAuth").intValue
var EnableNotification: Int = jResp.IntOf("branch.enableNotification").intValue
var EnablePerformanceMode: Int = jResp.IntOf("branch.enablePerformanceMode").intValue
var EnablePullRequestPreview: Int = jResp.IntOf("branch.enablePullRequestPreview").intValue
var v_String: String? = jResp.StringOf("branch.environmentVariables.string")
var Framework: String? = jResp.StringOf("branch.framework")
var PullRequestEnvironmentName: String? = jResp.StringOf("branch.pullRequestEnvironmentName")
var SourceBranch: String? = jResp.StringOf("branch.sourceBranch")
var Stage: String? = jResp.StringOf("branch.stage")
var TagsString: String? = jResp.StringOf("branch.tags.string")
var ThumbnailUrl: String? = jResp.StringOf("branch.thumbnailUrl")
var TotalNumberOfJobs: String? = jResp.StringOf("branch.totalNumberOfJobs")
var Ttl: String? = jResp.StringOf("branch.ttl")
var UpdateTime: Int = jResp.IntOf("branch.updateTime").intValue
var i: Int = 0
var count_i: Int = jResp.SizeOfArray("branch.associatedResources").intValue
while i < count_i {
jResp.I = i
strVal = jResp.StringOf("branch.associatedResources[i]")
i = i + 1
}
i = 0
count_i = jResp.SizeOfArray("branch.customDomains").intValue
while i < count_i {
jResp.I = i
strVal = jResp.StringOf("branch.customDomains[i]")
i = i + 1
}
// A sample JSON response body parsed by the above code:
// {
// "branch": {
// "activeJobId": "string",
// "associatedResources": [
// "string"
// ],
// "backendEnvironmentArn": "string",
// "basicAuthCredentials": "string",
// "branchArn": "string",
// "branchName": "string",
// "buildSpec": "string",
// "createTime": number,
// "customDomains": [
// "string"
// ],
// "description": "string",
// "destinationBranch": "string",
// "displayName": "string",
// "enableAutoBuild": boolean,
// "enableBasicAuth": boolean,
// "enableNotification": boolean,
// "enablePerformanceMode": boolean,
// "enablePullRequestPreview": boolean,
// "environmentVariables": {
// "string": "string"
// },
// "framework": "string",
// "pullRequestEnvironmentName": "string",
// "sourceBranch": "string",
// "stage": "string",
// "tags": {
// "string": "string"
// },
// "thumbnailUrl": "string",
// "totalNumberOfJobs": "string",
// "ttl": "string",
// "updateTime": number
// }
// }
}