GetJob unicodeCpp Example
#include <CkRestW.h>
#include <CkAuthAwsW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.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"braket");
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.SetAuthAws(authAws);
// URL: https://braket.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = rest.Connect(L"braket.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;
}
rest.AddHeader(L"Content-Type",L"application/x-amz-json-1.1");
rest.AddHeader(L"X-Amz-Target",L"GetJob");
CkStringBuilderW sbResponseBody;
success = rest.FullRequestNoBodySb(L"GET",L"/job/{jobArn}",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 *eventType = 0;
const wchar_t *message = 0;
int timeOfEvent;
const wchar_t *channelName = 0;
const wchar_t *contentType = 0;
const wchar_t *S3DataSourceS3Uri = 0;
const wchar_t *Uri = jResp.stringOf(L"algorithmSpecification.containerImage.uri");
const wchar_t *CompressionType = jResp.stringOf(L"algorithmSpecification.scriptModeConfig.compressionType");
const wchar_t *EntryPoint = jResp.stringOf(L"algorithmSpecification.scriptModeConfig.entryPoint");
const wchar_t *S3Uri = jResp.stringOf(L"algorithmSpecification.scriptModeConfig.s3Uri");
int billableDuration = jResp.IntOf(L"billableDuration");
const wchar_t *LocalPath = jResp.stringOf(L"checkpointConfig.localPath");
const wchar_t *checkpointConfigS3Uri = jResp.stringOf(L"checkpointConfig.s3Uri");
int createdAt = jResp.IntOf(L"createdAt");
const wchar_t *Device = jResp.stringOf(L"deviceConfig.device");
int endedAt = jResp.IntOf(L"endedAt");
const wchar_t *failureReason = jResp.stringOf(L"failureReason");
const wchar_t *v_String = jResp.stringOf(L"hyperParameters.string");
int InstanceCount = jResp.IntOf(L"instanceConfig.instanceCount");
const wchar_t *InstanceType = jResp.stringOf(L"instanceConfig.instanceType");
int VolumeSizeInGb = jResp.IntOf(L"instanceConfig.volumeSizeInGb");
const wchar_t *jobArn = jResp.stringOf(L"jobArn");
const wchar_t *jobName = jResp.stringOf(L"jobName");
const wchar_t *KmsKeyId = jResp.stringOf(L"outputDataConfig.kmsKeyId");
const wchar_t *S3Path = jResp.stringOf(L"outputDataConfig.s3Path");
const wchar_t *roleArn = jResp.stringOf(L"roleArn");
int startedAt = jResp.IntOf(L"startedAt");
const wchar_t *status = jResp.stringOf(L"status");
int MaxRuntimeInSeconds = jResp.IntOf(L"stoppingCondition.maxRuntimeInSeconds");
const wchar_t *tagsString = jResp.stringOf(L"tags.string");
int i = 0;
int count_i = jResp.SizeOfArray(L"events");
while (i < count_i) {
jResp.put_I(i);
eventType = jResp.stringOf(L"events[i].eventType");
message = jResp.stringOf(L"events[i].message");
timeOfEvent = jResp.IntOf(L"events[i].timeOfEvent");
i = i + 1;
}
i = 0;
count_i = jResp.SizeOfArray(L"inputDataConfig");
while (i < count_i) {
jResp.put_I(i);
channelName = jResp.stringOf(L"inputDataConfig[i].channelName");
contentType = jResp.stringOf(L"inputDataConfig[i].contentType");
S3DataSourceS3Uri = jResp.stringOf(L"inputDataConfig[i].dataSource.s3DataSource.s3Uri");
i = i + 1;
}
// A sample JSON response body parsed by the above code:
// {
// "algorithmSpecification": {
// "containerImage": {
// "uri": "string"
// },
// "scriptModeConfig": {
// "compressionType": "string",
// "entryPoint": "string",
// "s3Uri": "string"
// }
// },
// "billableDuration": number,
// "checkpointConfig": {
// "localPath": "string",
// "s3Uri": "string"
// },
// "createdAt": number,
// "deviceConfig": {
// "device": "string"
// },
// "endedAt": number,
// "events": [
// {
// "eventType": "string",
// "message": "string",
// "timeOfEvent": number
// }
// ],
// "failureReason": "string",
// "hyperParameters": {
// "string": "string"
// },
// "inputDataConfig": [
// {
// "channelName": "string",
// "contentType": "string",
// "dataSource": {
// "s3DataSource": {
// "s3Uri": "string"
// }
// }
// }
// ],
// "instanceConfig": {
// "instanceCount": number,
// "instanceType": "string",
// "volumeSizeInGb": number
// },
// "jobArn": "string",
// "jobName": "string",
// "outputDataConfig": {
// "kmsKeyId": "string",
// "s3Path": "string"
// },
// "roleArn": "string",
// "startedAt": number,
// "status": "string",
// "stoppingCondition": {
// "maxRuntimeInSeconds": number
// },
// "tags": {
// "string": "string"
// }
// }
}