GetImageRecipe Objective-C Example
#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: @"GetImageRecipe"];
CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestNoBodySb: @"GET" uriPath: @"/GetImageRecipe" 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 *deviceName = 0;
int DeleteOnTermination;
int Encrypted;
int Iops;
NSString *KmsKeyId = 0;
NSString *SnapshotId = 0;
int Throughput;
int VolumeSize;
NSString *VolumeType = 0;
NSString *noDevice = 0;
NSString *virtualName = 0;
NSString *componentArn = 0;
int j;
int count_j;
NSString *name = 0;
int k;
int count_k;
NSString *strVal = 0;
int UninstallAfterBuild = [[jResp IntOf: @"imageRecipe.additionalInstanceConfiguration.systemsManagerAgent.uninstallAfterBuild"] intValue];
NSString *UserDataOverride = [jResp StringOf: @"imageRecipe.additionalInstanceConfiguration.userDataOverride"];
NSString *Arn = [jResp StringOf: @"imageRecipe.arn"];
NSString *DateCreated = [jResp StringOf: @"imageRecipe.dateCreated"];
NSString *Description = [jResp StringOf: @"imageRecipe.description"];
NSString *Name = [jResp StringOf: @"imageRecipe.name"];
NSString *Owner = [jResp StringOf: @"imageRecipe.owner"];
NSString *ParentImage = [jResp StringOf: @"imageRecipe.parentImage"];
NSString *Platform = [jResp StringOf: @"imageRecipe.platform"];
NSString *v_String = [jResp StringOf: @"imageRecipe.tags.string"];
NSString *v_Type = [jResp StringOf: @"imageRecipe.type"];
NSString *Version = [jResp StringOf: @"imageRecipe.version"];
NSString *WorkingDirectory = [jResp StringOf: @"imageRecipe.workingDirectory"];
NSString *requestId = [jResp StringOf: @"requestId"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"imageRecipe.blockDeviceMappings"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: i];
deviceName = [jResp StringOf: @"imageRecipe.blockDeviceMappings[i].deviceName"];
DeleteOnTermination = [[jResp IntOf: @"imageRecipe.blockDeviceMappings[i].ebs.deleteOnTermination"] intValue];
Encrypted = [[jResp IntOf: @"imageRecipe.blockDeviceMappings[i].ebs.encrypted"] intValue];
Iops = [[jResp IntOf: @"imageRecipe.blockDeviceMappings[i].ebs.iops"] intValue];
KmsKeyId = [jResp StringOf: @"imageRecipe.blockDeviceMappings[i].ebs.kmsKeyId"];
SnapshotId = [jResp StringOf: @"imageRecipe.blockDeviceMappings[i].ebs.snapshotId"];
Throughput = [[jResp IntOf: @"imageRecipe.blockDeviceMappings[i].ebs.throughput"] intValue];
VolumeSize = [[jResp IntOf: @"imageRecipe.blockDeviceMappings[i].ebs.volumeSize"] intValue];
VolumeType = [jResp StringOf: @"imageRecipe.blockDeviceMappings[i].ebs.volumeType"];
noDevice = [jResp StringOf: @"imageRecipe.blockDeviceMappings[i].noDevice"];
virtualName = [jResp StringOf: @"imageRecipe.blockDeviceMappings[i].virtualName"];
i = i + 1;
}
i = 0;
count_i = [[jResp SizeOfArray: @"imageRecipe.components"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: i];
componentArn = [jResp StringOf: @"imageRecipe.components[i].componentArn"];
j = 0;
count_j = [[jResp SizeOfArray: @"imageRecipe.components[i].parameters"] intValue];
while (j < count_j) {
jResp.J = [NSNumber numberWithInt: j];
name = [jResp StringOf: @"imageRecipe.components[i].parameters[j].name"];
k = 0;
count_k = [[jResp SizeOfArray: @"imageRecipe.components[i].parameters[j].value"] intValue];
while (k < count_k) {
jResp.K = [NSNumber numberWithInt: k];
strVal = [jResp StringOf: @"imageRecipe.components[i].parameters[j].value[k]"];
k = k + 1;
}
j = j + 1;
}
i = i + 1;
}
// A sample JSON response body parsed by the above code:
// {
// "imageRecipe": {
// "additionalInstanceConfiguration": {
// "systemsManagerAgent": {
// "uninstallAfterBuild": boolean
// },
// "userDataOverride": "string"
// },
// "arn": "string",
// "blockDeviceMappings": [
// {
// "deviceName": "string",
// "ebs": {
// "deleteOnTermination": boolean,
// "encrypted": boolean,
// "iops": number,
// "kmsKeyId": "string",
// "snapshotId": "string",
// "throughput": number,
// "volumeSize": number,
// "volumeType": "string"
// },
// "noDevice": "string",
// "virtualName": "string"
// }
// ],
// "components": [
// {
// "componentArn": "string",
// "parameters": [
// {
// "name": "string",
// "value": [
// "string"
// ]
// }
// ]
// }
// ],
// "dateCreated": "string",
// "description": "string",
// "name": "string",
// "owner": "string",
// "parentImage": "string",
// "platform": "string",
// "tags": {
// "string": "string"
// },
// "type": "string",
// "version": "string",
// "workingDirectory": "string"
// },
// "requestId": "string"
// }