Chilkat Online Tools

ListOrganizationInsights Swift3 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.update("AccountIds[0]", value: "string")
    json.updateInt("MaxResults", value: 123)
    json.update("NextToken", value: "string")
    json.update("OrganizationalUnitIds[0]", value: "string")
    json.updateInt("StatusFilter.Any.StartTimeRange.FromTime", value: 123)
    json.updateInt("StatusFilter.Any.StartTimeRange.ToTime", value: 123)
    json.update("StatusFilter.Any.Type", value: "string")
    json.updateInt("StatusFilter.Closed.EndTimeRange.FromTime", value: 123)
    json.updateInt("StatusFilter.Closed.EndTimeRange.ToTime", value: 123)
    json.update("StatusFilter.Closed.Type", value: "string")
    json.update("StatusFilter.Ongoing.Type", value: "string")

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

    // {
    //   "AccountIds": [
    //     "string"
    //   ],
    //   "MaxResults": number,
    //   "NextToken": "string",
    //   "OrganizationalUnitIds": [
    //     "string"
    //   ],
    //   "StatusFilter": {
    //     "Any": {
    //       "StartTimeRange": {
    //         "FromTime": number,
    //         "ToTime": number
    //       },
    //       "Type": "string"
    //     },
    //     "Closed": {
    //       "EndTimeRange": {
    //         "FromTime": number,
    //         "ToTime": number
    //       },
    //       "Type": "string"
    //     },
    //     "Ongoing": {
    //       "Type": "string"
    //     }
    //   }
    // }

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

    let sbRequestBody = CkoStringBuilder()!
    json.emitSb(sbRequestBody)
    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestSb("POST", uriPath: "/organization/insights", 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 AccountId: String?
    var Id: String?
    var EndTime: Int
    var StartTime: Int
    var Name: String?
    var OrganizationalUnitId: 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.string(of: "NextToken")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "ProactiveInsights").intValue
    while i < count_i {
        jResp.i = i
        AccountId = jResp.string(of: "ProactiveInsights[i].AccountId")
        Id = jResp.string(of: "ProactiveInsights[i].Id")
        EndTime = jResp.int(of: "ProactiveInsights[i].InsightTimeRange.EndTime").intValue
        StartTime = jResp.int(of: "ProactiveInsights[i].InsightTimeRange.StartTime").intValue
        Name = jResp.string(of: "ProactiveInsights[i].Name")
        OrganizationalUnitId = jResp.string(of: "ProactiveInsights[i].OrganizationalUnitId")
        PredictionTimeRangeEndTime = jResp.int(of: "ProactiveInsights[i].PredictionTimeRange.EndTime").intValue
        PredictionTimeRangeStartTime = jResp.int(of: "ProactiveInsights[i].PredictionTimeRange.StartTime").intValue
        Severity = jResp.string(of: "ProactiveInsights[i].Severity")
        Status = jResp.string(of: "ProactiveInsights[i].Status")
        j = 0
        count_j = jResp.size(ofArray: "ProactiveInsights[i].ResourceCollection.CloudFormation.StackNames").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "ProactiveInsights[i].ResourceCollection.CloudFormation.StackNames[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "ProactiveInsights[i].ResourceCollection.Tags").intValue
        while j < count_j {
            jResp.j = j
            AppBoundaryKey = jResp.string(of: "ProactiveInsights[i].ResourceCollection.Tags[j].AppBoundaryKey")
            k = 0
            count_k = jResp.size(ofArray: "ProactiveInsights[i].ResourceCollection.Tags[j].TagValues").intValue
            while k < count_k {
                jResp.k = k
                strVal = jResp.string(of: "ProactiveInsights[i].ResourceCollection.Tags[j].TagValues[k]")
                k = k + 1
            }

            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "ProactiveInsights[i].ServiceCollection.ServiceNames").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "ProactiveInsights[i].ServiceCollection.ServiceNames[j]")
            j = j + 1
        }

        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "ReactiveInsights").intValue
    while i < count_i {
        jResp.i = i
        AccountId = jResp.string(of: "ReactiveInsights[i].AccountId")
        Id = jResp.string(of: "ReactiveInsights[i].Id")
        InsightTimeRangeEndTime = jResp.int(of: "ReactiveInsights[i].InsightTimeRange.EndTime").intValue
        InsightTimeRangeStartTime = jResp.int(of: "ReactiveInsights[i].InsightTimeRange.StartTime").intValue
        Name = jResp.string(of: "ReactiveInsights[i].Name")
        OrganizationalUnitId = jResp.string(of: "ReactiveInsights[i].OrganizationalUnitId")
        Severity = jResp.string(of: "ReactiveInsights[i].Severity")
        Status = jResp.string(of: "ReactiveInsights[i].Status")
        j = 0
        count_j = jResp.size(ofArray: "ReactiveInsights[i].ResourceCollection.CloudFormation.StackNames").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "ReactiveInsights[i].ResourceCollection.CloudFormation.StackNames[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "ReactiveInsights[i].ResourceCollection.Tags").intValue
        while j < count_j {
            jResp.j = j
            AppBoundaryKey = jResp.string(of: "ReactiveInsights[i].ResourceCollection.Tags[j].AppBoundaryKey")
            k = 0
            count_k = jResp.size(ofArray: "ReactiveInsights[i].ResourceCollection.Tags[j].TagValues").intValue
            while k < count_k {
                jResp.k = k
                strVal = jResp.string(of: "ReactiveInsights[i].ResourceCollection.Tags[j].TagValues[k]")
                k = k + 1
            }

            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "ReactiveInsights[i].ServiceCollection.ServiceNames").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "ReactiveInsights[i].ServiceCollection.ServiceNames[j]")
            j = j + 1
        }

        i = i + 1
    }

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

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

}