ListApps C Example
#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 *appArn;
const char *appId;
const char *BasicAuthCredentials;
const char *BuildSpec;
int EnableAutoBuild;
int EnableBasicAuth;
int EnablePerformanceMode;
int EnablePullRequestPreview;
const char *v_String;
const char *Framework;
const char *PullRequestEnvironmentName;
const char *Stage;
const char *basicAuthCredentials;
const char *buildSpec;
int createTime;
const char *customHeaders;
const char *defaultDomain;
const char *description;
int enableAutoBranchCreation;
int enableBasicAuth;
int enableBranchAutoBuild;
int enableBranchAutoDeletion;
const char *environmentVariablesString;
const char *iamServiceRoleArn;
const char *name;
const char *platform;
const char *BranchName;
int LastDeployTime;
const char *Status;
const char *ThumbnailUrl;
const char *repository;
const char *repositoryCloneMethod;
const char *tagsString;
int updateTime;
int j;
int count_j;
const char *strVal;
const char *condition;
const char *source;
const char *status;
const char *target;
const char *nextToken;
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,"amplify");
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest_SetAuthAws(rest,authAws);
// URL: https://amplify.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = CkRest_Connect(rest,"amplify.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","ListApps");
sbResponseBody = CkStringBuilder_Create();
success = CkRest_FullRequestNoBodySb(rest,"GET","/apps",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.
nextToken = CkJsonObject_stringOf(jResp,"nextToken");
i = 0;
count_i = CkJsonObject_SizeOfArray(jResp,"apps");
while (i < count_i) {
CkJsonObject_putI(jResp,i);
appArn = CkJsonObject_stringOf(jResp,"apps[i].appArn");
appId = CkJsonObject_stringOf(jResp,"apps[i].appId");
BasicAuthCredentials = CkJsonObject_stringOf(jResp,"apps[i].autoBranchCreationConfig.basicAuthCredentials");
BuildSpec = CkJsonObject_stringOf(jResp,"apps[i].autoBranchCreationConfig.buildSpec");
EnableAutoBuild = CkJsonObject_IntOf(jResp,"apps[i].autoBranchCreationConfig.enableAutoBuild");
EnableBasicAuth = CkJsonObject_IntOf(jResp,"apps[i].autoBranchCreationConfig.enableBasicAuth");
EnablePerformanceMode = CkJsonObject_IntOf(jResp,"apps[i].autoBranchCreationConfig.enablePerformanceMode");
EnablePullRequestPreview = CkJsonObject_IntOf(jResp,"apps[i].autoBranchCreationConfig.enablePullRequestPreview");
v_String = CkJsonObject_stringOf(jResp,"apps[i].autoBranchCreationConfig.environmentVariables.string");
Framework = CkJsonObject_stringOf(jResp,"apps[i].autoBranchCreationConfig.framework");
PullRequestEnvironmentName = CkJsonObject_stringOf(jResp,"apps[i].autoBranchCreationConfig.pullRequestEnvironmentName");
Stage = CkJsonObject_stringOf(jResp,"apps[i].autoBranchCreationConfig.stage");
basicAuthCredentials = CkJsonObject_stringOf(jResp,"apps[i].basicAuthCredentials");
buildSpec = CkJsonObject_stringOf(jResp,"apps[i].buildSpec");
createTime = CkJsonObject_IntOf(jResp,"apps[i].createTime");
customHeaders = CkJsonObject_stringOf(jResp,"apps[i].customHeaders");
defaultDomain = CkJsonObject_stringOf(jResp,"apps[i].defaultDomain");
description = CkJsonObject_stringOf(jResp,"apps[i].description");
enableAutoBranchCreation = CkJsonObject_IntOf(jResp,"apps[i].enableAutoBranchCreation");
enableBasicAuth = CkJsonObject_IntOf(jResp,"apps[i].enableBasicAuth");
enableBranchAutoBuild = CkJsonObject_IntOf(jResp,"apps[i].enableBranchAutoBuild");
enableBranchAutoDeletion = CkJsonObject_IntOf(jResp,"apps[i].enableBranchAutoDeletion");
environmentVariablesString = CkJsonObject_stringOf(jResp,"apps[i].environmentVariables.string");
iamServiceRoleArn = CkJsonObject_stringOf(jResp,"apps[i].iamServiceRoleArn");
name = CkJsonObject_stringOf(jResp,"apps[i].name");
platform = CkJsonObject_stringOf(jResp,"apps[i].platform");
BranchName = CkJsonObject_stringOf(jResp,"apps[i].productionBranch.branchName");
LastDeployTime = CkJsonObject_IntOf(jResp,"apps[i].productionBranch.lastDeployTime");
Status = CkJsonObject_stringOf(jResp,"apps[i].productionBranch.status");
ThumbnailUrl = CkJsonObject_stringOf(jResp,"apps[i].productionBranch.thumbnailUrl");
repository = CkJsonObject_stringOf(jResp,"apps[i].repository");
repositoryCloneMethod = CkJsonObject_stringOf(jResp,"apps[i].repositoryCloneMethod");
tagsString = CkJsonObject_stringOf(jResp,"apps[i].tags.string");
updateTime = CkJsonObject_IntOf(jResp,"apps[i].updateTime");
j = 0;
count_j = CkJsonObject_SizeOfArray(jResp,"apps[i].autoBranchCreationPatterns");
while (j < count_j) {
CkJsonObject_putJ(jResp,j);
strVal = CkJsonObject_stringOf(jResp,"apps[i].autoBranchCreationPatterns[j]");
j = j + 1;
}
j = 0;
count_j = CkJsonObject_SizeOfArray(jResp,"apps[i].customRules");
while (j < count_j) {
CkJsonObject_putJ(jResp,j);
condition = CkJsonObject_stringOf(jResp,"apps[i].customRules[j].condition");
source = CkJsonObject_stringOf(jResp,"apps[i].customRules[j].source");
status = CkJsonObject_stringOf(jResp,"apps[i].customRules[j].status");
target = CkJsonObject_stringOf(jResp,"apps[i].customRules[j].target");
j = j + 1;
}
i = i + 1;
}
// A sample JSON response body parsed by the above code:
// {
// "apps": [
// {
// "appArn": "string",
// "appId": "string",
// "autoBranchCreationConfig": {
// "basicAuthCredentials": "string",
// "buildSpec": "string",
// "enableAutoBuild": boolean,
// "enableBasicAuth": boolean,
// "enablePerformanceMode": boolean,
// "enablePullRequestPreview": boolean,
// "environmentVariables": {
// "string": "string"
// },
// "framework": "string",
// "pullRequestEnvironmentName": "string",
// "stage": "string"
// },
// "autoBranchCreationPatterns": [
// "string"
// ],
// "basicAuthCredentials": "string",
// "buildSpec": "string",
// "createTime": number,
// "customHeaders": "string",
// "customRules": [
// {
// "condition": "string",
// "source": "string",
// "status": "string",
// "target": "string"
// }
// ],
// "defaultDomain": "string",
// "description": "string",
// "enableAutoBranchCreation": boolean,
// "enableBasicAuth": boolean,
// "enableBranchAutoBuild": boolean,
// "enableBranchAutoDeletion": boolean,
// "environmentVariables": {
// "string": "string"
// },
// "iamServiceRoleArn": "string",
// "name": "string",
// "platform": "string",
// "productionBranch": {
// "branchName": "string",
// "lastDeployTime": number,
// "status": "string",
// "thumbnailUrl": "string"
// },
// "repository": "string",
// "repositoryCloneMethod": "string",
// "tags": {
// "string": "string"
// },
// "updateTime": number
// }
// ],
// "nextToken": "string"
// }
CkRest_Dispose(rest);
CkAuthAws_Dispose(authAws);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);
}