Chilkat Online Tools

GetCoreNetworkChangeSet Objective-C Example

AWS Network Manager

#import <CkoRest.h>
#import <CkoAuthAws.h>
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <NSString.h>

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

CkoRest *rest = [[CkoRest alloc] init];
BOOL success;

CkoAuthAws *authAws = [[CkoAuthAws alloc] init];
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: [NSNumber numberWithInt: 443] tls: YES autoReconnect: YES];
if (success != YES) {
    NSLog(@"%@%d",@"ConnectFailReason: ",[rest.ConnectFailReason intValue]);
    NSLog(@"%@",rest.LastErrorText);
    return;
}

[rest AddHeader: @"Content-Type" value: @"application/x-amz-json-1.1"];
[rest AddHeader: @"X-Amz-Target" value: @"GetCoreNetworkChangeSet"];

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestNoBodySb: @"GET" uriPath: @"/core-networks/{coreNetworkId}/core-network-change-sets/{policyVersionId}" sb: sbResponseBody];
if (success != YES) {
    NSLog(@"%@",rest.LastErrorText);
    return;
}

int respStatusCode = [rest.ResponseStatusCode intValue];
NSLog(@"%@%d",@"response status code = ",respStatusCode);
if (respStatusCode != 200) {
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",rest.ResponseHeader);
    NSLog(@"%@",@"Response Body:");
    NSLog(@"%@",[sbResponseBody GetAsString]);
    return;
}

CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[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

NSString *Action = 0;
NSString *Identifier = 0;
int v_Asn;
NSString *Cidr = 0;
NSString *DestinationIdentifier = 0;
NSString *SegmentName = 0;
int PreviousValuesAsn;
NSString *PreviousValuesCidr = 0;
NSString *PreviousValuesDestinationIdentifier = 0;
NSString *PreviousValuesSegmentName = 0;
NSString *v_Type = 0;
int j;
int count_j;
NSString *strVal = 0;

NSString *NextToken = [jResp StringOf: @"NextToken"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"CoreNetworkChanges"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    Action = [jResp StringOf: @"CoreNetworkChanges[i].Action"];
    Identifier = [jResp StringOf: @"CoreNetworkChanges[i].Identifier"];
    v_Asn = [[jResp IntOf: @"CoreNetworkChanges[i].NewValues.Asn"] intValue];
    Cidr = [jResp StringOf: @"CoreNetworkChanges[i].NewValues.Cidr"];
    DestinationIdentifier = [jResp StringOf: @"CoreNetworkChanges[i].NewValues.DestinationIdentifier"];
    SegmentName = [jResp StringOf: @"CoreNetworkChanges[i].NewValues.SegmentName"];
    PreviousValuesAsn = [[jResp IntOf: @"CoreNetworkChanges[i].PreviousValues.Asn"] intValue];
    PreviousValuesCidr = [jResp StringOf: @"CoreNetworkChanges[i].PreviousValues.Cidr"];
    PreviousValuesDestinationIdentifier = [jResp StringOf: @"CoreNetworkChanges[i].PreviousValues.DestinationIdentifier"];
    PreviousValuesSegmentName = [jResp StringOf: @"CoreNetworkChanges[i].PreviousValues.SegmentName"];
    v_Type = [jResp StringOf: @"CoreNetworkChanges[i].Type"];
    j = 0;
    count_j = [[jResp SizeOfArray: @"CoreNetworkChanges[i].NewValues.EdgeLocations"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        strVal = [jResp StringOf: @"CoreNetworkChanges[i].NewValues.EdgeLocations[j]"];
        j = j + 1;
    }

    j = 0;
    count_j = [[jResp SizeOfArray: @"CoreNetworkChanges[i].NewValues.InsideCidrBlocks"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        strVal = [jResp StringOf: @"CoreNetworkChanges[i].NewValues.InsideCidrBlocks[j]"];
        j = j + 1;
    }

    j = 0;
    count_j = [[jResp SizeOfArray: @"CoreNetworkChanges[i].NewValues.SharedSegments"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        strVal = [jResp StringOf: @"CoreNetworkChanges[i].NewValues.SharedSegments[j]"];
        j = j + 1;
    }

    j = 0;
    count_j = [[jResp SizeOfArray: @"CoreNetworkChanges[i].PreviousValues.EdgeLocations"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        strVal = [jResp StringOf: @"CoreNetworkChanges[i].PreviousValues.EdgeLocations[j]"];
        j = j + 1;
    }

    j = 0;
    count_j = [[jResp SizeOfArray: @"CoreNetworkChanges[i].PreviousValues.InsideCidrBlocks"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        strVal = [jResp StringOf: @"CoreNetworkChanges[i].PreviousValues.InsideCidrBlocks[j]"];
        j = j + 1;
    }

    j = 0;
    count_j = [[jResp SizeOfArray: @"CoreNetworkChanges[i].PreviousValues.SharedSegments"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        strVal = [jResp StringOf: @"CoreNetworkChanges[i].PreviousValues.SharedSegments[j]"];
        j = j + 1;
    }

    i = i + 1;
}

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

// {
//   "CoreNetworkChanges": [
//     {
//       "Action": "string",
//       "Identifier": "string",
//       "NewValues": {
//         "Asn": number,
//         "Cidr": "string",
//         "DestinationIdentifier": "string",
//         "EdgeLocations": [
//           "string"
//         ],
//         "InsideCidrBlocks": [
//           "string"
//         ],
//         "SegmentName": "string",
//         "SharedSegments": [
//           "string"
//         ]
//       },
//       "PreviousValues": {
//         "Asn": number,
//         "Cidr": "string",
//         "DestinationIdentifier": "string",
//         "EdgeLocations": [
//           "string"
//         ],
//         "InsideCidrBlocks": [
//           "string"
//         ],
//         "SegmentName": "string",
//         "SharedSegments": [
//           "string"
//         ]
//       },
//       "Type": "string"
//     }
//   ],
//   "NextToken": "string"
// }