GetContainerRecipe 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: @"GetContainerRecipe"];
CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestNoBodySb: @"GET" uriPath: @"/GetContainerRecipe" 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 *componentArn = 0;
int j;
int count_j;
NSString *name = 0;
int k;
int count_k;
NSString *strVal = 0;
NSString *deviceName = 0;
int DeleteOnTermination;
int ebsEncrypted;
int Iops;
NSString *ebsKmsKeyId = 0;
NSString *SnapshotId = 0;
int Throughput;
int VolumeSize;
NSString *VolumeType = 0;
NSString *noDevice = 0;
NSString *virtualName = 0;
NSString *Arn = [jResp StringOf: @"containerRecipe.arn"];
NSString *ContainerType = [jResp StringOf: @"containerRecipe.containerType"];
NSString *DateCreated = [jResp StringOf: @"containerRecipe.dateCreated"];
NSString *Description = [jResp StringOf: @"containerRecipe.description"];
NSString *DockerfileTemplateData = [jResp StringOf: @"containerRecipe.dockerfileTemplateData"];
int Encrypted = [[jResp IntOf: @"containerRecipe.encrypted"] intValue];
NSString *Image = [jResp StringOf: @"containerRecipe.instanceConfiguration.image"];
NSString *KmsKeyId = [jResp StringOf: @"containerRecipe.kmsKeyId"];
NSString *Name = [jResp StringOf: @"containerRecipe.name"];
NSString *Owner = [jResp StringOf: @"containerRecipe.owner"];
NSString *ParentImage = [jResp StringOf: @"containerRecipe.parentImage"];
NSString *Platform = [jResp StringOf: @"containerRecipe.platform"];
NSString *v_String = [jResp StringOf: @"containerRecipe.tags.string"];
NSString *RepositoryName = [jResp StringOf: @"containerRecipe.targetRepository.repositoryName"];
NSString *Service = [jResp StringOf: @"containerRecipe.targetRepository.service"];
NSString *Version = [jResp StringOf: @"containerRecipe.version"];
NSString *WorkingDirectory = [jResp StringOf: @"containerRecipe.workingDirectory"];
NSString *requestId = [jResp StringOf: @"requestId"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"containerRecipe.components"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: i];
componentArn = [jResp StringOf: @"containerRecipe.components[i].componentArn"];
j = 0;
count_j = [[jResp SizeOfArray: @"containerRecipe.components[i].parameters"] intValue];
while (j < count_j) {
jResp.J = [NSNumber numberWithInt: j];
name = [jResp StringOf: @"containerRecipe.components[i].parameters[j].name"];
k = 0;
count_k = [[jResp SizeOfArray: @"containerRecipe.components[i].parameters[j].value"] intValue];
while (k < count_k) {
jResp.K = [NSNumber numberWithInt: k];
strVal = [jResp StringOf: @"containerRecipe.components[i].parameters[j].value[k]"];
k = k + 1;
}
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = [[jResp SizeOfArray: @"containerRecipe.instanceConfiguration.blockDeviceMappings"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: i];
deviceName = [jResp StringOf: @"containerRecipe.instanceConfiguration.blockDeviceMappings[i].deviceName"];
DeleteOnTermination = [[jResp IntOf: @"containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.deleteOnTermination"] intValue];
ebsEncrypted = [[jResp IntOf: @"containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.encrypted"] intValue];
Iops = [[jResp IntOf: @"containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.iops"] intValue];
ebsKmsKeyId = [jResp StringOf: @"containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.kmsKeyId"];
SnapshotId = [jResp StringOf: @"containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.snapshotId"];
Throughput = [[jResp IntOf: @"containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.throughput"] intValue];
VolumeSize = [[jResp IntOf: @"containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.volumeSize"] intValue];
VolumeType = [jResp StringOf: @"containerRecipe.instanceConfiguration.blockDeviceMappings[i].ebs.volumeType"];
noDevice = [jResp StringOf: @"containerRecipe.instanceConfiguration.blockDeviceMappings[i].noDevice"];
virtualName = [jResp StringOf: @"containerRecipe.instanceConfiguration.blockDeviceMappings[i].virtualName"];
i = i + 1;
}
// A sample JSON response body parsed by the above code:
// {
// "containerRecipe": {
// "arn": "string",
// "components": [
// {
// "componentArn": "string",
// "parameters": [
// {
// "name": "string",
// "value": [
// "string"
// ]
// }
// ]
// }
// ],
// "containerType": "string",
// "dateCreated": "string",
// "description": "string",
// "dockerfileTemplateData": "string",
// "encrypted": boolean,
// "instanceConfiguration": {
// "blockDeviceMappings": [
// {
// "deviceName": "string",
// "ebs": {
// "deleteOnTermination": boolean,
// "encrypted": boolean,
// "iops": number,
// "kmsKeyId": "string",
// "snapshotId": "string",
// "throughput": number,
// "volumeSize": number,
// "volumeType": "string"
// },
// "noDevice": "string",
// "virtualName": "string"
// }
// ],
// "image": "string"
// },
// "kmsKeyId": "string",
// "name": "string",
// "owner": "string",
// "parentImage": "string",
// "platform": "string",
// "tags": {
// "string": "string"
// },
// "targetRepository": {
// "repositoryName": "string",
// "service": "string"
// },
// "version": "string",
// "workingDirectory": "string"
// },
// "requestId": "string"
// }