Chilkat Online Tools

DescribeInsight Swift Example

Amazon DevOps Guru

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

    // URL: https://devops-guru.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect("devops-guru.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: "DescribeInsight")

    let sbResponseBody = CkoStringBuilder()
    success = rest.FullRequestNoBodySb("GET", uriPath: "/insights/{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 AppBoundaryKey: String?
    var j: Int
    var count_j: Int

    var Description: String? = jResp.StringOf("ProactiveInsight.Description")
    var Id: String? = jResp.StringOf("ProactiveInsight.Id")
    var EndTime: Int = jResp.IntOf("ProactiveInsight.InsightTimeRange.EndTime").intValue
    var StartTime: Int = jResp.IntOf("ProactiveInsight.InsightTimeRange.StartTime").intValue
    var Name: String? = jResp.StringOf("ProactiveInsight.Name")
    var PredictionTimeRangeEndTime: Int = jResp.IntOf("ProactiveInsight.PredictionTimeRange.EndTime").intValue
    var PredictionTimeRangeStartTime: Int = jResp.IntOf("ProactiveInsight.PredictionTimeRange.StartTime").intValue
    var Severity: String? = jResp.StringOf("ProactiveInsight.Severity")
    var SsmOpsItemId: String? = jResp.StringOf("ProactiveInsight.SsmOpsItemId")
    var Status: String? = jResp.StringOf("ProactiveInsight.Status")
    var ReactiveInsightDescription: String? = jResp.StringOf("ReactiveInsight.Description")
    var ReactiveInsightId: String? = jResp.StringOf("ReactiveInsight.Id")
    var InsightTimeRangeEndTime: Int = jResp.IntOf("ReactiveInsight.InsightTimeRange.EndTime").intValue
    var InsightTimeRangeStartTime: Int = jResp.IntOf("ReactiveInsight.InsightTimeRange.StartTime").intValue
    var ReactiveInsightName: String? = jResp.StringOf("ReactiveInsight.Name")
    var ReactiveInsightSeverity: String? = jResp.StringOf("ReactiveInsight.Severity")
    var ReactiveInsightSsmOpsItemId: String? = jResp.StringOf("ReactiveInsight.SsmOpsItemId")
    var ReactiveInsightStatus: String? = jResp.StringOf("ReactiveInsight.Status")
    var i: Int = 0
    var count_i: Int = jResp.SizeOfArray("ProactiveInsight.ResourceCollection.CloudFormation.StackNames").intValue
    while i < count_i {
        jResp.I = i
        strVal = jResp.StringOf("ProactiveInsight.ResourceCollection.CloudFormation.StackNames[i]")
        i = i + 1
    }

    i = 0
    count_i = jResp.SizeOfArray("ProactiveInsight.ResourceCollection.Tags").intValue
    while i < count_i {
        jResp.I = i
        AppBoundaryKey = jResp.StringOf("ProactiveInsight.ResourceCollection.Tags[i].AppBoundaryKey")
        j = 0
        count_j = jResp.SizeOfArray("ProactiveInsight.ResourceCollection.Tags[i].TagValues").intValue
        while j < count_j {
            jResp.J = j
            strVal = jResp.StringOf("ProactiveInsight.ResourceCollection.Tags[i].TagValues[j]")
            j = j + 1
        }

        i = i + 1
    }

    i = 0
    count_i = jResp.SizeOfArray("ReactiveInsight.ResourceCollection.CloudFormation.StackNames").intValue
    while i < count_i {
        jResp.I = i
        strVal = jResp.StringOf("ReactiveInsight.ResourceCollection.CloudFormation.StackNames[i]")
        i = i + 1
    }

    i = 0
    count_i = jResp.SizeOfArray("ReactiveInsight.ResourceCollection.Tags").intValue
    while i < count_i {
        jResp.I = i
        AppBoundaryKey = jResp.StringOf("ReactiveInsight.ResourceCollection.Tags[i].AppBoundaryKey")
        j = 0
        count_j = jResp.SizeOfArray("ReactiveInsight.ResourceCollection.Tags[i].TagValues").intValue
        while j < count_j {
            jResp.J = j
            strVal = jResp.StringOf("ReactiveInsight.ResourceCollection.Tags[i].TagValues[j]")
            j = j + 1
        }

        i = i + 1
    }

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

    // {
    //   "ProactiveInsight": {
    //     "Description": "string",
    //     "Id": "string",
    //     "InsightTimeRange": {
    //       "EndTime": number,
    //       "StartTime": number
    //     },
    //     "Name": "string",
    //     "PredictionTimeRange": {
    //       "EndTime": number,
    //       "StartTime": number
    //     },
    //     "ResourceCollection": {
    //       "CloudFormation": {
    //         "StackNames": [
    //           "string"
    //         ]
    //       },
    //       "Tags": [
    //         {
    //           "AppBoundaryKey": "string",
    //           "TagValues": [
    //             "string"
    //           ]
    //         }
    //       ]
    //     },
    //     "Severity": "string",
    //     "SsmOpsItemId": "string",
    //     "Status": "string"
    //   },
    //   "ReactiveInsight": {
    //     "Description": "string",
    //     "Id": "string",
    //     "InsightTimeRange": {
    //       "EndTime": number,
    //       "StartTime": number
    //     },
    //     "Name": "string",
    //     "ResourceCollection": {
    //       "CloudFormation": {
    //         "StackNames": [
    //           "string"
    //         ]
    //       },
    //       "Tags": [
    //         {
    //           "AppBoundaryKey": "string",
    //           "TagValues": [
    //             "string"
    //           ]
    //         }
    //       ]
    //     },
    //     "Severity": "string",
    //     "SsmOpsItemId": "string",
    //     "Status": "string"
    //   }
    // }

}