Chilkat Online Tools

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

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

    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestNoBodySb("GET", uriPath: "/experiments/{id}", sb: 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: "experiment.actions.string.actionId")
    var Description: String? = jResp.string(of: "experiment.actions.string.description")
    var EndTime: Int = jResp.int(of: "experiment.actions.string.endTime").intValue
    var v_String: String? = jResp.string(of: "experiment.actions.string.parameters.string")
    var StartTime: Int = jResp.int(of: "experiment.actions.string.startTime").intValue
    var Reason: String? = jResp.string(of: "experiment.actions.string.state.reason")
    var Status: String? = jResp.string(of: "experiment.actions.string.state.status")
    var TargetsString: String? = jResp.string(of: "experiment.actions.string.targets.string")
    var CreationTime: Int = jResp.int(of: "experiment.creationTime").intValue
    var experimentEndTime: Int = jResp.int(of: "experiment.endTime").intValue
    var ExperimentTemplateId: String? = jResp.string(of: "experiment.experimentTemplateId")
    var Id: String? = jResp.string(of: "experiment.id")
    var LogGroupArn: String? = jResp.string(of: "experiment.logConfiguration.cloudWatchLogsConfiguration.logGroupArn")
    var LogSchemaVersion: Int = jResp.int(of: "experiment.logConfiguration.logSchemaVersion").intValue
    var BucketName: String? = jResp.string(of: "experiment.logConfiguration.s3Configuration.bucketName")
    var Prefix: String? = jResp.string(of: "experiment.logConfiguration.s3Configuration.prefix")
    var RoleArn: String? = jResp.string(of: "experiment.roleArn")
    var experimentStartTime: Int = jResp.int(of: "experiment.startTime").intValue
    var StateReason: String? = jResp.string(of: "experiment.state.reason")
    var StateStatus: String? = jResp.string(of: "experiment.state.status")
    var TagsString: String? = jResp.string(of: "experiment.tags.string")
    var ParametersString: String? = jResp.string(of: "experiment.targets.string.parameters.string")
    var ResourceTagsString: String? = jResp.string(of: "experiment.targets.string.resourceTags.string")
    var ResourceType: String? = jResp.string(of: "experiment.targets.string.resourceType")
    var SelectionMode: String? = jResp.string(of: "experiment.targets.string.selectionMode")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "experiment.actions.string.startAfter").intValue
    while i < count_i {
        jResp.i = i
        strVal = jResp.string(of: "experiment.actions.string.startAfter[i]")
        i = i + 1
    }

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

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

        i = i + 1
    }

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

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

    // {
    //   "experiment": {
    //     "actions": {
    //       "string": {
    //         "actionId": "string",
    //         "description": "string",
    //         "endTime": number,
    //         "parameters": {
    //           "string": "string"
    //         },
    //         "startAfter": [
    //           "string"
    //         ],
    //         "startTime": number,
    //         "state": {
    //           "reason": "string",
    //           "status": "string"
    //         },
    //         "targets": {
    //           "string": "string"
    //         }
    //       }
    //     },
    //     "creationTime": number,
    //     "endTime": number,
    //     "experimentTemplateId": "string",
    //     "id": "string",
    //     "logConfiguration": {
    //       "cloudWatchLogsConfiguration": {
    //         "logGroupArn": "string"
    //       },
    //       "logSchemaVersion": number,
    //       "s3Configuration": {
    //         "bucketName": "string",
    //         "prefix": "string"
    //       }
    //     },
    //     "roleArn": "string",
    //     "startTime": number,
    //     "state": {
    //       "reason": "string",
    //       "status": "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"
    //       }
    //     }
    //   }
    // }

}