Chilkat Online Tools

DescribeAddonVersions Objective-C Example

Amazon Elastic Kubernetes Service

#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 = @"eks";
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
[rest SetAuthAws: authAws];

// URL: https://eks.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = [rest Connect: @"eks.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: @"DescribeAddonVersions"];

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestNoBodySb: @"GET" uriPath: @"/addons/supported-versions" 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 *addonName = 0;
NSString *v_type = 0;
int j;
int count_j;
NSString *addonVersion = 0;
int k;
int count_k;
NSString *strVal = 0;
NSString *clusterVersion = 0;
int defaultVersion;
CkoJsonObject *json1 = 0;
int i1;
int count_i1;

NSString *nextToken = [jResp StringOf: @"nextToken"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"addons"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    addonName = [jResp StringOf: @"addons[i].addonName"];
    v_type = [jResp StringOf: @"addons[i].type"];
    j = 0;
    count_j = [[jResp SizeOfArray: @"addons[i].addonVersions"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        addonVersion = [jResp StringOf: @"addons[i].addonVersions[j].addonVersion"];
        k = 0;
        count_k = [[jResp SizeOfArray: @"addons[i].addonVersions[j].architecture"] intValue];
        while (k < count_k) {
            jResp.K = [NSNumber numberWithInt: k];
            strVal = [jResp StringOf: @"addons[i].addonVersions[j].architecture[k]"];
            k = k + 1;
        }

        k = 0;
        count_k = [[jResp SizeOfArray: @"addons[i].addonVersions[j].compatibilities"] intValue];
        while (k < count_k) {
            jResp.K = [NSNumber numberWithInt: k];
            clusterVersion = [jResp StringOf: @"addons[i].addonVersions[j].compatibilities[k].clusterVersion"];
            defaultVersion = [[jResp IntOf: @"addons[i].addonVersions[j].compatibilities[k].defaultVersion"] intValue];

            json1 = [jResp ObjectOf: @"addons[i].addonVersions[j].compatibilities[k]"];
            i1 = 0;
            count_i1 = [[json1 SizeOfArray: @"platformVersions"] intValue];
            while (i1 < count_i1) {
                json1.I = [NSNumber numberWithInt: i1];
                strVal = [json1 StringOf: @"platformVersions[i]"];
                i1 = i1 + 1;
            }

            k = k + 1;
        }

        j = j + 1;
    }

    i = i + 1;
}

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

// {
//   "addons": [
//     {
//       "addonName": "string",
//       "addonVersions": [
//         {
//           "addonVersion": "string",
//           "architecture": [
//             "string"
//           ],
//           "compatibilities": [
//             {
//               "clusterVersion": "string",
//               "defaultVersion": boolean,
//               "platformVersions": [
//                 "string"
//               ]
//             }
//           ]
//         }
//       ],
//       "type": "string"
//     }
//   ],
//   "nextToken": "string"
// }