Chilkat Online Tools

GetJob C Example

Amazon Braket

#include <C_CkRest.h>
#include <C_CkAuthAws.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL success;
    HCkAuthAws authAws;
    HCkStringBuilder sbResponseBody;
    int respStatusCode;
    HCkJsonObject jResp;
    const char *eventType;
    const char *message;
    int timeOfEvent;
    const char *channelName;
    const char *contentType;
    const char *S3DataSourceS3Uri;
    const char *Uri;
    const char *CompressionType;
    const char *EntryPoint;
    const char *S3Uri;
    int billableDuration;
    const char *LocalPath;
    const char *checkpointConfigS3Uri;
    int createdAt;
    const char *Device;
    int endedAt;
    const char *failureReason;
    const char *v_String;
    int InstanceCount;
    const char *InstanceType;
    int VolumeSizeInGb;
    const char *jobArn;
    const char *jobName;
    const char *KmsKeyId;
    const char *S3Path;
    const char *roleArn;
    int startedAt;
    const char *status;
    int MaxRuntimeInSeconds;
    const char *tagsString;
    int i;
    int count_i;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    rest = CkRest_Create();

    authAws = CkAuthAws_Create();
    CkAuthAws_putAccessKey(authAws,"AWS_ACCESS_KEY");
    CkAuthAws_putSecretKey(authAws,"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.)
    CkAuthAws_putRegion(authAws,"us-west-2");
    CkAuthAws_putServiceName(authAws,"braket");
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    CkRest_SetAuthAws(rest,authAws);

    // URL: https://braket.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = CkRest_Connect(rest,"braket.us-west-2.amazonaws.com",443,TRUE,TRUE);
    if (success != TRUE) {
        printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkAuthAws_Dispose(authAws);
        return;
    }

    CkRest_AddHeader(rest,"Content-Type","application/x-amz-json-1.1");
    CkRest_AddHeader(rest,"X-Amz-Target","GetJob");

    sbResponseBody = CkStringBuilder_Create();
    success = CkRest_FullRequestNoBodySb(rest,"GET","/job/{jobArn}",sbResponseBody);
    if (success != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkAuthAws_Dispose(authAws);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    respStatusCode = CkRest_getResponseStatusCode(rest);
    printf("response status code = %d\n",respStatusCode);
    if (respStatusCode != 200) {
        printf("Response Header:\n");
        printf("%s\n",CkRest_responseHeader(rest));
        printf("Response Body:\n");
        printf("%s\n",CkStringBuilder_getAsString(sbResponseBody));
        CkRest_Dispose(rest);
        CkAuthAws_Dispose(authAws);
        CkStringBuilder_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObject_Create();
    CkJsonObject_LoadSb(jResp,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.

    Uri = CkJsonObject_stringOf(jResp,"algorithmSpecification.containerImage.uri");
    CompressionType = CkJsonObject_stringOf(jResp,"algorithmSpecification.scriptModeConfig.compressionType");
    EntryPoint = CkJsonObject_stringOf(jResp,"algorithmSpecification.scriptModeConfig.entryPoint");
    S3Uri = CkJsonObject_stringOf(jResp,"algorithmSpecification.scriptModeConfig.s3Uri");
    billableDuration = CkJsonObject_IntOf(jResp,"billableDuration");
    LocalPath = CkJsonObject_stringOf(jResp,"checkpointConfig.localPath");
    checkpointConfigS3Uri = CkJsonObject_stringOf(jResp,"checkpointConfig.s3Uri");
    createdAt = CkJsonObject_IntOf(jResp,"createdAt");
    Device = CkJsonObject_stringOf(jResp,"deviceConfig.device");
    endedAt = CkJsonObject_IntOf(jResp,"endedAt");
    failureReason = CkJsonObject_stringOf(jResp,"failureReason");
    v_String = CkJsonObject_stringOf(jResp,"hyperParameters.string");
    InstanceCount = CkJsonObject_IntOf(jResp,"instanceConfig.instanceCount");
    InstanceType = CkJsonObject_stringOf(jResp,"instanceConfig.instanceType");
    VolumeSizeInGb = CkJsonObject_IntOf(jResp,"instanceConfig.volumeSizeInGb");
    jobArn = CkJsonObject_stringOf(jResp,"jobArn");
    jobName = CkJsonObject_stringOf(jResp,"jobName");
    KmsKeyId = CkJsonObject_stringOf(jResp,"outputDataConfig.kmsKeyId");
    S3Path = CkJsonObject_stringOf(jResp,"outputDataConfig.s3Path");
    roleArn = CkJsonObject_stringOf(jResp,"roleArn");
    startedAt = CkJsonObject_IntOf(jResp,"startedAt");
    status = CkJsonObject_stringOf(jResp,"status");
    MaxRuntimeInSeconds = CkJsonObject_IntOf(jResp,"stoppingCondition.maxRuntimeInSeconds");
    tagsString = CkJsonObject_stringOf(jResp,"tags.string");
    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"events");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        eventType = CkJsonObject_stringOf(jResp,"events[i].eventType");
        message = CkJsonObject_stringOf(jResp,"events[i].message");
        timeOfEvent = CkJsonObject_IntOf(jResp,"events[i].timeOfEvent");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(jResp,"inputDataConfig");
    while (i < count_i) {
        CkJsonObject_putI(jResp,i);
        channelName = CkJsonObject_stringOf(jResp,"inputDataConfig[i].channelName");
        contentType = CkJsonObject_stringOf(jResp,"inputDataConfig[i].contentType");
        S3DataSourceS3Uri = CkJsonObject_stringOf(jResp,"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"
    //   }
    // }


    CkRest_Dispose(rest);
    CkAuthAws_Dispose(authAws);
    CkStringBuilder_Dispose(sbResponseBody);
    CkJsonObject_Dispose(jResp);

    }