Chilkat Online Tools

CreateExperimentTemplate Swift3 Example

AWS Fault Injection Simulator

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 = "fis"
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.setAuthAws(authAws)

    // URL: https://fis.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.connect("fis.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("actions.string.actionId", value: "string")
    json.update("actions.string.description", value: "string")
    json.update("actions.string.parameters.string", value: "string")
    json.update("actions.string.startAfter[0]", value: "string")
    json.update("actions.string.targets.string", value: "string")
    json.update("clientToken", value: "string")
    json.update("description", value: "string")
    json.update("logConfiguration.cloudWatchLogsConfiguration.logGroupArn", value: "string")
    json.updateInt("logConfiguration.logSchemaVersion", value: 123)
    json.update("logConfiguration.s3Configuration.bucketName", value: "string")
    json.update("logConfiguration.s3Configuration.prefix", value: "string")
    json.update("roleArn", value: "string")
    json.update("stopConditions[0].source", value: "string")
    json.update("stopConditions[0].value", value: "string")
    json.update("tags.string", value: "string")
    json.update("targets.string.filters[0].path", value: "string")
    json.update("targets.string.filters[0].values[0]", value: "string")
    json.update("targets.string.parameters.string", value: "string")
    json.update("targets.string.resourceArns[0]", value: "string")
    json.update("targets.string.resourceTags.string", value: "string")
    json.update("targets.string.resourceType", value: "string")
    json.update("targets.string.selectionMode", value: "string")

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

    // {
    //   "actions": {
    //     "string": {
    //       "actionId": "string",
    //       "description": "string",
    //       "parameters": {
    //         "string": "string"
    //       },
    //       "startAfter": [
    //         "string"
    //       ],
    //       "targets": {
    //         "string": "string"
    //       }
    //     }
    //   },
    //   "clientToken": "string",
    //   "description": "string",
    //   "logConfiguration": {
    //     "cloudWatchLogsConfiguration": {
    //       "logGroupArn": "string"
    //     },
    //     "logSchemaVersion": number,
    //     "s3Configuration": {
    //       "bucketName": "string",
    //       "prefix": "string"
    //     }
    //   },
    //   "roleArn": "string",
    //   "stopConditions": [
    //     {
    //       "source": "string",
    //       "value": "string"
    //     }
    //   ],
    //   "tags": {
    //     "string": "string"
    //   },
    //   "targets": {
    //     "string": {
    //       "filters": [
    //         {
    //           "path": "string",
    //           "values": [
    //             "string"
    //           ]
    //         }
    //       ],
    //       "parameters": {
    //         "string": "string"
    //       },
    //       "resourceArns": [
    //         "string"
    //       ],
    //       "resourceTags": {
    //         "string": "string"
    //       },
    //       "resourceType": "string",
    //       "selectionMode": "string"
    //     }
    //   }
    // }

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

    let sbRequestBody = CkoStringBuilder()!
    json.emitSb(sbRequestBody)
    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestSb("POST", uriPath: "/experimentTemplates", 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 source: String?
    var value: String?
    var path: String?
    var j: Int
    var count_j: Int

    var ActionId: String? = jResp.string(of: "experimentTemplate.actions.string.actionId")
    var Description: String? = jResp.string(of: "experimentTemplate.actions.string.description")
    var v_String: String? = jResp.string(of: "experimentTemplate.actions.string.parameters.string")
    var TargetsString: String? = jResp.string(of: "experimentTemplate.actions.string.targets.string")
    var CreationTime: Int = jResp.int(of: "experimentTemplate.creationTime").intValue
    var experimentTemplateDescription: String? = jResp.string(of: "experimentTemplate.description")
    var Id: String? = jResp.string(of: "experimentTemplate.id")
    var LastUpdateTime: Int = jResp.int(of: "experimentTemplate.lastUpdateTime").intValue
    var LogGroupArn: String? = jResp.string(of: "experimentTemplate.logConfiguration.cloudWatchLogsConfiguration.logGroupArn")
    var LogSchemaVersion: Int = jResp.int(of: "experimentTemplate.logConfiguration.logSchemaVersion").intValue
    var BucketName: String? = jResp.string(of: "experimentTemplate.logConfiguration.s3Configuration.bucketName")
    var Prefix: String? = jResp.string(of: "experimentTemplate.logConfiguration.s3Configuration.prefix")
    var RoleArn: String? = jResp.string(of: "experimentTemplate.roleArn")
    var TagsString: String? = jResp.string(of: "experimentTemplate.tags.string")
    var ParametersString: String? = jResp.string(of: "experimentTemplate.targets.string.parameters.string")
    var ResourceTagsString: String? = jResp.string(of: "experimentTemplate.targets.string.resourceTags.string")
    var ResourceType: String? = jResp.string(of: "experimentTemplate.targets.string.resourceType")
    var SelectionMode: String? = jResp.string(of: "experimentTemplate.targets.string.selectionMode")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "experimentTemplate.actions.string.startAfter").intValue
    while i < count_i {
        jResp.i = i
        strVal = jResp.string(of: "experimentTemplate.actions.string.startAfter[i]")
        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "experimentTemplate.stopConditions").intValue
    while i < count_i {
        jResp.i = i
        source = jResp.string(of: "experimentTemplate.stopConditions[i].source")
        value = jResp.string(of: "experimentTemplate.stopConditions[i].value")
        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "experimentTemplate.targets.string.filters").intValue
    while i < count_i {
        jResp.i = i
        path = jResp.string(of: "experimentTemplate.targets.string.filters[i].path")
        j = 0
        count_j = jResp.size(ofArray: "experimentTemplate.targets.string.filters[i].values").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "experimentTemplate.targets.string.filters[i].values[j]")
            j = j + 1
        }

        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "experimentTemplate.targets.string.resourceArns").intValue
    while i < count_i {
        jResp.i = i
        strVal = jResp.string(of: "experimentTemplate.targets.string.resourceArns[i]")
        i = i + 1
    }

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

    // {
    //   "experimentTemplate": {
    //     "actions": {
    //       "string": {
    //         "actionId": "string",
    //         "description": "string",
    //         "parameters": {
    //           "string": "string"
    //         },
    //         "startAfter": [
    //           "string"
    //         ],
    //         "targets": {
    //           "string": "string"
    //         }
    //       }
    //     },
    //     "creationTime": number,
    //     "description": "string",
    //     "id": "string",
    //     "lastUpdateTime": number,
    //     "logConfiguration": {
    //       "cloudWatchLogsConfiguration": {
    //         "logGroupArn": "string"
    //       },
    //       "logSchemaVersion": number,
    //       "s3Configuration": {
    //         "bucketName": "string",
    //         "prefix": "string"
    //       }
    //     },
    //     "roleArn": "string",
    //     "stopConditions": [
    //       {
    //         "source": "string",
    //         "value": "string"
    //       }
    //     ],
    //     "tags": {
    //       "string": "string"
    //     },
    //     "targets": {
    //       "string": {
    //         "filters": [
    //           {
    //             "path": "string",
    //             "values": [
    //               "string"
    //             ]
    //           }
    //         ],
    //         "parameters": {
    //           "string": "string"
    //         },
    //         "resourceArns": [
    //           "string"
    //         ],
    //         "resourceTags": {
    //           "string": "string"
    //         },
    //         "resourceType": "string",
    //         "selectionMode": "string"
    //       }
    //     }
    //   }
    // }

}