Chilkat Online Tools

CreatePipeline Objective-C Example

AWS CodePipeline

#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 = @"codepipeline";
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
[rest SetAuthAws: authAws];

// URL: https://codepipeline.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = [rest Connect: @"codepipeline.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: @"pipeline.artifactStore.encryptionKey.id" value: @"string"];
[json UpdateString: @"pipeline.artifactStore.encryptionKey.type" value: @"string"];
[json UpdateString: @"pipeline.artifactStore.location" value: @"string"];
[json UpdateString: @"pipeline.artifactStore.type" value: @"string"];
[json UpdateString: @"pipeline.artifactStores.string.encryptionKey.id" value: @"string"];
[json UpdateString: @"pipeline.artifactStores.string.encryptionKey.type" value: @"string"];
[json UpdateString: @"pipeline.artifactStores.string.location" value: @"string"];
[json UpdateString: @"pipeline.artifactStores.string.type" value: @"string"];
[json UpdateString: @"pipeline.name" value: @"string"];
[json UpdateString: @"pipeline.roleArn" value: @"string"];
[json UpdateString: @"pipeline.stages[0].actions[0].actionTypeId.category" value: @"string"];
[json UpdateString: @"pipeline.stages[0].actions[0].actionTypeId.owner" value: @"string"];
[json UpdateString: @"pipeline.stages[0].actions[0].actionTypeId.provider" value: @"string"];
[json UpdateString: @"pipeline.stages[0].actions[0].actionTypeId.version" value: @"string"];
[json UpdateString: @"pipeline.stages[0].actions[0].configuration.string" value: @"string"];
[json UpdateString: @"pipeline.stages[0].actions[0].inputArtifacts[0].name" value: @"string"];
[json UpdateString: @"pipeline.stages[0].actions[0].name" value: @"string"];
[json UpdateString: @"pipeline.stages[0].actions[0].namespace" value: @"string"];
[json UpdateString: @"pipeline.stages[0].actions[0].outputArtifacts[0].name" value: @"string"];
[json UpdateString: @"pipeline.stages[0].actions[0].region" value: @"string"];
[json UpdateString: @"pipeline.stages[0].actions[0].roleArn" value: @"string"];
[json UpdateInt: @"pipeline.stages[0].actions[0].runOrder" value: [NSNumber numberWithInt: 123]];
[json UpdateString: @"pipeline.stages[0].blockers[0].name" value: @"string"];
[json UpdateString: @"pipeline.stages[0].blockers[0].type" value: @"string"];
[json UpdateString: @"pipeline.stages[0].name" value: @"string"];
[json UpdateInt: @"pipeline.version" value: [NSNumber numberWithInt: 123]];
[json UpdateString: @"tags[0].key" value: @"string"];
[json UpdateString: @"tags[0].value" value: @"string"];

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

// {
//   "pipeline": {
//     "artifactStore": {
//       "encryptionKey": {
//         "id": "string",
//         "type": "string"
//       },
//       "location": "string",
//       "type": "string"
//     },
//     "artifactStores": {
//       "string": {
//         "encryptionKey": {
//           "id": "string",
//           "type": "string"
//         },
//         "location": "string",
//         "type": "string"
//       }
//     },
//     "name": "string",
//     "roleArn": "string",
//     "stages": [
//       {
//         "actions": [
//           {
//             "actionTypeId": {
//               "category": "string",
//               "owner": "string",
//               "provider": "string",
//               "version": "string"
//             },
//             "configuration": {
//               "string": "string"
//             },
//             "inputArtifacts": [
//               {
//                 "name": "string"
//               }
//             ],
//             "name": "string",
//             "namespace": "string",
//             "outputArtifacts": [
//               {
//                 "name": "string"
//               }
//             ],
//             "region": "string",
//             "roleArn": "string",
//             "runOrder": number
//           }
//         ],
//         "blockers": [
//           {
//             "name": "string",
//             "type": "string"
//           }
//         ],
//         "name": "string"
//       }
//     ],
//     "version": number
//   },
//   "tags": [
//     {
//       "key": "string",
//       "value": "string"
//     }
//   ]
// }

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

CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[json EmitSb: sbRequestBody];
CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestSb: @"POST" uriPath: @"/" 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 *name = 0;
int j;
int count_j;
NSString *Category = 0;
NSString *Owner = 0;
NSString *Provider = 0;
NSString *actionTypeIdVersion = 0;
NSString *v_String = 0;
NSString *namespace = 0;
NSString *region = 0;
NSString *roleArn = 0;
int runOrder;
int k;
int count_k;
NSString *v_type = 0;
NSString *key = 0;
NSString *value = 0;

