CreateDataRepositoryTask 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 = "fsx"
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.SetAuthAws(authAws)
// URL: https://fsx.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = rest.Connect("fsx.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("ClientRequestToken", value: "string")
json.UpdateString("FileSystemId", value: "string")
json.UpdateString("Paths[0]", value: "string")
json.UpdateInt("Report.Enabled", value: 123)
json.UpdateString("Report.Format", value: "string")
json.UpdateString("Report.Path", value: "string")
json.UpdateString("Report.Scope", value: "string")
json.UpdateString("Tags[0].Key", value: "string")
json.UpdateString("Tags[0].Value", value: "string")
json.UpdateString("Type", value: "string")
// The JSON request body created by the above code:
// {
// "ClientRequestToken": "string",
// "FileSystemId": "string",
// "Paths": [
// "string"
// ],
// "Report": {
// "Enabled": boolean,
// "Format": "string",
// "Path": "string",
// "Scope": "string"
// },
// "Tags": [
// {
// "Key": "string",
// "Value": "string"
// }
// ],
// "Type": "string"
// }
rest.AddHeader("Content-Type", value: "application/x-amz-json-1.1")
rest.AddHeader("X-Amz-Target", value: "AWSSimbaAPIService_v20180301.CreateDataRepositoryTask")
let sbRequestBody = CkoStringBuilder()
json.EmitSb(sbRequestBody)
let sbResponseBody = CkoStringBuilder()
success = rest.FullRequestSb("POST", uriPath: "/", 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 Key: String?
var Value: String?
var CreationTime: Int = jResp.IntOf("DataRepositoryTask.CreationTime").intValue
var EndTime: Int = jResp.IntOf("DataRepositoryTask.EndTime").intValue
var Message: String? = jResp.StringOf("DataRepositoryTask.FailureDetails.Message")
var FileSystemId: String? = jResp.StringOf("DataRepositoryTask.FileSystemId")
var Lifecycle: String? = jResp.StringOf("DataRepositoryTask.Lifecycle")
var Enabled: Int = jResp.IntOf("DataRepositoryTask.Report.Enabled").intValue
var Format: String? = jResp.StringOf("DataRepositoryTask.Report.Format")
var Path: String? = jResp.StringOf("DataRepositoryTask.Report.Path")
var Scope: String? = jResp.StringOf("DataRepositoryTask.Report.Scope")
var ResourceARN: String? = jResp.StringOf("DataRepositoryTask.ResourceARN")
var StartTime: Int = jResp.IntOf("DataRepositoryTask.StartTime").intValue
var FailedCount: Int = jResp.IntOf("DataRepositoryTask.Status.FailedCount").intValue
var LastUpdatedTime: Int = jResp.IntOf("DataRepositoryTask.Status.LastUpdatedTime").intValue
var SucceededCount: Int = jResp.IntOf("DataRepositoryTask.Status.SucceededCount").intValue
var TotalCount: Int = jResp.IntOf("DataRepositoryTask.Status.TotalCount").intValue
var TaskId: String? = jResp.StringOf("DataRepositoryTask.TaskId")
var v_Type: String? = jResp.StringOf("DataRepositoryTask.Type")
var i: Int = 0
var count_i: Int = jResp.SizeOfArray("DataRepositoryTask.Paths").intValue
while i < count_i {
jResp.I = i
strVal = jResp.StringOf("DataRepositoryTask.Paths[i]")
i = i + 1
}
i = 0
count_i = jResp.SizeOfArray("DataRepositoryTask.Tags").intValue
while i < count_i {
jResp.I = i
Key = jResp.StringOf("DataRepositoryTask.Tags[i].Key")
Value = jResp.StringOf("DataRepositoryTask.Tags[i].Value")
i = i + 1
}
// A sample JSON response body parsed by the above code:
// {
// "DataRepositoryTask": {
// "CreationTime": number,
// "EndTime": number,
// "FailureDetails": {
// "Message": "string"
// },
// "FileSystemId": "string",
// "Lifecycle": "string",
// "Paths": [
// "string"
// ],
// "Report": {
// "Enabled": boolean,
// "Format": "string",
// "Path": "string",
// "Scope": "string"
// },
// "ResourceARN": "string",
// "StartTime": number,
// "Status": {
// "FailedCount": number,
// "LastUpdatedTime": number,
// "SucceededCount": number,
// "TotalCount": number
// },
// "Tags": [
// {
// "Key": "string",
// "Value": "string"
// }
// ],
// "TaskId": "string",
// "Type": "string"
// }
// }
}