CreateFleet 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"appstream");
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.SetAuthAws(authAws);
// URL: https://appstream2.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = rest.Connect(L"appstream2.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.UpdateInt(L"ComputeCapacity.DesiredInstances",123);
json.UpdateString(L"Description",L"string");
json.UpdateInt(L"DisconnectTimeoutInSeconds",123);
json.UpdateString(L"DisplayName",L"string");
json.UpdateString(L"DomainJoinInfo.DirectoryName",L"string");
json.UpdateString(L"DomainJoinInfo.OrganizationalUnitDistinguishedName",L"string");
json.UpdateInt(L"EnableDefaultInternetAccess",123);
json.UpdateString(L"FleetType",L"string");
json.UpdateString(L"IamRoleArn",L"string");
json.UpdateInt(L"IdleDisconnectTimeoutInSeconds",123);
json.UpdateString(L"ImageArn",L"string");
json.UpdateString(L"ImageName",L"string");
json.UpdateString(L"InstanceType",L"string");
json.UpdateInt(L"MaxConcurrentSessions",123);
json.UpdateInt(L"MaxUserDurationInSeconds",123);
json.UpdateString(L"Name",L"string");
json.UpdateString(L"Platform",L"string");
json.UpdateString(L"SessionScriptS3Location.S3Bucket",L"string");
json.UpdateString(L"SessionScriptS3Location.S3Key",L"string");
json.UpdateString(L"StreamView",L"string");
json.UpdateString(L"Tags.string",L"string");
json.UpdateString(L"UsbDeviceFilterStrings[0]",L"string");
json.UpdateString(L"VpcConfig.SecurityGroupIds[0]",L"string");
json.UpdateString(L"VpcConfig.SubnetIds[0]",L"string");
// The JSON request body created by the above code:
// {
// "ComputeCapacity": {
// "DesiredInstances": number
// },
// "Description": "string",
// "DisconnectTimeoutInSeconds": number,
// "DisplayName": "string",
// "DomainJoinInfo": {
// "DirectoryName": "string",
// "OrganizationalUnitDistinguishedName": "string"
// },
// "EnableDefaultInternetAccess": boolean,
// "FleetType": "string",
// "IamRoleArn": "string",
// "IdleDisconnectTimeoutInSeconds": number,
// "ImageArn": "string",
// "ImageName": "string",
// "InstanceType": "string",
// "MaxConcurrentSessions": number,
// "MaxUserDurationInSeconds": number,
// "Name": "string",
// "Platform": "string",
// "SessionScriptS3Location": {
// "S3Bucket": "string",
// "S3Key": "string"
// },
// "StreamView": "string",
// "Tags": {
// "string": "string"
// },
// "UsbDeviceFilterStrings": [
// "string"
// ],
// "VpcConfig": {
// "SecurityGroupIds": [
// "string"
// ],
// "SubnetIds": [
// "string"
// ]
// }
// }
rest.AddHeader(L"Content-Type",L"application/x-amz-json-1.1");
rest.AddHeader(L"X-Amz-Target",L"PhotonAdminProxyService.CreateFleet");
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 *ErrorCode = 0;
const wchar_t *ErrorMessage = 0;
const wchar_t *strVal = 0;
const wchar_t *Arn = jResp.stringOf(L"Fleet.Arn");
int Available = jResp.IntOf(L"Fleet.ComputeCapacityStatus.Available");
int Desired = jResp.IntOf(L"Fleet.ComputeCapacityStatus.Desired");
int InUse = jResp.IntOf(L"Fleet.ComputeCapacityStatus.InUse");
int Running = jResp.IntOf(L"Fleet.ComputeCapacityStatus.Running");
int CreatedTime = jResp.IntOf(L"Fleet.CreatedTime");
const wchar_t *Description = jResp.stringOf(L"Fleet.Description");
int DisconnectTimeoutInSeconds = jResp.IntOf(L"Fleet.DisconnectTimeoutInSeconds");
const wchar_t *DisplayName = jResp.stringOf(L"Fleet.DisplayName");
const wchar_t *DirectoryName = jResp.stringOf(L"Fleet.DomainJoinInfo.DirectoryName");
const wchar_t *OrganizationalUnitDistinguishedName = jResp.stringOf(L"Fleet.DomainJoinInfo.OrganizationalUnitDistinguishedName");
int EnableDefaultInternetAccess = jResp.IntOf(L"Fleet.EnableDefaultInternetAccess");
const wchar_t *FleetType = jResp.stringOf(L"Fleet.FleetType");
const wchar_t *IamRoleArn = jResp.stringOf(L"Fleet.IamRoleArn");
int IdleDisconnectTimeoutInSeconds = jResp.IntOf(L"Fleet.IdleDisconnectTimeoutInSeconds");
const wchar_t *ImageArn = jResp.stringOf(L"Fleet.ImageArn");
const wchar_t *ImageName = jResp.stringOf(L"Fleet.ImageName");
const wchar_t *InstanceType = jResp.stringOf(L"Fleet.InstanceType");
int MaxConcurrentSessions = jResp.IntOf(L"Fleet.MaxConcurrentSessions");
int MaxUserDurationInSeconds = jResp.IntOf(L"Fleet.MaxUserDurationInSeconds");
const wchar_t *Name = jResp.stringOf(L"Fleet.Name");
const wchar_t *Platform = jResp.stringOf(L"Fleet.Platform");
const wchar_t *S3Bucket = jResp.stringOf(L"Fleet.SessionScriptS3Location.S3Bucket");
const wchar_t *S3Key = jResp.stringOf(L"Fleet.SessionScriptS3Location.S3Key");
const wchar_t *State = jResp.stringOf(L"Fleet.State");
const wchar_t *StreamView = jResp.stringOf(L"Fleet.StreamView");
int i = 0;
int count_i = jResp.SizeOfArray(L"Fleet.FleetErrors");
while (i < count_i) {
jResp.put_I(i);
ErrorCode = jResp.stringOf(L"Fleet.FleetErrors[i].ErrorCode");
ErrorMessage = jResp.stringOf(L"Fleet.FleetErrors[i].ErrorMessage");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"Fleet.UsbDeviceFilterStrings");
while (i < count_i) {
jResp.put_I(i);
strVal = jResp.stringOf(L"Fleet.UsbDeviceFilterStrings[i]");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"Fleet.VpcConfig.SecurityGroupIds");
while (i < count_i) {
jResp.put_I(i);
strVal = jResp.stringOf(L"Fleet.VpcConfig.SecurityGroupIds[i]");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"Fleet.VpcConfig.SubnetIds");
while (i < count_i) {
jResp.put_I(i);
strVal = jResp.stringOf(L"Fleet.VpcConfig.SubnetIds[i]");
i = i + 1;
}
// A sample JSON response body parsed by the above code:
// {
// "Fleet": {
// "Arn": "string",
// "ComputeCapacityStatus": {
// "Available": number,
// "Desired": number,
// "InUse": number,
// "Running": number
// },
// "CreatedTime": number,
// "Description": "string",
// "DisconnectTimeoutInSeconds": number,
// "DisplayName": "string",
// "DomainJoinInfo": {
// "DirectoryName": "string",
// "OrganizationalUnitDistinguishedName": "string"
// },
// "EnableDefaultInternetAccess": boolean,
// "FleetErrors": [
// {
// "ErrorCode": "string",
// "ErrorMessage": "string"
// }
// ],
// "FleetType": "string",
// "IamRoleArn": "string",
// "IdleDisconnectTimeoutInSeconds": number,
// "ImageArn": "string",
// "ImageName": "string",
// "InstanceType": "string",
// "MaxConcurrentSessions": number,
// "MaxUserDurationInSeconds": number,
// "Name": "string",
// "Platform": "string",
// "SessionScriptS3Location": {
// "S3Bucket": "string",
// "S3Key": "string"
// },
// "State": "string",
// "StreamView": "string",
// "UsbDeviceFilterStrings": [
// "string"
// ],
// "VpcConfig": {
// "SecurityGroupIds": [
// "string"
// ],
// "SubnetIds": [
// "string"
// ]
// }
// }
// }
}