Chilkat Online Tools

ListLicenseVersions unicodeCpp Example

AWS License Manager

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

    // URL: https://license-manager.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.Connect(L"license-manager.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"LicenseArn",L"string");
    json.UpdateInt(L"MaxResults",123);
    json.UpdateString(L"NextToken",L"string");

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

    // {
    //   "LicenseArn": "string",
    //   "MaxResults": number,
    //   "NextToken": "string"
    // }

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

    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 *Beneficiary = 0;
    int AllowEarlyCheckIn;
    int MaxTimeToLiveInMinutes;
    int ProvisionalConfigurationMaxTimeToLiveInMinutes;
    const wchar_t *RenewType = 0;
    const wchar_t *CreateTime = 0;
    const wchar_t *HomeRegion = 0;
    const wchar_t *KeyFingerprint = 0;
    const wchar_t *Name = 0;
    const wchar_t *SignKey = 0;
    const wchar_t *LicenseArn = 0;
    const wchar_t *LicenseName = 0;
    const wchar_t *ProductName = 0;
    const wchar_t *ProductSKU = 0;
    const wchar_t *Status = 0;
    const wchar_t *Begin = 0;
    const wchar_t *v_End = 0;
    const wchar_t *Version = 0;
    int j;
    int count_j;
    int AllowCheckIn;
    int MaxCount;
    int Overage;
    const wchar_t *Unit = 0;
    const wchar_t *Value = 0;

    const wchar_t *NextToken = jResp.stringOf(L"NextToken");
    int i = 0;
    int count_i = jResp.SizeOfArray(L"Licenses");
    while (i < count_i) {
        jResp.put_I(i);
        Beneficiary = jResp.stringOf(L"Licenses[i].Beneficiary");
        AllowEarlyCheckIn = jResp.IntOf(L"Licenses[i].ConsumptionConfiguration.BorrowConfiguration.AllowEarlyCheckIn");
        MaxTimeToLiveInMinutes = jResp.IntOf(L"Licenses[i].ConsumptionConfiguration.BorrowConfiguration.MaxTimeToLiveInMinutes");
        ProvisionalConfigurationMaxTimeToLiveInMinutes = jResp.IntOf(L"Licenses[i].ConsumptionConfiguration.ProvisionalConfiguration.MaxTimeToLiveInMinutes");
        RenewType = jResp.stringOf(L"Licenses[i].ConsumptionConfiguration.RenewType");
        CreateTime = jResp.stringOf(L"Licenses[i].CreateTime");
        HomeRegion = jResp.stringOf(L"Licenses[i].HomeRegion");
        KeyFingerprint = jResp.stringOf(L"Licenses[i].Issuer.KeyFingerprint");
        Name = jResp.stringOf(L"Licenses[i].Issuer.Name");
        SignKey = jResp.stringOf(L"Licenses[i].Issuer.SignKey");
        LicenseArn = jResp.stringOf(L"Licenses[i].LicenseArn");
        LicenseName = jResp.stringOf(L"Licenses[i].LicenseName");
        ProductName = jResp.stringOf(L"Licenses[i].ProductName");
        ProductSKU = jResp.stringOf(L"Licenses[i].ProductSKU");
        Status = jResp.stringOf(L"Licenses[i].Status");
        Begin = jResp.stringOf(L"Licenses[i].Validity.Begin");
        v_End = jResp.stringOf(L"Licenses[i].Validity.End");
        Version = jResp.stringOf(L"Licenses[i].Version");
        j = 0;
        count_j = jResp.SizeOfArray(L"Licenses[i].Entitlements");
        while (j < count_j) {
            jResp.put_J(j);
            AllowCheckIn = jResp.IntOf(L"Licenses[i].Entitlements[j].AllowCheckIn");
            MaxCount = jResp.IntOf(L"Licenses[i].Entitlements[j].MaxCount");
            Name = jResp.stringOf(L"Licenses[i].Entitlements[j].Name");
            Overage = jResp.IntOf(L"Licenses[i].Entitlements[j].Overage");
            Unit = jResp.stringOf(L"Licenses[i].Entitlements[j].Unit");
            Value = jResp.stringOf(L"Licenses[i].Entitlements[j].Value");
            j = j + 1;
        }

        j = 0;
        count_j = jResp.SizeOfArray(L"Licenses[i].LicenseMetadata");
        while (j < count_j) {
            jResp.put_J(j);
            Name = jResp.stringOf(L"Licenses[i].LicenseMetadata[j].Name");
            Value = jResp.stringOf(L"Licenses[i].LicenseMetadata[j].Value");
            j = j + 1;
        }

        i = i + 1;
    }

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

    // {
    //   "Licenses": [
    //     {
    //       "Beneficiary": "string",
    //       "ConsumptionConfiguration": {
    //         "BorrowConfiguration": {
    //           "AllowEarlyCheckIn": boolean,
    //           "MaxTimeToLiveInMinutes": number
    //         },
    //         "ProvisionalConfiguration": {
    //           "MaxTimeToLiveInMinutes": number
    //         },
    //         "RenewType": "string"
    //       },
    //       "CreateTime": "string",
    //       "Entitlements": [
    //         {
    //           "AllowCheckIn": boolean,
    //           "MaxCount": number,
    //           "Name": "string",
    //           "Overage": boolean,
    //           "Unit": "string",
    //           "Value": "string"
    //         }
    //       ],
    //       "HomeRegion": "string",
    //       "Issuer": {
    //         "KeyFingerprint": "string",
    //         "Name": "string",
    //         "SignKey": "string"
    //       },
    //       "LicenseArn": "string",
    //       "LicenseMetadata": [
    //         {
    //           "Name": "string",
    //           "Value": "string"
    //         }
    //       ],
    //       "LicenseName": "string",
    //       "ProductName": "string",
    //       "ProductSKU": "string",
    //       "Status": "string",
    //       "Validity": {
    //         "Begin": "string",
    //         "End": "string"
    //       },
    //       "Version": "string"
    //     }
    //   ],
    //   "NextToken": "string"
    // }
    }