GetComponent Objective-C Example
뀈ല䀈ఫn style="color: rgb(0,123,181)">#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 = @"imagebuilder";
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
[rest SetAuthAws: authAws];
// URL: https://imagebuilder.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = [rest Connect: @"imagebuilder.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: @"GetComponent"];
CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestNoBodySb: @"GET" uriPath: @"/GetComponent" 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 *description = 0;
NSString *name = 0;
NSString *v_type = 0;
int j;
int count_j;
NSString *strVal = 0;
NSString *Arn = [jResp StringOf: @"component.arn"];
NSString *ChangeDescription = [jResp StringOf: @"component.changeDescription"];
NSString *Data = [jResp StringOf: @"component.data"];
NSString *DateCreated = [jResp StringOf: @"component.dateCreated"];
NSString *Description = [jResp StringOf: @"component.description"];
int Encrypted = [[jResp IntOf: @"component.encrypted"] intValue];
NSString *KmsKeyId = [jResp StringOf: @"component.kmsKeyId"];
NSString *Name = [jResp StringOf: @"component.name"];
NSString *Owner = [jResp StringOf: @"component.owner"];
NSString *Platform = [jResp StringOf: @"component.platform"];
NSString *Reason = [jResp StringOf: @"component.state.reason"];
NSString *Status = [jResp StringOf: @"component.state.status"];
NSString *v_String = [jResp StringOf: @"component.tags.string"];
NSString *v_Type = [jResp StringOf: @"component.type"];
NSString *Version = [jResp StringOf: @"component.version"];
NSString *requestId = [jResp StringOf: @"requestId"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"component.parameters"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: i];
description = [jResp StringOf: @"component.parameters[i].description"];
name = [jResp StringOf: @"component.parameters[i].name"];
v_type = [jResp StringOf: @"component.parameters[i].type"];
j = 0;
count_j = [[jResp SizeOfArray: @"component.parameters[i].defaultValue"] intValue];
while (j < count_j) {
jResp.J = [NSNumber numberWithInt: j];
strVal = [jResp StringOf: @"component.parameters[i].defaultValue[j]"];
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = [[jResp SizeOfArray: @"component.supportedOsVersions"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: i];
strVal = [jResp StringOf: @"component.supportedOsVersions[i]"];
i = i + 1;
}
// A sample JSON response body parsed by the above code:
// {
// "component": {
// "arn": "string",
// "changeDescription": "string",
// "data": "string",
// "dateCreated": "string",
// "description": "string",
// "encrypted": boolean,
// "kmsKeyId": "string",
// "name": "string",
// "owner": "string",
// "parameters": [
// {
// "defaultValue": [
// "string"
// ],
// "description": "string",
// "name": "string",
// "type": "string"
// }
// ],
// "platform": "string",
// "state": {
// "reason": "string",
// "status": "string"
// },
// "supportedOsVersions": [
// "string"
// ],
// "tags": {
// "string": "string"
// },
// "type": "string",
// "version": "string"
// },
// "requestId": "string"
// }