CreatePipeline unicodeCpp Example
#include <CkRestW.h>
#include <CkAuthAwsW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>
void ChilkatSample(void)
{
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkRestW rest;
bool success;
CkAuthAwsW authAws;
authAws.put_AccessKey(L"AWS_ACCESS_KEY");
authAws.put_SecretKey(L"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.put_Region(L"us-west-2");
authAws.put_ServiceName(L"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(L"codepipeline.us-west-2.amazonaws.com",443,true,true);
if (success != true) {
wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
wprintf(L"%s\n",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
CkJsonObjectW json;
json.UpdateString(L"pipeline.artifactStore.encryptionKey.id",L"string");
json.UpdateString(L"pipeline.artifactStore.encryptionKey.type",L"string");
json.UpdateString(L"pipeline.artifactStore.location",L"string");
json.UpdateString(L"pipeline.artifactStore.type",L"string");
json.UpdateString(L"pipeline.artifactStores.string.encryptionKey.id",L"string");
json.UpdateString(L"pipeline.artifactStores.string.encryptionKey.type",L"string");
json.UpdateString(L"pipeline.artifactStores.string.location",L"string");
json.UpdateString(L"pipeline.artifactStores.string.type",L"string");
json.UpdateString(L"pipeline.name",L"string");
json.UpdateString(L"pipeline.roleArn",L"string");
json.UpdateString(L"pipeline.stages[0].actions[0].actionTypeId.category",L"string");
json.UpdateString(L"pipeline.stages[0].actions[0].actionTypeId.owner",L"string");
json.UpdateString(L"pipeline.stages[0].actions[0].actionTypeId.provider",L"string");
json.UpdateString(L"pipeline.stages[0].actions[0].actionTypeId.version",L"string");
json.UpdateString(L"pipeline.stages[0].actions[0].configuration.string",L"string");
json.UpdateString(L"pipeline.stages[0].actions[0].inputArtifacts[0].name",L"string");
json.UpdateString(L"pipeline.stages[0].actions[0].name",L"string");
json.UpdateString(L"pipeline.stages[0].actions[0].namespace",L"string");
json.UpdateString(L"pipeline.stages[0].actions[0].outputArtifacts[0].name",L"string");
json.UpdateString(L"pipeline.stages[0].actions[0].region",L"string");
json.UpdateString(L"pipeline.stages[0].actions[0].roleArn",L"string");
json.UpdateInt(L"pipeline.stages[0].actions[0].runOrder",123);
json.UpdateString(L"pipeline.stages[0].blockers[0].name",L"string");
json.UpdateString(L"pipeline.stages[0].blockers[0].type",L"string");
json.UpdateString(L"pipeline.stages[0].name",L"string");
json.UpdateInt(L"pipeline.version",123);
json.UpdateString(L"tags[0].key",L"string");
json.UpdateString(L"tags[0].value",L"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(L"Content-Type",L"application/x-amz-json-1.1");
rest.AddHeader(L"X-Amz-Target",L"CodePipeline_20150709.CreatePipeline");
CkStringBuilderW sbRequestBody;
json.EmitSb(sbRequestBody);
CkStringBuilderW sbResponseBody;
success = rest.FullRequestSb(L"POST",L"/",sbRequestBody,sbResponseBody);
if (success != true) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
int respStatusCode = rest.get_ResponseStatusCode();
wprintf(L"response status code = %d\n",respStatusCode);
if (respStatusCode != 200) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",rest.responseHeader());
wprintf(L"Response Body:\n");
wprintf(L"%s\n",sbResponseBody.getAsString());
return;
}
CkJsonObjectW jResp;
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
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
// See this example explaining how this memory should be used: const char * functions.
const wchar_t *name = 0;
int j;
int count_j;
const wchar_t *Category = 0;
const wchar_t *Owner = 0;
const wchar_t *Provider = 0;
const wchar_t *actionTypeIdVersion = 0;
const wchar_t *v_String = 0;
const wchar_t *namespace = 0;
const wchar_t *region = 0;
const wchar_t *roleArn = 0;
int runOrder;
int k;
int count_k;
const wchar_t *v_type = 0;
const wchar_t *key = 0;
const wchar_t *value = 0;
const wchar_t *Id = jResp.stringOf(L"pipeline.artifactStore.encryptionKey.id");
const wchar_t *v_Type = jResp.stringOf(L"pipeline.artifactStore.encryptionKey.type");
const wchar_t *Location = jResp.stringOf(L"pipeline.artifactStore.location");
const wchar_t *ArtifactStoreType = jResp.stringOf(L"pipeline.artifactStore.type");
const wchar_t *EncryptionKeyId = jResp.stringOf(L"pipeline.artifactStores.string.encryptionKey.id");
const wchar_t *EncryptionKeyType = jResp.stringOf(L"pipeline.artifactStores.string.encryptionKey.type");
const wchar_t *StringLocation = jResp.stringOf(L"pipeline.artifactStores.string.location");
const wchar_t *StringType = jResp.stringOf(L"pipeline.artifactStores.string.type");
const wchar_t *Name = jResp.stringOf(L"pipeline.name");
const wchar_t *RoleArn = jResp.stringOf(L"pipeline.roleArn");
int Version = jResp.IntOf(L"pipeline.version");
int i = 0;
int count_i = jResp.SizeOfArray(L"pipeline.stages");
while (i < count_i) {
jResp.put_I(i);
name = jResp.stringOf(L"pipeline.stages[i].name");
j = 0;
count_j = jResp.SizeOfArray(L"pipeline.stages[i].actions");
while (j < count_j) {
jResp.put_J(j);
Category = jResp.stringOf(L"pipeline.stages[i].actions[j].actionTypeId.category");
Owner = jResp.stringOf(L"pipeline.stages[i].actions[j].actionTypeId.owner");
Provider = jResp.stringOf(L"pipeline.stages[i].actions[j].actionTypeId.provider");
actionTypeIdVersion = jResp.stringOf(L"pipeline.stages[i].actions[j].actionTypeId.version");
v_String = jResp.stringOf(L"pipeline.stages[i].actions[j].configuration.string");
name = jResp.stringOf(L"pipeline.stages[i].actions[j].name");
namespace = jResp.stringOf(L"pipeline.stages[i].actions[j].namespace");
region = jResp.stringOf(L"pipeline.stages[i].actions[j].region");
roleArn = jResp.stringOf(L"pipeline.stages[i].actions[j].roleArn");
runOrder = jResp.IntOf(L"pipeline.stages[i].actions[j].runOrder");
k = 0;
count_k = jResp.SizeOfArray(L"pipeline.stages[i].actions[j].inputArtifacts");
while (k < count_k) {
jResp.put_K(k);
name = jResp.stringOf(L"pipeline.stages[i].actions[j].inputArtifacts[k].name");
k = k + 1;
}
k = 0;
count_k = jResp.SizeOfArray(L"pipeline.stages[i].actions[j].outputArtifacts");
while (k < count_k) {
jResp.put_K(k);
name = jResp.stringOf(L"pipeline.stages[i].actions[j].outputArtifacts[k].name");
k = k + 1;
}
j = j + 1;
}
j = 0;
count_j = jResp.SizeOfArray(L"pipeline.stages[i].blockers");
while (j < count_j) {
jResp.put_J(j);
name = jResp.stringOf(L"pipeline.stages[i].blockers[j].name");
v_type = jResp.stringOf(L"pipeline.stages[i].blockers[j].type");
j = j + 1;
}
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"tags");
while (i < count_i) {
jResp.put_I(i);
key = jResp.stringOf(L"tags[i].key");
value = jResp.stringOf(L"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"
// }
// ]
// }
}