GetLifecyclePolicy 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 = @"dlm";
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
[rest SetAuthAws: authAws];
// URL: https://dlm.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = [rest Connect: @"dlm.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: @"GetLifecyclePolicy"];
CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestNoBodySb: @"GET" uriPath: @"/policies/{policyId}/" 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 *Name = 0;
int j;
int count_j;
NSString *CmkArn = 0;
int Encrypted;
int Interval;
NSString *IntervalUnit = 0;
NSString *Target = 0;
NSString *strVal = 0;
int CopyTags;
NSString *CronExpression = 0;
int CreateRuleInterval;
NSString *CreateRuleIntervalUnit = 0;
NSString *Location = 0;
int Count;
int DeprecateRuleInterval;
NSString *DeprecateRuleIntervalUnit = 0;
int FastRestoreRuleCount;
int FastRestoreRuleInterval;
NSString *FastRestoreRuleIntervalUnit = 0;
int RetainRuleCount;
int RetainRuleInterval;
NSString *RetainRuleIntervalUnit = 0;
NSString *TargetRegion = 0;
int UnshareInterval;
NSString *UnshareIntervalUnit = 0;
int k;
int count_k;
NSString *Key = 0;
NSString *Value = 0;
int DateCreated = [[jResp IntOf: @"Policy.DateCreated"] intValue];
int DateModified = [[jResp IntOf: @"Policy.DateModified"] intValue];
NSString *Description = [jResp StringOf: @"Policy.Description"];
NSString *ExecutionRoleArn = [jResp StringOf: @"Policy.ExecutionRoleArn"];
NSString *PolicyArn = [jResp StringOf: @"Policy.PolicyArn"];
NSString *DescriptionRegex = [jResp StringOf: @"Policy.PolicyDetails.EventSource.Parameters.DescriptionRegex"];
NSString *EventType = [jResp StringOf: @"Policy.PolicyDetails.EventSource.Parameters.EventType"];
NSString *v_Type = [jResp StringOf: @"Policy.PolicyDetails.EventSource.Type"];
int ExcludeBootVolume = [[jResp IntOf: @"Policy.PolicyDetails.Parameters.ExcludeBootVolume"] intValue];
int NoReboot = [[jResp IntOf: @"Policy.PolicyDetails.Parameters.NoReboot"] intValue];
NSString *PolicyType = [jResp StringOf: @"Policy.PolicyDetails.PolicyType"];
NSString *PolicyId = [jResp StringOf: @"Policy.PolicyId"];
NSString *State = [jResp StringOf: @"Policy.State"];
NSString *StatusMessage = [jResp StringOf: @"Policy.StatusMessage"];
NSString *v_String = [jResp StringOf: @"Policy.Tags.string"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"Policy.PolicyDetails.Actions"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: i];
Name = [jResp StringOf: @"Policy.PolicyDetails.Actions[i].Name"];
j = 0;
count_j = [[jResp SizeOfArray: @"Policy.PolicyDetails.Actions[i].CrossRegionCopy"] intValue];
while (j < count_j) {
jResp.J = [NSNumber numberWithInt: j];
CmkArn = [jResp StringOf: @"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].EncryptionConfiguration.CmkArn"];
Encrypted = [[jResp IntOf: @"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].EncryptionConfiguration.Encrypted"] intValue];
Interval = [[jResp IntOf: @"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].RetainRule.Interval"] intValue];
IntervalUnit = [jResp StringOf: @"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].RetainRule.IntervalUnit"];
Target = [jResp StringOf: @"Policy.PolicyDetails.Actions[i].CrossRegionCopy[j].Target"];
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = [[jResp SizeOfArray: @"Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: i];
strVal = [jResp StringOf: @"Policy.PolicyDetails.EventSource.Parameters.SnapshotOwner[i]"];
i = i + 1;
}
i = 0;
count_i = [[jResp SizeOfArray: @"Policy.PolicyDetails.ResourceLocations"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: i];
strVal = [jResp StringOf: @"Policy.PolicyDetails.ResourceLocations[i]"];
i = i + 1;
}
i = 0;
count_i = [[jResp SizeOfArray: @"Policy.PolicyDetails.ResourceTypes"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: i];
strVal = [jResp StringOf: @"Policy.PolicyDetails.ResourceTypes[i]"];
i = i + 1;
}
i = 0;
count_i = [[jResp SizeOfArray: @"Policy.PolicyDetails.Schedules"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: i];
CopyTags = [[jResp IntOf: @"Policy.PolicyDetails.Schedules[i].CopyTags"] intValue];
CronExpression = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].CreateRule.CronExpression"];
CreateRuleInterval = [[jResp IntOf: @"Policy.PolicyDetails.Schedules[i].CreateRule.Interval"] intValue];
CreateRuleIntervalUnit = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].CreateRule.IntervalUnit"];
Location = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].CreateRule.Location"];
Count = [[jResp IntOf: @"Policy.PolicyDetails.Schedules[i].DeprecateRule.Count"] intValue];
DeprecateRuleInterval = [[jResp IntOf: @"Policy.PolicyDetails.Schedules[i].DeprecateRule.Interval"] intValue];
DeprecateRuleIntervalUnit = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].DeprecateRule.IntervalUnit"];
FastRestoreRuleCount = [[jResp IntOf: @"Policy.PolicyDetails.Schedules[i].FastRestoreRule.Count"] intValue];
FastRestoreRuleInterval = [[jResp IntOf: @"Policy.PolicyDetails.Schedules[i].FastRestoreRule.Interval"] intValue];
FastRestoreRuleIntervalUnit = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].FastRestoreRule.IntervalUnit"];
Name = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].Name"];
RetainRuleCount = [[jResp IntOf: @"Policy.PolicyDetails.Schedules[i].RetainRule.Count"] intValue];
RetainRuleInterval = [[jResp IntOf: @"Policy.PolicyDetails.Schedules[i].RetainRule.Interval"] intValue];
RetainRuleIntervalUnit = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].RetainRule.IntervalUnit"];
j = 0;
count_j = [[jResp SizeOfArray: @"Policy.PolicyDetails.Schedules[i].CreateRule.Times"] intValue];
while (j < count_j) {
jResp.J = [NSNumber numberWithInt: j];
strVal = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].CreateRule.Times[j]"];
j = j + 1;
}
j = 0;
count_j = [[jResp SizeOfArray: @"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules"] intValue];
while (j < count_j) {
jResp.J = [NSNumber numberWithInt: j];
CmkArn = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].CmkArn"];
CopyTags = [[jResp IntOf: @"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].CopyTags"] intValue];
DeprecateRuleInterval = [[jResp IntOf: @"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].DeprecateRule.Interval"] intValue];
DeprecateRuleIntervalUnit = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].DeprecateRule.IntervalUnit"];
Encrypted = [[jResp IntOf: @"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].Encrypted"] intValue];
RetainRuleInterval = [[jResp IntOf: @"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].RetainRule.Interval"] intValue];
RetainRuleIntervalUnit = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].RetainRule.IntervalUnit"];
Target = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].Target"];
TargetRegion = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].CrossRegionCopyRules[j].TargetRegion"];
j = j + 1;
}
j = 0;
count_j = [[jResp SizeOfArray: @"Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones"] intValue];
while (j < count_j) {
jResp.J = [NSNumber numberWithInt: j];
strVal = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].FastRestoreRule.AvailabilityZones[j]"];
j = j + 1;
}
j = 0;
count_j = [[jResp SizeOfArray: @"Policy.PolicyDetails.Schedules[i].ShareRules"] intValue];
while (j < count_j) {
jResp.J = [NSNumber numberWithInt: j];
UnshareInterval = [[jResp IntOf: @"Policy.PolicyDetails.Schedules[i].ShareRules[j].UnshareInterval"] intValue];
UnshareIntervalUnit = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].ShareRules[j].UnshareIntervalUnit"];
k = 0;
count_k = [[jResp SizeOfArray: @"Policy.PolicyDetails.Schedules[i].ShareRules[j].TargetAccounts"] intValue];
while (k < count_k) {
jResp.K = [NSNumber numberWithInt: k];
strVal = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].ShareRules[j].TargetAccounts[k]"];
k = k + 1;
}
j = j + 1;
}
j = 0;
count_j = [[jResp SizeOfArray: @"Policy.PolicyDetails.Schedules[i].TagsToAdd"] intValue];
while (j < count_j) {
jResp.J = [NSNumber numberWithInt: j];
Key = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].TagsToAdd[j].Key"];
Value = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].TagsToAdd[j].Value"];
j = j + 1;
}
j = 0;
count_j = [[jResp SizeOfArray: @"Policy.PolicyDetails.Schedules[i].VariableTags"] intValue];
while (j < count_j) {
jResp.J = [NSNumber numberWithInt: j];
Key = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].VariableTags[j].Key"];
Value = [jResp StringOf: @"Policy.PolicyDetails.Schedules[i].VariableTags[j].Value"];
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = [[jResp SizeOfArray: @"Policy.PolicyDetails.TargetTags"] intValue];
while (i < count_i) {
jResp.I = [NSNumber numberWithInt: i];
Key = [jResp StringOf: @"Policy.PolicyDetails.TargetTags[i].Key"];
Value = [jResp StringOf: @"Policy.PolicyDetails.TargetTags[i].Value"];
i = i + 1;
}
// A sample JSON response body parsed by the above code:
// {
// "Policy": {
// "DateCreated": number,
// "DateModified": number,
// "Description": "string",
// "ExecutionRoleArn": "string",
// "PolicyArn": "string",
// "PolicyDetails": {
// "Actions": [
// {
// "CrossRegionCopy": [
// {
// "EncryptionConfiguration": {
// "CmkArn": "string",
// "Encrypted": boolean
// },
// "RetainRule": {
// "Interval": number,
// "IntervalUnit": "string"
// },
// "Target": "string"
// }
// ],
// "Name": "string"
// }
// ],
// "EventSource": {
// "Parameters": {
// "DescriptionRegex": "string",
// "EventType": "string",
// "SnapshotOwner": [
// "string"
// ]
// },
// "Type": "string"
// },
// "Parameters": {
// "ExcludeBootVolume": boolean,
// "NoReboot": boolean
// },
// "PolicyType": "string",
// "ResourceLocations": [
// "string"
// ],
// "ResourceTypes": [
// "string"
// ],
// "Schedules": [
// {
// "CopyTags": boolean,
// "CreateRule": {
// "CronExpression": "string",
// "Interval": number,
// "IntervalUnit": "string",
// "Location": "string",
// "Times": [
// "string"
// ]
// },
// "CrossRegionCopyRules": [
// {
// "CmkArn": "string",
// "CopyTags": boolean,
// "DeprecateRule": {
// "Interval": number,
// "IntervalUnit": "string"
// },
// "Encrypted": boolean,
// "RetainRule": {
// "Interval": number,
// "IntervalUnit": "string"
// },
// "Target": "string",
// "TargetRegion": "string"
// }
// ],
// "DeprecateRule": {
// "Count": number,
// "Interval": number,
// "IntervalUnit": "string"
// },
// "FastRestoreRule": {
// "AvailabilityZones": [
// "string"
// ],
// "Count": number,
// "Interval": number,
// "IntervalUnit": "string"
// },
// "Name": "string",
// "RetainRule": {
// "Count": number,
// "Interval": number,
// "IntervalUnit": "string"
// },
// "ShareRules": [
// {
// "TargetAccounts": [
// "string"
// ],
// "UnshareInterval": number,
// "UnshareIntervalUnit": "string"
// }
// ],
// "TagsToAdd": [
// {
// "Key": "string",
// "Value": "string"
// }
// ],
// "VariableTags": [
// {
// "Key": "string",
// "Value": "string"
// }
// ]
// }
// ],
// "TargetTags": [
// {
// "Key": "string",
// "Value": "string"
// }
// ]
// },
// "PolicyId": "string",
// "State": "string",
// "StatusMessage": "string",
// "Tags": {
// "string": "string"
// }
// }
// }