Chilkat Online Tools

StartRouteAnalysis Swift3 Example

AWS Network Manager

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

    // URL: https://networkmanager.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.connect("networkmanager.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("Destination.IpAddress", value: "string")
    json.update("Destination.TransitGatewayAttachmentArn", value: "string")
    json.updateInt("IncludeReturnPath", value: 123)
    json.update("Source.IpAddress", value: "string")
    json.update("Source.TransitGatewayAttachmentArn", value: "string")
    json.updateInt("UseMiddleboxes", value: 123)

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

    // {
    //   "Destination": {
    //     "IpAddress": "string",
    //     "TransitGatewayAttachmentArn": "string"
    //   },
    //   "IncludeReturnPath": boolean,
    //   "Source": {
    //     "IpAddress": "string",
    //     "TransitGatewayAttachmentArn": "string"
    //   },
    //   "UseMiddleboxes": boolean
    // }

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

    let sbRequestBody = CkoStringBuilder()!
    json.emitSb(sbRequestBody)
    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestSb("POST", uriPath: "/global-networks/{globalNetworkId}/route-analyses", 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 DestinationCidrBlock: String?
    var Definition: String?
    var IsMiddlebox: Int
    var NameTag: String?
    var RegisteredGatewayArn: String?
    var ResourceArn: String?
    var ResourceType: String?
    var Sequence: Int
    var ResourceDefinition: String?
    var ResourceIsMiddlebox: Int
    var ResourceNameTag: String?
    var ResourceRegisteredGatewayArn: String?
    var ResourceResourceArn: String?
    var ResourceResourceType: String?

    var IpAddress: String? = jResp.string(of: "RouteAnalysis.Destination.IpAddress")
    var TransitGatewayArn: String? = jResp.string(of: "RouteAnalysis.Destination.TransitGatewayArn")
    var TransitGatewayAttachmentArn: String? = jResp.string(of: "RouteAnalysis.Destination.TransitGatewayAttachmentArn")
    var ReasonCode: String? = jResp.string(of: "RouteAnalysis.ForwardPath.CompletionStatus.ReasonCode")
    var v_String: String? = jResp.string(of: "RouteAnalysis.ForwardPath.CompletionStatus.ReasonContext.string")
    var ResultCode: String? = jResp.string(of: "RouteAnalysis.ForwardPath.CompletionStatus.ResultCode")
    var GlobalNetworkId: String? = jResp.string(of: "RouteAnalysis.GlobalNetworkId")
    var IncludeReturnPath: Int = jResp.int(of: "RouteAnalysis.IncludeReturnPath").intValue
    var OwnerAccountId: String? = jResp.string(of: "RouteAnalysis.OwnerAccountId")
    var CompletionStatusReasonCode: String? = jResp.string(of: "RouteAnalysis.ReturnPath.CompletionStatus.ReasonCode")
    var ReasonContextString: String? = jResp.string(of: "RouteAnalysis.ReturnPath.CompletionStatus.ReasonContext.string")
    var CompletionStatusResultCode: String? = jResp.string(of: "RouteAnalysis.ReturnPath.CompletionStatus.ResultCode")
    var RouteAnalysisId: String? = jResp.string(of: "RouteAnalysis.RouteAnalysisId")
    var SourceIpAddress: String? = jResp.string(of: "RouteAnalysis.Source.IpAddress")
    var SourceTransitGatewayArn: String? = jResp.string(of: "RouteAnalysis.Source.TransitGatewayArn")
    var SourceTransitGatewayAttachmentArn: String? = jResp.string(of: "RouteAnalysis.Source.TransitGatewayAttachmentArn")
    var StartTimestamp: Int = jResp.int(of: "RouteAnalysis.StartTimestamp").intValue
    var Status: String? = jResp.string(of: "RouteAnalysis.Status")
    var UseMiddleboxes: Int = jResp.int(of: "RouteAnalysis.UseMiddleboxes").intValue
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "RouteAnalysis.ForwardPath.Path").intValue
    while i < count_i {
        jResp.i = i
        DestinationCidrBlock = jResp.string(of: "RouteAnalysis.ForwardPath.Path[i].DestinationCidrBlock")
        Definition = jResp.string(of: "RouteAnalysis.ForwardPath.Path[i].Resource.Definition")
        IsMiddlebox = jResp.int(of: "RouteAnalysis.ForwardPath.Path[i].Resource.IsMiddlebox").intValue
        NameTag = jResp.string(of: "RouteAnalysis.ForwardPath.Path[i].Resource.NameTag")
        RegisteredGatewayArn = jResp.string(of: "RouteAnalysis.ForwardPath.Path[i].Resource.RegisteredGatewayArn")
        ResourceArn = jResp.string(of: "RouteAnalysis.ForwardPath.Path[i].Resource.ResourceArn")
        ResourceType = jResp.string(of: "RouteAnalysis.ForwardPath.Path[i].Resource.ResourceType")
        Sequence = jResp.int(of: "RouteAnalysis.ForwardPath.Path[i].Sequence").intValue
        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "RouteAnalysis.ReturnPath.Path").intValue
    while i < count_i {
        jResp.i = i
        DestinationCidrBlock = jResp.string(of: "RouteAnalysis.ReturnPath.Path[i].DestinationCidrBlock")
        ResourceDefinition = jResp.string(of: "RouteAnalysis.ReturnPath.Path[i].Resource.Definition")
        ResourceIsMiddlebox = jResp.int(of: "RouteAnalysis.ReturnPath.Path[i].Resource.IsMiddlebox").intValue
        ResourceNameTag = jResp.string(of: "RouteAnalysis.ReturnPath.Path[i].Resource.NameTag")
        ResourceRegisteredGatewayArn = jResp.string(of: "RouteAnalysis.ReturnPath.Path[i].Resource.RegisteredGatewayArn")
        ResourceResourceArn = jResp.string(of: "RouteAnalysis.ReturnPath.Path[i].Resource.ResourceArn")
        ResourceResourceType = jResp.string(of: "RouteAnalysis.ReturnPath.Path[i].Resource.ResourceType")
        Sequence = jResp.int(of: "RouteAnalysis.ReturnPath.Path[i].Sequence").intValue
        i = i + 1
    }

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

    // {
    //   "RouteAnalysis": {
    //     "Destination": {
    //       "IpAddress": "string",
    //       "TransitGatewayArn": "string",
    //       "TransitGatewayAttachmentArn": "string"
    //     },
    //     "ForwardPath": {
    //       "CompletionStatus": {
    //         "ReasonCode": "string",
    //         "ReasonContext": {
    //           "string": "string"
    //         },
    //         "ResultCode": "string"
    //       },
    //       "Path": [
    //         {
    //           "DestinationCidrBlock": "string",
    //           "Resource": {
    //             "Definition": "string",
    //             "IsMiddlebox": boolean,
    //             "NameTag": "string",
    //             "RegisteredGatewayArn": "string",
    //             "ResourceArn": "string",
    //             "ResourceType": "string"
    //           },
    //           "Sequence": number
    //         }
    //       ]
    //     },
    //     "GlobalNetworkId": "string",
    //     "IncludeReturnPath": boolean,
    //     "OwnerAccountId": "string",
    //     "ReturnPath": {
    //       "CompletionStatus": {
    //         "ReasonCode": "string",
    //         "ReasonContext": {
    //           "string": "string"
    //         },
    //         "ResultCode": "string"
    //       },
    //       "Path": [
    //         {
    //           "DestinationCidrBlock": "string",
    //           "Resource": {
    //             "Definition": "string",
    //             "IsMiddlebox": boolean,
    //             "NameTag": "string",
    //             "RegisteredGatewayArn": "string",
    //             "ResourceArn": "string",
    //             "ResourceType": "string"
    //           },
    //           "Sequence": number
    //         }
    //       ]
    //     },
    //     "RouteAnalysisId": "string",
    //     "Source": {
    //       "IpAddress": "string",
    //       "TransitGatewayArn": "string",
    //       "TransitGatewayAttachmentArn": "string"
    //     },
    //     "StartTimestamp": number,
    //     "Status": "string",
    //     "UseMiddleboxes": boolean
    //   }
    // }

}