NSString *Id = [jResp StringOf: @"pipeline.artifactStore.encryptionKey.id"];
NSString *v_Type = [jResp StringOf: @"pipeline.artifactStore.encryptionKey.type"];
NSString *Location = [jResp StringOf: @"pipeline.artifactStore.location"];
NSString *ArtifactStoreType = [jResp StringOf: @"pipeline.artifactStore.type"];
NSString *EncryptionKeyId = [jResp StringOf: @"pipeline.artifactStores.string.encryptionKey.id"];
NSString *EncryptionKeyType = [jResp StringOf: @"pipeline.artifactStores.string.encryptionKey.type"];
NSString *StringLocation = [jResp StringOf: @"pipeline.artifactStores.string.location"];
NSString *StringType = [jResp StringOf: @"pipeline.artifactStores.string.type"];
NSString *Name = [jResp StringOf: @"pipeline.name"];
NSString *RoleArn = [jResp StringOf: @"pipeline.roleArn"];
int Version = [[jResp IntOf: @"pipeline.version"] intValue];
int i = 0;
int count_i = [[jResp SizeOfArray: @"pipeline.stages"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    name = [jResp StringOf: @"pipeline.stages[i].name"];
    j = 0;
    count_j = [[jResp SizeOfArray: @"pipeline.stages[i].actions"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        Category = [jResp StringOf: @"pipeline.stages[i].actions[j].actionTypeId.category"];
        Owner = [jResp StringOf: @"pipeline.stages[i].actions[j].actionTypeId.owner"];
        Provider = [jResp StringOf: @"pipeline.stages[i].actions[j].actionTypeId.provider"];
        actionTypeIdVersion = [jResp StringOf: @"pipeline.stages[i].actions[j].actionTypeId.version"];
        v_String = [jResp StringOf: @"pipeline.stages[i].actions[j].configuration.string"];
        name = [jResp StringOf: @"pipeline.stages[i].actions[j].name"];
        namespace = [jResp StringOf: @"pipeline.stages[i].actions[j].namespace"];
        region = [jResp StringOf: @"pipeline.stages[i].actions[j].region"];
        roleArn = [jResp StringOf: @"pipeline.stages[i].actions[j].roleArn"];
        runOrder = [[jResp IntOf: @"pipeline.stages[i].actions[j].runOrder"] intValue];
        k = 0;
        count_k = [[jResp SizeOfArray: @"pipeline.stages[i].actions[j].inputArtifacts"] intValue];
        while (k < count_k) {
            jResp.K = [NSNumber numberWithInt: k];
            name = [jResp StringOf: @"pipeline.stages[i].actions[j].inputArtifacts[k].name"];
            k = k + 1;
        }

        k = 0;
        count_k = [[jResp SizeOfArray: @"pipeline.stages[i].actions[j].outputArtifacts"] intValue];
        while (k < count_k) {
            jResp.K = [NSNumber numberWithInt: k];
            name = [jResp StringOf: @"pipeline.stages[i].actions[j].outputArtifacts[k].name"];
            k = k + 1;
        }

        j = j + 1;
    }

    j = 0;
    count_j = [[jResp SizeOfArray: @"pipeline.stages[i].blockers"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        name = [jResp StringOf: @"pipeline.stages[i].blockers[j].name"];
        v_type = [jResp StringOf: @"pipeline.stages[i].blockers[j].type"];
        j = j + 1;
    }

    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"tags"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    key = [jResp StringOf: @"tags[i].key"];
    value = [jResp StringOf: @"tags[i].value"];
    i = i + 1;
}

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

// {
//   "pipeline": {
//     "artifactStore": {
//       "encryptionKey": {
//         "id": "string",
//         "type": "string"
//       },
//       "location": "string",
//       "type": "string"
//     },
//     "artifactStores": {
//       "string": {
//         "encryptionKey": {
//           "id": "string",
//           "type": "string"
//         },
//         "location": "string",
//         "type": "string"
//       }
//     },
//     "name": "string",
//     "roleArn": "string",
//     "stages": [
//       {
//         "actions": [
//           {
//             "actionTypeId": {
//               "category": "string",
//               "owner": "string",
//               "provider": "string",
//               "version": "string"
//             },
//             "configuration": {
//               "string": "string"
//             },
//             "inputArtifacts": [
//               {
//                 "name": "string"
//               }
//             ],
//             "name": "string",
//             "namespace": "string",
//             "outputArtifacts": [
//               {
//                 "name": "string"
//               }
//             ],
//             "region": "string",
//             "roleArn": "string",
//             "runOrder": number
//           }
//         ],
//         "blockers": [
//           {
//             "name": "string",
//             "type": "string"
//           }
//         ],
//         "name": "string"
//       }
//     ],
//     "version": number
//   },
//   "tags": [
//     {
//       "key": "string",
//       "value": "string"
//     }
//   ]
// }