UpdateApp unicodeC Example
#include <C_CkRestW.h>
#include <C_CkAuthAwsW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
HCkRestW rest;
BOOL success;
HCkAuthAwsW authAws;
HCkJsonObjectW json;
HCkStringBuilderW sbRequestBody;
HCkStringBuilderW sbResponseBody;
int respStatusCode;
HCkJsonObjectW jResp;
const wchar_t *strVal;
const wchar_t *condition;
const wchar_t *source;
const wchar_t *status;
const wchar_t *target;
const wchar_t *AppArn;
const wchar_t *AppId;
const wchar_t *BasicAuthCredentials;
const wchar_t *BuildSpec;
int EnableAutoBuild;
int EnableBasicAuth;
int EnablePerformanceMode;
int EnablePullRequestPreview;
const wchar_t *v_String;
const wchar_t *Framework;
const wchar_t *PullRequestEnvironmentName;
const wchar_t *Stage;
const wchar_t *appBasicAuthCredentials;
const wchar_t *appBuildSpec;
int CreateTime;
const wchar_t *CustomHeaders;
const wchar_t *DefaultDomain;
const wchar_t *Description;
int EnableAutoBranchCreation;
int appEnableBasicAuth;
int EnableBranchAutoBuild;
int EnableBranchAutoDeletion;
const wchar_t *EnvironmentVariablesString;
const wchar_t *IamServiceRoleArn;
const wchar_t *Name;
const wchar_t *Platform;
const wchar_t *BranchName;
int LastDeployTime;
const wchar_t *Status;
const wchar_t *ThumbnailUrl;
const wchar_t *Repository;
const wchar_t *RepositoryCloneMethod;
const wchar_t *TagsString;
int UpdateTime;
int i;
int count_i;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
rest = CkRestW_Create();
authAws = CkAuthAwsW_Create();
CkAuthAwsW_putAccessKey(authAws,L"AWS_ACCESS_KEY");
CkAuthAwsW_putSecretKey(authAws,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.)
CkAuthAwsW_putRegion(authAws,L"us-west-2");
CkAuthAwsW_putServiceName(authAws,L"amplify");
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRestW_SetAuthAws(rest,authAws);
// URL: https://amplify.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = CkRestW_Connect(rest,L"amplify.us-west-2.amazonaws.com",443,TRUE,TRUE);
if (success != TRUE) {
wprintf(L"ConnectFailReason: %d\n",CkRestW_getConnectFailReason(rest));
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
CkAuthAwsW_Dispose(authAws);
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
json = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(json,L"accessToken",L"string");
CkJsonObjectW_UpdateString(json,L"autoBranchCreationConfig.basicAuthCredentials",L"string");
CkJsonObjectW_UpdateString(json,L"autoBranchCreationConfig.buildSpec",L"string");
CkJsonObjectW_UpdateInt(json,L"autoBranchCreationConfig.enableAutoBuild",123);
CkJsonObjectW_UpdateInt(json,L"autoBranchCreationConfig.enableBasicAuth",123);
CkJsonObjectW_UpdateInt(json,L"autoBranchCreationConfig.enablePerformanceMode",123);
CkJsonObjectW_UpdateInt(json,L"autoBranchCreationConfig.enablePullRequestPreview",123);
CkJsonObjectW_UpdateString(json,L"autoBranchCreationConfig.environmentVariables.string",L"string");
CkJsonObjectW_UpdateString(json,L"autoBranchCreationConfig.framework",L"string");
CkJsonObjectW_UpdateString(json,L"autoBranchCreationConfig.pullRequestEnvironmentName",L"string");
CkJsonObjectW_UpdateString(json,L"autoBranchCreationConfig.stage",L"string");
CkJsonObjectW_UpdateString(json,L"autoBranchCreationPatterns[0]",L"string");
CkJsonObjectW_UpdateString(json,L"basicAuthCredentials",L"string");
CkJsonObjectW_UpdateString(json,L"buildSpec",L"string");
CkJsonObjectW_UpdateString(json,L"customHeaders",L"string");
CkJsonObjectW_UpdateString(json,L"customRules[0].condition",L"string");
CkJsonObjectW_UpdateString(json,L"customRules[0].source",L"string");
CkJsonObjectW_UpdateString(json,L"customRules[0].status",L"string");
CkJsonObjectW_UpdateString(json,L"customRules[0].target",L"string");
CkJsonObjectW_UpdateString(json,L"description",L"string");
CkJsonObjectW_UpdateInt(json,L"enableAutoBranchCreation",123);
CkJsonObjectW_UpdateInt(json,L"enableBasicAuth",123);
CkJsonObjectW_UpdateInt(json,L"enableBranchAutoBuild",123);
CkJsonObjectW_UpdateInt(json,L"enableBranchAutoDeletion",123);
CkJsonObjectW_UpdateString(json,L"environmentVariables.string",L"string");
CkJsonObjectW_UpdateString(json,L"iamServiceRoleArn",L"string");
CkJsonObjectW_UpdateString(json,L"name",L"string");
CkJsonObjectW_UpdateString(json,L"oauthToken",L"string");
CkJsonObjectW_UpdateString(json,L"platform",L"string");
CkJsonObjectW_UpdateString(json,L"repository",L"string");
// The JSON request body created by the above code:
// {
// "accessToken": "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",
// "customHeaders": "string",
// "customRules": [
// {
// "condition": "string",
// "source": "string",
// "status": "string",
// "target": "string"
// }
// ],
// "description": "string",
// "enableAutoBranchCreation": boolean,
// "enableBasicAuth": boolean,
// "enableBranchAutoBuild": boolean,
// "enableBranchAutoDeletion": boolean,
// "environmentVariables": {
// "string": "string"
// },
// "iamServiceRoleArn": "string",
// "name": "string",
// "oauthToken": "string",
// "platform": "string",
// "repository": "string"
// }
CkRestW_AddHeader(rest,L"Content-Type",L"application/x-amz-json-1.1");
CkRestW_AddHeader(rest,L"X-Amz-Target",L"UpdateApp");
sbRequestBody = CkStringBuilderW_Create();
CkJsonObjectW_EmitSb(json,sbRequestBody);
sbResponseBody = CkStringBuilderW_Create();
success = CkRestW_FullRequestSb(rest,L"POST",L"/apps/{appId}",sbRequestBody,sbResponseBody);
if (success != TRUE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
CkAuthAwsW_Dispose(authAws);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
CkStringBuilderW_Dispose(sbResponseBody);
return;
}
respStatusCode = CkRestW_getResponseStatusCode(rest);
wprintf(L"response status code = %d\n",respStatusCode);
if (respStatusCode != 200) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",CkRestW_responseHeader(rest));
wprintf(L"Response Body:\n");
wprintf(L"%s\n",CkStringBuilderW_getAsString(sbResponseBody));
CkRestW_Dispose(rest);
CkAuthAwsW_Dispose(authAws);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
CkStringBuilderW_Dispose(sbResponseBody);
return;
}
jResp = CkJsonObjectW_Create();
CkJsonObjectW_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.
AppArn = CkJsonObjectW_stringOf(jResp,L"app.appArn");
AppId = CkJsonObjectW_stringOf(jResp,L"app.appId");
BasicAuthCredentials = CkJsonObjectW_stringOf(jResp,L"app.autoBranchCreationConfig.basicAuthCredentials");
BuildSpec = CkJsonObjectW_stringOf(jResp,L"app.autoBranchCreationConfig.buildSpec");
EnableAutoBuild = CkJsonObjectW_IntOf(jResp,L"app.autoBranchCreationConfig.enableAutoBuild");
EnableBasicAuth = CkJsonObjectW_IntOf(jResp,L"app.autoBranchCreationConfig.enableBasicAuth");
EnablePerformanceMode = CkJsonObjectW_IntOf(jResp,L"app.autoBranchCreationConfig.enablePerformanceMode");
EnablePullRequestPreview = CkJsonObjectW_IntOf(jResp,L"app.autoBranchCreationConfig.enablePullRequestPreview");
v_String = CkJsonObjectW_stringOf(jResp,L"app.autoBranchCreationConfig.environmentVariables.string");
Framework = CkJsonObjectW_stringOf(jResp,L"app.autoBranchCreationConfig.framework");
PullRequestEnvironmentName = CkJsonObjectW_stringOf(jResp,L"app.autoBranchCreationConfig.pullRequestEnvironmentName");
Stage = CkJsonObjectW_stringOf(jResp,L"app.autoBranchCreationConfig.stage");
appBasicAuthCredentials = CkJsonObjectW_stringOf(jResp,L"app.basicAuthCredentials");
appBuildSpec = CkJsonObjectW_stringOf(jResp,L"app.buildSpec");
CreateTime = CkJsonObjectW_IntOf(jResp,L"app.createTime");
CustomHeaders = CkJsonObjectW_stringOf(jResp,L"app.customHeaders");
DefaultDomain = CkJsonObjectW_stringOf(jResp,L"app.defaultDomain");
Description = CkJsonObjectW_stringOf(jResp,L"app.description");
EnableAutoBranchCreation = CkJsonObjectW_IntOf(jResp,L"app.enableAutoBranchCreation");
appEnableBasicAuth = CkJsonObjectW_IntOf(jResp,L"app.enableBasicAuth");
EnableBranchAutoBuild = CkJsonObjectW_IntOf(jResp,L"app.enableBranchAutoBuild");
EnableBranchAutoDeletion = CkJsonObjectW_IntOf(jResp,L"app.enableBranchAutoDeletion");
EnvironmentVariablesString = CkJsonObjectW_stringOf(jResp,L"app.environmentVariables.string");
IamServiceRoleArn = CkJsonObjectW_stringOf(jResp,L"app.iamServiceRoleArn");
Name = CkJsonObjectW_stringOf(jResp,L"app.name");
Platform = CkJsonObjectW_stringOf(jResp,L"app.platform");
BranchName = CkJsonObjectW_stringOf(jResp,L"app.productionBranch.branchName");
LastDeployTime = CkJsonObjectW_IntOf(jResp,L"app.productionBranch.lastDeployTime");
Status = CkJsonObjectW_stringOf(jResp,L"app.productionBranch.status");
ThumbnailUrl = CkJsonObjectW_stringOf(jResp,L"app.productionBranch.thumbnailUrl");
Repository = CkJsonObjectW_stringOf(jResp,L"app.repository");
RepositoryCloneMethod = CkJsonObjectW_stringOf(jResp,L"app.repositoryCloneMethod");
TagsString = CkJsonObjectW_stringOf(jResp,L"app.tags.string");
UpdateTime = CkJsonObjectW_IntOf(jResp,L"app.updateTime");
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"app.autoBranchCreationPatterns");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
strVal = CkJsonObjectW_stringOf(jResp,L"app.autoBranchCreationPatterns[i]");
i = i + 1;
}
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"app.customRules");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
condition = CkJsonObjectW_stringOf(jResp,L"app.customRules[i].condition");
source = CkJsonObjectW_stringOf(jResp,L"app.customRules[i].source");
status = CkJsonObjectW_stringOf(jResp,L"app.customRules[i].status");
target = CkJsonObjectW_stringOf(jResp,L"app.customRules[i].target");
i = i + 1;
}
// A sample JSON response body parsed by the above code:
// {
// "app": {
// "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
// }
// }
CkRestW_Dispose(rest);
CkAuthAwsW_Dispose(authAws);
CkJsonObjectW_Dispose(json);
CkStringBuilderW_Dispose(sbRequestBody);
CkStringBuilderW_Dispose(sbResponseBody);
CkJsonObjectW_Dispose(jResp);
}