Chilkat Online Tools

GetLicense 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.UpdateString(L"Version",L"string");

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

    // {
    //   "LicenseArn": "string",
    //   "Version": "string"
    // }

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

    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.

    int AllowCheckIn;
    int MaxCount;
    int Overage;
    const wchar_t *Unit = 0;
    const wchar_t *Value = 0;

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

    i = 0;
    count_i = jResp.SizeOfArray(L"License.LicenseMetadata");
    while (i < count_i) {
        jResp.put_I(i);
        Name = jResp.stringOf(L"License.LicenseMetadata[i].Name");
        Value = jResp.stringOf(L"License.LicenseMetadata[i].Value");
        i = i + 1;
    }

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

    // {
    //   "License": {
    //     "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"
    //   }
    // }
    }