Chilkat Online Tools

GetDeployment unicodeCpp Example

AWS CodeDeploy

#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"codedeploy");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.SetAuthAws(authAws);

    // URL: https://codedeploy.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect(L"codedeploy.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"deploymentId",L"string");

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

    // {
    //   "deploymentId": "string"
    // }

    rest.AddHeader(L"Content-Type",L"application/x-amz-json-1.1");
    rest.AddHeader(L"X-Amz-Target",L"CodeDeploy_20141006.GetDeployment");

    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 *strVal = 0;
    const wchar_t *name = 0;
    int j;
    int count_j;
    const wchar_t *v_Type = 0;
    const wchar_t *Value = 0;

    const wchar_t *AdditionalDeploymentStatusInfo = jResp.stringOf(L"deploymentInfo.additionalDeploymentStatusInfo");
    const wchar_t *ApplicationName = jResp.stringOf(L"deploymentInfo.applicationName");
    int Enabled = jResp.IntOf(L"deploymentInfo.autoRollbackConfiguration.enabled");
    const wchar_t *ActionOnTimeout = jResp.stringOf(L"deploymentInfo.blueGreenDeploymentConfiguration.deploymentReadyOption.actionOnTimeout");
    int WaitTimeInMinutes = jResp.IntOf(L"deploymentInfo.blueGreenDeploymentConfiguration.deploymentReadyOption.waitTimeInMinutes");
    const wchar_t *Action = jResp.stringOf(L"deploymentInfo.blueGreenDeploymentConfiguration.greenFleetProvisioningOption.action");
    const wchar_t *TerminateBlueInstancesOnDeploymentSuccessAction = jResp.stringOf(L"deploymentInfo.blueGreenDeploymentConfiguration.terminateBlueInstancesOnDeploymentSuccess.action");
    int TerminationWaitTimeInMinutes = jResp.IntOf(L"deploymentInfo.blueGreenDeploymentConfiguration.terminateBlueInstancesOnDeploymentSuccess.terminationWaitTimeInMinutes");
    int CompleteTime = jResp.IntOf(L"deploymentInfo.completeTime");
    const wchar_t *ComputePlatform = jResp.stringOf(L"deploymentInfo.computePlatform");
    int CreateTime = jResp.IntOf(L"deploymentInfo.createTime");
    const wchar_t *Creator = jResp.stringOf(L"deploymentInfo.creator");
    const wchar_t *DeploymentConfigName = jResp.stringOf(L"deploymentInfo.deploymentConfigName");
    const wchar_t *DeploymentGroupName = jResp.stringOf(L"deploymentInfo.deploymentGroupName");
    const wchar_t *DeploymentId = jResp.stringOf(L"deploymentInfo.deploymentId");
    int Failed = jResp.IntOf(L"deploymentInfo.deploymentOverview.Failed");
    int InProgress = jResp.IntOf(L"deploymentInfo.deploymentOverview.InProgress");
    int Pending = jResp.IntOf(L"deploymentInfo.deploymentOverview.Pending");
    int Ready = jResp.IntOf(L"deploymentInfo.deploymentOverview.Ready");
    int Skipped = jResp.IntOf(L"deploymentInfo.deploymentOverview.Skipped");
    int Succeeded = jResp.IntOf(L"deploymentInfo.deploymentOverview.Succeeded");
    const wchar_t *DeploymentOption = jResp.stringOf(L"deploymentInfo.deploymentStyle.deploymentOption");
    const wchar_t *DeploymentType = jResp.stringOf(L"deploymentInfo.deploymentStyle.deploymentType");
    const wchar_t *Description = jResp.stringOf(L"deploymentInfo.description");
    const wchar_t *Code = jResp.stringOf(L"deploymentInfo.errorInformation.code");
    const wchar_t *Message = jResp.stringOf(L"deploymentInfo.errorInformation.message");
    const wchar_t *ExternalId = jResp.stringOf(L"deploymentInfo.externalId");
    const wchar_t *FileExistsBehavior = jResp.stringOf(L"deploymentInfo.fileExistsBehavior");
    int IgnoreApplicationStopFailures = jResp.IntOf(L"deploymentInfo.ignoreApplicationStopFailures");
    int InstanceTerminationWaitTimeStarted = jResp.IntOf(L"deploymentInfo.instanceTerminationWaitTimeStarted");
    const wchar_t *Content = jResp.stringOf(L"deploymentInfo.previousRevision.appSpecContent.content");
    const wchar_t *Sha256 = jResp.stringOf(L"deploymentInfo.previousRevision.appSpecContent.sha256");
    const wchar_t *CommitId = jResp.stringOf(L"deploymentInfo.previousRevision.gitHubLocation.commitId");
    const wchar_t *Repository = jResp.stringOf(L"deploymentInfo.previousRevision.gitHubLocation.repository");
    const wchar_t *RevisionType = jResp.stringOf(L"deploymentInfo.previousRevision.revisionType");
    const wchar_t *Bucket = jResp.stringOf(L"deploymentInfo.previousRevision.s3Location.bucket");
    const wchar_t *BundleType = jResp.stringOf(L"deploymentInfo.previousRevision.s3Location.bundleType");
    const wchar_t *ETag = jResp.stringOf(L"deploymentInfo.previousRevision.s3Location.eTag");
    const wchar_t *Key = jResp.stringOf(L"deploymentInfo.previousRevision.s3Location.key");
    const wchar_t *Version = jResp.stringOf(L"deploymentInfo.previousRevision.s3Location.version");
    const wchar_t *StringContent = jResp.stringOf(L"deploymentInfo.previousRevision.string.content");
    const wchar_t *StringSha256 = jResp.stringOf(L"deploymentInfo.previousRevision.string.sha256");
    const wchar_t *AutoUpdateOutdatedInstancesRootDeploymentId = jResp.stringOf(L"deploymentInfo.relatedDeployments.autoUpdateOutdatedInstancesRootDeploymentId");
    const wchar_t *AppSpecContentContent = jResp.stringOf(L"deploymentInfo.revision.appSpecContent.content");
    const wchar_t *AppSpecContentSha256 = jResp.stringOf(L"deploymentInfo.revision.appSpecContent.sha256");
    const wchar_t *GitHubLocationCommitId = jResp.stringOf(L"deploymentInfo.revision.gitHubLocation.commitId");
    const wchar_t *GitHubLocationRepository = jResp.stringOf(L"deploymentInfo.revision.gitHubLocation.repository");
    const wchar_t *RevisionRevisionType = jResp.stringOf(L"deploymentInfo.revision.revisionType");
    const wchar_t *S3LocationBucket = jResp.stringOf(L"deploymentInfo.revision.s3Location.bucket");
    const wchar_t *S3LocationBundleType = jResp.stringOf(L"deploymentInfo.revision.s3Location.bundleType");
    const wchar_t *S3LocationETag = jResp.stringOf(L"deploymentInfo.revision.s3Location.eTag");
    const wchar_t *S3LocationKey = jResp.stringOf(L"deploymentInfo.revision.s3Location.key");
    const wchar_t *S3LocationVersion = jResp.stringOf(L"deploymentInfo.revision.s3Location.version");
    StringContent = jResp.stringOf(L"deploymentInfo.revision.string.content");
    StringSha256 = jResp.stringOf(L"deploymentInfo.revision.string.sha256");
    const wchar_t *RollbackDeploymentId = jResp.stringOf(L"deploymentInfo.rollbackInfo.rollbackDeploymentId");
    const wchar_t *RollbackMessage = jResp.stringOf(L"deploymentInfo.rollbackInfo.rollbackMessage");
    const wchar_t *RollbackTriggeringDeploymentId = jResp.stringOf(L"deploymentInfo.rollbackInfo.rollbackTriggeringDeploymentId");
    int StartTime = jResp.IntOf(L"deploymentInfo.startTime");
    const wchar_t *Status = jResp.stringOf(L"deploymentInfo.status");
    int UpdateOutdatedInstancesOnly = jResp.IntOf(L"deploymentInfo.updateOutdatedInstancesOnly");
    int i = 0;
    int count_i = jResp.SizeOfArray(L"deploymentInfo.autoRollbackConfiguration.events");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"deploymentInfo.autoRollbackConfiguration.events[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"deploymentInfo.deploymentStatusMessages");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"deploymentInfo.deploymentStatusMessages[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"deploymentInfo.loadBalancerInfo.elbInfoList");
    while (i < count_i) {
        jResp.put_I(i);
        name = jResp.stringOf(L"deploymentInfo.loadBalancerInfo.elbInfoList[i].name");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"deploymentInfo.loadBalancerInfo.targetGroupInfoList");
    while (i < count_i) {
        jResp.put_I(i);
        name = jResp.stringOf(L"deploymentInfo.loadBalancerInfo.targetGroupInfoList[i].name");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"deploymentInfo.loadBalancerInfo.targetGroupPairInfoList");
    while (i < count_i) {
        jResp.put_I(i);
        j = 0;
        count_j = jResp.SizeOfArray(L"deploymentInfo.loadBalancerInfo.targetGroupPairInfoList[i].prodTrafficRoute.listenerArns");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf(L"deploymentInfo.loadBalancerInfo.targetGroupPairInfoList[i].prodTrafficRoute.listenerArns[j]");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray(L"deploymentInfo.loadBalancerInfo.targetGroupPairInfoList[i].targetGroups");
        while (j < count_j) {
            jResp.put_J(j);
            name = jResp.stringOf(L"deploymentInfo.loadBalancerInfo.targetGroupPairInfoList[i].targetGroups[j].name");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray(L"deploymentInfo.loadBalancerInfo.targetGroupPairInfoList[i].testTrafficRoute.listenerArns");
        while (j < count_j) {
            jResp.put_J(j);
            strVal = jResp.stringOf(L"deploymentInfo.loadBalancerInfo.targetGroupPairInfoList[i].testTrafficRoute.listenerArns[j]");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"deploymentInfo.relatedDeployments.autoUpdateOutdatedInstancesDeploymentIds");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"deploymentInfo.relatedDeployments.autoUpdateOutdatedInstancesDeploymentIds[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"deploymentInfo.targetInstances.autoScalingGroups");
    while (i < count_i) {
        jResp.put_I(i);
        strVal = jResp.stringOf(L"deploymentInfo.targetInstances.autoScalingGroups[i]");
        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"deploymentInfo.targetInstances.ec2TagSet.ec2TagSetList");
    while (i < count_i) {
        jResp.put_I(i);
        j = 0;
        count_j = jResp.SizeOfArray(L"deploymentInfo.targetInstances.ec2TagSet.ec2TagSetList[i]");
        while (j < count_j) {
            jResp.put_J(j);
            Key = jResp.stringOf(L"deploymentInfo.targetInstances.ec2TagSet.ec2TagSetList[i][j].Key");
            v_Type = jResp.stringOf(L"deploymentInfo.targetInstances.ec2TagSet.ec2TagSetList[i][j].Type");
            Value = jResp.stringOf(L"deploymentInfo.targetInstances.ec2TagSet.ec2TagSetList[i][j].Value");
            j = j + 1;
        }

        i = i + 1;
    }

    i = 0;
    count_i = jResp.SizeOfArray(L"deploymentInfo.targetInstances.tagFilters");
    while (i < count_i) {
        jResp.put_I(i);
        Key = jResp.stringOf(L"deploymentInfo.targetInstances.tagFilters[i].Key");
        v_Type = jResp.stringOf(L"deploymentInfo.targetInstances.tagFilters[i].Type");
        Value = jResp.stringOf(L"deploymentInfo.targetInstances.tagFilters[i].Value");
        i = i + 1;
    }

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

    // {
    //   "deploymentInfo": {
    //     "additionalDeploymentStatusInfo": "string",
    //     "applicationName": "string",
    //     "autoRollbackConfiguration": {
    //       "enabled": boolean,
    //       "events": [
    //         "string"
    //       ]
    //     },
    //     "blueGreenDeploymentConfiguration": {
    //       "deploymentReadyOption": {
    //         "actionOnTimeout": "string",
    //         "waitTimeInMinutes": number
    //       },
    //       "greenFleetProvisioningOption": {
    //         "action": "string"
    //       },
    //       "terminateBlueInstancesOnDeploymentSuccess": {
    //         "action": "string",
    //         "terminationWaitTimeInMinutes": number
    //       }
    //     },
    //     "completeTime": number,
    //     "computePlatform": "string",
    //     "createTime": number,
    //     "creator": "string",
    //     "deploymentConfigName": "string",
    //     "deploymentGroupName": "string",
    //     "deploymentId": "string",
    //     "deploymentOverview": {
    //       "Failed": number,
    //       "InProgress": number,
    //       "Pending": number,
    //       "Ready": number,
    //       "Skipped": number,
    //       "Succeeded": number
    //     },
    //     "deploymentStatusMessages": [
    //       "string"
    //     ],
    //     "deploymentStyle": {
    //       "deploymentOption": "string",
    //       "deploymentType": "string"
    //     },
    //     "description": "string",
    //     "errorInformation": {
    //       "code": "string",
    //       "message": "string"
    //     },
    //     "externalId": "string",
    //     "fileExistsBehavior": "string",
    //     "ignoreApplicationStopFailures": boolean,
    //     "instanceTerminationWaitTimeStarted": boolean,
    //     "loadBalancerInfo": {
    //       "elbInfoList": [
    //         {
    //           "name": "string"
    //         }
    //       ],
    //       "targetGroupInfoList": [
    //         {
    //           "name": "string"
    //         }
    //       ],
    //       "targetGroupPairInfoList": [
    //         {
    //           "prodTrafficRoute": {
    //             "listenerArns": [
    //               "string"
    //             ]
    //           },
    //           "targetGroups": [
    //             {
    //               "name": "string"
    //             }
    //           ],
    //           "testTrafficRoute": {
    //             "listenerArns": [
    //               "string"
    //             ]
    //           }
    //         }
    //       ]
    //     },
    //     "previousRevision": {
    //       "appSpecContent": {
    //         "content": "string",
    //         "sha256": "string"
    //       },
    //       "gitHubLocation": {
    //         "commitId": "string",
    //         "repository": "string"
    //       },
    //       "revisionType": "string",
    //       "s3Location": {
    //         "bucket": "string",
    //         "bundleType": "string",
    //         "eTag": "string",
    //         "key": "string",
    //         "version": "string"
    //       },
    //       "string": {
    //         "content": "string",
    //         "sha256": "string"
    //       }
    //     },
    //     "relatedDeployments": {
    //       "autoUpdateOutdatedInstancesDeploymentIds": [
    //         "string"
    //       ],
    //       "autoUpdateOutdatedInstancesRootDeploymentId": "string"
    //     },
    //     "revision": {
    //       "appSpecContent": {
    //         "content": "string",
    //         "sha256": "string"
    //       },
    //       "gitHubLocation": {
    //         "commitId": "string",
    //         "repository": "string"
    //       },
    //       "revisionType": "string",
    //       "s3Location": {
    //         "bucket": "string",
    //         "bundleType": "string",
    //         "eTag": "string",
    //         "key": "string",
    //         "version": "string"
    //       },
    //       "string": {
    //         "content": "string",
    //         "sha256": "string"
    //       }
    //     },
    //     "rollbackInfo": {
    //       "rollbackDeploymentId": "string",
    //       "rollbackMessage": "string",
    //       "rollbackTriggeringDeploymentId": "string"
    //     },
    //     "startTime": number,
    //     "status": "string",
    //     "targetInstances": {
    //       "autoScalingGroups": [
    //         "string"
    //       ],
    //       "ec2TagSet": {
    //         "ec2TagSetList": [
    //           [
    //             {
    //               "Key": "string",
    //               "Type": "string",
    //               "Value": "string"
    //             }
    //           ]
    //         ]
    //       },
    //       "tagFilters": [
    //         {
    //           "Key": "string",
    //           "Type": "string",
    //           "Value": "string"
    //         }
    //       ]
    //     },
    //     "updateOutdatedInstancesOnly": boolean
    //   }
    // }
    }