Chilkat Online Tools

ListServers Objective-C Example

Migration Hub Strategy Recommendations

#import <CkoRest.h>
#import <CkoAuthAws.h>
#import <CkoJsonObject.h>
#import <CkoStringBuilder.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 = @"migrationhub-strategy";
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
[rest SetAuthAws: authAws];

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

// 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

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"filterValue" value: @"string"];
[json UpdateString: @"groupIdFilter[0].name" value: @"string"];
[json UpdateString: @"groupIdFilter[0].value" value: @"string"];
[json UpdateInt: @"maxResults" value: [NSNumber numberWithInt: 123]];
[json UpdateString: @"nextToken" value: @"string"];
[json UpdateString: @"serverCriteria" value: @"string"];
[json UpdateString: @"sort" value: @"string"];

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

// {
//   "filterValue": "string",
//   "groupIdFilter": [
//     {
//       "name": "string",
//       "value": "string"
//     }
//   ],
//   "maxResults": number,
//   "nextToken": "string",
//   "serverCriteria": "string",
//   "sort": "string"
// }

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

CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[json EmitSb: sbRequestBody];
CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestSb: @"POST" uriPath: @"/list-servers" requestBody: sbRequestBody responseBody: 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 *S3Bucket = 0;
NSString *S3key = 0;
NSString *antipatternReportStatus = 0;
NSString *antipatternReportStatusMessage = 0;
NSString *dataCollectionStatus = 0;
NSString *id = 0;
int lastAnalyzedTimestamp;
NSString *name = 0;
NSString *Strategy = 0;
NSString *TargetDestination = 0;
NSString *Description = 0;
NSString *Name = 0;
NSString *TranformationToolInstallationLink = 0;
NSString *serverType = 0;
NSString *statusMessage = 0;
NSString *CpuArchitecture = 0;
NSString *FileSystemType = 0;
NSString *v_Type = 0;
NSString *Version = 0;
int j;
int count_j;
int count;
NSString *strategy = 0;
NSString *severity = 0;
NSString *interfaceName = 0;
NSString *ipAddress = 0;
NSString *macAddress = 0;
NSString *netMask = 0;

NSString *nextToken = [jResp StringOf: @"nextToken"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"serverInfos"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    S3Bucket = [jResp StringOf: @"serverInfos[i].antipatternReportS3Object.s3Bucket"];
    S3key = [jResp StringOf: @"serverInfos[i].antipatternReportS3Object.s3key"];
    antipatternReportStatus = [jResp StringOf: @"serverInfos[i].antipatternReportStatus"];
    antipatternReportStatusMessage = [jResp StringOf: @"serverInfos[i].antipatternReportStatusMessage"];
    dataCollectionStatus = [jResp StringOf: @"serverInfos[i].dataCollectionStatus"];
    id = [jResp StringOf: @"serverInfos[i].id"];
    lastAnalyzedTimestamp = [[jResp IntOf: @"serverInfos[i].lastAnalyzedTimestamp"] intValue];
    name = [jResp StringOf: @"serverInfos[i].name"];
    Strategy = [jResp StringOf: @"serverInfos[i].recommendationSet.strategy"];
    TargetDestination = [jResp StringOf: @"serverInfos[i].recommendationSet.targetDestination"];
    Description = [jResp StringOf: @"serverInfos[i].recommendationSet.transformationTool.description"];
    Name = [jResp StringOf: @"serverInfos[i].recommendationSet.transformationTool.name"];
    TranformationToolInstallationLink = [jResp StringOf: @"serverInfos[i].recommendationSet.transformationTool.tranformationToolInstallationLink"];
    serverType = [jResp StringOf: @"serverInfos[i].serverType"];
    statusMessage = [jResp StringOf: @"serverInfos[i].statusMessage"];
    CpuArchitecture = [jResp StringOf: @"serverInfos[i].systemInfo.cpuArchitecture"];
    FileSystemType = [jResp StringOf: @"serverInfos[i].systemInfo.fileSystemType"];
    v_Type = [jResp StringOf: @"serverInfos[i].systemInfo.osInfo.type"];
    Version = [jResp StringOf: @"serverInfos[i].systemInfo.osInfo.version"];
    j = 0;
    count_j = [[jResp SizeOfArray: @"serverInfos[i].applicationComponentStrategySummary"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        count = [[jResp IntOf: @"serverInfos[i].applicationComponentStrategySummary[j].count"] intValue];
        strategy = [jResp StringOf: @"serverInfos[i].applicationComponentStrategySummary[j].strategy"];
        j = j + 1;
    }

    j = 0;
    count_j = [[jResp SizeOfArray: @"serverInfos[i].listAntipatternSeveritySummary"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        count = [[jResp IntOf: @"serverInfos[i].listAntipatternSeveritySummary[j].count"] intValue];
        severity = [jResp StringOf: @"serverInfos[i].listAntipatternSeveritySummary[j].severity"];
        j = j + 1;
    }

    j = 0;
    count_j = [[jResp SizeOfArray: @"serverInfos[i].systemInfo.networkInfoList"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        interfaceName = [jResp StringOf: @"serverInfos[i].systemInfo.networkInfoList[j].interfaceName"];
        ipAddress = [jResp StringOf: @"serverInfos[i].systemInfo.networkInfoList[j].ipAddress"];
        macAddress = [jResp StringOf: @"serverInfos[i].systemInfo.networkInfoList[j].macAddress"];
        netMask = [jResp StringOf: @"serverInfos[i].systemInfo.networkInfoList[j].netMask"];
        j = j + 1;
    }

    i = i + 1;
}

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

// {
//   "nextToken": "string",
//   "serverInfos": [
//     {
//       "antipatternReportS3Object": {
//         "s3Bucket": "string",
//         "s3key": "string"
//       },
//       "antipatternReportStatus": "string",
//       "antipatternReportStatusMessage": "string",
//       "applicationComponentStrategySummary": [
//         {
//           "count": number,
//           "strategy": "string"
//         }
//       ],
//       "dataCollectionStatus": "string",
//       "id": "string",
//       "lastAnalyzedTimestamp": number,
//       "listAntipatternSeveritySummary": [
//         {
//           "count": number,
//           "severity": "string"
//         }
//       ],
//       "name": "string",
//       "recommendationSet": {
//         "strategy": "string",
//         "targetDestination": "string",
//         "transformationTool": {
//           "description": "string",
//           "name": "string",
//           "tranformationToolInstallationLink": "string"
//         }
//       },
//       "serverType": "string",
//       "statusMessage": "string",
//       "systemInfo": {
//         "cpuArchitecture": "string",
//         "fileSystemType": "string",
//         "networkInfoList": [
//           {
//             "interfaceName": "string",
//             "ipAddress": "string",
//             "macAddress": "string",
//             "netMask": "string"
//           }
//         ],
//         "osInfo": {
//           "type": "string",
//           "version": "string"
//         }
//       }
//     }
//   ]
// }