Chilkat Online Tools

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

    // 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("AccountIds[0]", value: "string")
    json.UpdateString("Filters.ResourceCollection.CloudFormation.StackNames[0]", value: "string")
    json.UpdateString("Filters.ResourceCollection.Tags[0].AppBoundaryKey", value: "string")
    json.UpdateString("Filters.ResourceCollection.Tags[0].TagValues[0]", value: "string")
    json.UpdateString("Filters.ServiceCollection.ServiceNames[0]", value: "string")
    json.UpdateString("Filters.Severities[0]", value: "string")
    json.UpdateString("Filters.Statuses[0]", value: "string")
    json.UpdateInt("MaxResults", value: 123)
    json.UpdateString("NextToken", value: "string")
    json.UpdateInt("StartTimeRange.FromTime", value: 123)
    json.UpdateInt("StartTimeRange.ToTime", value: 123)
    json.UpdateString("Type", value: "string")

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

    // {
    //   "AccountIds": [
    //     "string"
    //   ],
    //   "Filters": {
    //     "ResourceCollection": {
    //       "CloudFormation": {
    //         "StackNames": [
    //           "string"
    //         ]
    //       },
    //       "Tags": [
    //         {
    //           "AppBoundaryKey": "string",
    //           "TagValues": [
    //             "string"
    //           ]
    //         }
    //       ]
    //     },
    //     "ServiceCollection": {
    //       "ServiceNames": [
    //         "string"
    //       ]
    //     },
    //     "Severities": [
    //       "string"
    //     ],
    //     "Statuses": [
    //       "string"
    //     ]
    //   },
    //   "MaxResults": number,
    //   "NextToken": "string",
    //   "StartTimeRange": {
    //     "FromTime": number,
    //     "ToTime": number
    //   },
    //   "Type": "string"
    // }

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

    let sbRequestBody = CkoStringBuilder()
    json.EmitSb(sbRequestBody)
    let sbResponseBody = CkoStringBuilder()
    success = rest.FullRequestSb("POST", uriPath: "/organization/insights/search", 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 Id: String?
    var EndTime: Int
    var StartTime: Int
    var Name: String?
    var PredictionTimeRangeEndTime: Int
    var PredictionTimeRangeStartTime: Int
    var Severity: String?
    var Status: String?
    var j: Int
    var count_j: Int
    var strVal: String?
    var AppBoundaryKey: String?
    var k: Int
    var count_k: Int
    var InsightTimeRangeEndTime: Int
    var InsightTimeRangeStartTime: Int

    var NextToken: String? = jResp.StringOf("NextToken")
    var i: Int = 0
    var count_i: Int = jResp.SizeOfArray("ProactiveInsights").intValue
    while i < count_i {
        jResp.I = i
        Id = jResp.StringOf("ProactiveInsights[i].Id")
        EndTime = jResp.IntOf("ProactiveInsights[i].InsightTimeRange.EndTime").intValue
        StartTime = jResp.IntOf("ProactiveInsights[i].InsightTimeRange.StartTime").intValue
        Name = jResp.StringOf("ProactiveInsights[i].Name")
        PredictionTimeRangeEndTime = jResp.IntOf("ProactiveInsights[i].PredictionTimeRange.EndTime").intValue
        PredictionTimeRangeStartTime = jResp.IntOf("ProactiveInsights[i].PredictionTimeRange.StartTime").intValue
        Severity = jResp.StringOf("ProactiveInsights[i].Severity")
        Status = jResp.StringOf("ProactiveInsights[i].Status")
        j = 0
        count_j = jResp.SizeOfArray("ProactiveInsights[i].AssociatedResourceArns").intValue
        while j < count_j {
            jResp.J = j
            strVal = jResp.StringOf("ProactiveInsights[i].AssociatedResourceArns[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.SizeOfArray("ProactiveInsights[i].ResourceCollection.CloudFormation.StackNames").intValue
        while j < count_j {
            jResp.J = j
            strVal = jResp.StringOf("ProactiveInsights[i].ResourceCollection.CloudFormation.StackNames[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.SizeOfArray("ProactiveInsights[i].ResourceCollection.Tags").intValue
        while j < count_j {
            jResp.J = j
            AppBoundaryKey = jResp.StringOf("ProactiveInsights[i].ResourceCollection.Tags[j].AppBoundaryKey")
            k = 0
            count_k = jResp.SizeOfArray("ProactiveInsights[i].ResourceCollection.Tags[j].TagValues").intValue
            while k < count_k {
                jResp.K = k
                strVal = jResp.StringOf("ProactiveInsights[i].ResourceCollection.Tags[j].TagValues[k]")
                k = k + 1
            }

            j = j + 1
        }

        j = 0
        count_j = jResp.SizeOfArray("ProactiveInsights[i].ServiceCollection.ServiceNames").intValue
        while j < count_j {
            jResp.J = j
            strVal = jResp.StringOf("ProactiveInsights[i].ServiceCollection.ServiceNames[j]")
            j = j + 1
        }

        i = i + 1
    }

    i = 0
    count_i = jResp.SizeOfArray("ReactiveInsights").intValue
    while i < count_i {
        jResp.I = i
        Id = jResp.StringOf("ReactiveInsights[i].Id")
        InsightTimeRangeEndTime = jResp.IntOf("ReactiveInsights[i].InsightTimeRange.EndTime").intValue
        InsightTimeRangeStartTime = jResp.IntOf("ReactiveInsights[i].InsightTimeRange.StartTime").intValue
        Name = jResp.StringOf("ReactiveInsights[i].Name")
        Severity = jResp.StringOf("ReactiveInsights[i].Severity")
        Status = jResp.StringOf("ReactiveInsights[i].Status")
        j = 0
        count_j = jResp.SizeOfArray("ReactiveInsights[i].AssociatedResourceArns").intValue
        while j < count_j {
            jResp.J = j
            strVal = jResp.StringOf("ReactiveInsights[i].AssociatedResourceArns[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.SizeOfArray("ReactiveInsights[i].ResourceCollection.CloudFormation.StackNames").intValue
        while j < count_j {
            jResp.J = j
            strVal = jResp.StringOf("ReactiveInsights[i].ResourceCollection.CloudFormation.StackNames[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.SizeOfArray("ReactiveInsights[i].ResourceCollection.Tags").intValue
        while j < count_j {
            jResp.J = j
            AppBoundaryKey = jResp.StringOf("ReactiveInsights[i].ResourceCollection.Tags[j].AppBoundaryKey")
            k = 0
            count_k = jResp.SizeOfArray("ReactiveInsights[i].ResourceCollection.Tags[j].TagValues").intValue
            while k < count_k {
                jResp.K = k
                strVal = jResp.StringOf("ReactiveInsights[i].ResourceCollection.Tags[j].TagValues[k]")
                k = k + 1
            }

            j = j + 1
        }

        j = 0
        count_j = jResp.SizeOfArray("ReactiveInsights[i].ServiceCollection.ServiceNames").intValue
        while j < count_j {
            jResp.J = j
            strVal = jResp.StringOf("ReactiveInsights[i].ServiceCollection.ServiceNames[j]")
            j = j + 1
        }

        i = i + 1
    }

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

    // {
    //   "NextToken": "string",
    //   "ProactiveInsights": [
    //     {
    //       "AssociatedResourceArns": [
    //         "string"
    //       ],
    //       "Id": "string",
    //       "InsightTimeRange": {
    //         "EndTime": number,
    //         "StartTime": number
    //       },
    //       "Name": "string",
    //       "PredictionTimeRange": {
    //         "EndTime": number,
    //         "StartTime": number
    //       },
    //       "ResourceCollection": {
    //         "CloudFormation": {
    //           "StackNames": [
    //             "string"
    //           ]
    //         },
    //         "Tags": [
    //           {
    //             "AppBoundaryKey": "string",
    //             "TagValues": [
    //               "string"
    //             ]
    //           }
    //         ]
    //       },
    //       "ServiceCollection": {
    //         "ServiceNames": [
    //           "string"
    //         ]
    //       },
    //       "Severity": "string",
    //       "Status": "string"
    //     }
    //   ],
    //   "ReactiveInsights": [
    //     {
    //       "AssociatedResourceArns": [
    //         "string"
    //       ],
    //       "Id": "string",
    //       "InsightTimeRange": {
    //         "EndTime": number,
    //         "StartTime": number
    //       },
    //       "Name": "string",
    //       "ResourceCollection": {
    //         "CloudFormation": {
    //           "StackNames": [
    //             "string"
    //           ]
    //         },
    //         "Tags": [
    //           {
    //             "AppBoundaryKey": "string",
    //             "TagValues": [
    //               "string"
    //             ]
    //           }
    //         ]
    //       },
    //       "ServiceCollection": {
    //         "ServiceNames": [
    //           "string"
    //         ]
    //       },
    //       "Severity": "string",
    //       "Status": "string"
    //     }
    //   ]
    // }

}