Chilkat Online Tools

UpdateApp delphiDll Example

Amplify

var
rest: HCkRest;
success: Boolean;
authAws: HCkAuthAws;
json: HCkJsonObject;
sbRequestBody: HCkStringBuilder;
sbResponseBody: HCkStringBuilder;
respStatusCode: Integer;
jResp: HCkJsonObject;
strVal: PWideChar;
condition: PWideChar;
source: PWideChar;
status: PWideChar;
target: PWideChar;
AppArn: PWideChar;
AppId: PWideChar;
BasicAuthCredentials: PWideChar;
BuildSpec: PWideChar;
EnableAutoBuild: Integer;
EnableBasicAuth: Integer;
EnablePerformanceMode: Integer;
EnablePullRequestPreview: Integer;
v_String: PWideChar;
Framework: PWideChar;
PullRequestEnvironmentName: PWideChar;
Stage: PWideChar;
appBasicAuthCredentials: PWideChar;
appBuildSpec: PWideChar;
CreateTime: Integer;
CustomHeaders: PWideChar;
DefaultDomain: PWideChar;
Description: PWideChar;
EnableAutoBranchCreation: Integer;
appEnableBasicAuth: Integer;
EnableBranchAutoBuild: Integer;
EnableBranchAutoDeletion: Integer;
EnvironmentVariablesString: PWideChar;
IamServiceRoleArn: PWideChar;
Name: PWideChar;
Platform: PWideChar;
BranchName: PWideChar;
LastDeployTime: Integer;
Status: PWideChar;
ThumbnailUrl: PWideChar;
Repository: PWideChar;
RepositoryCloneMethod: PWideChar;
TagsString: PWideChar;
UpdateTime: Integer;
i: Integer;
count_i: Integer;

begin
// 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) then
  begin
    Memo1.Lines.Add('ConnectFailReason: ' + IntToStr(CkRest_getConnectFailReason(rest)));
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;

// 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 := CkJsonObject_Create();
CkJsonObject_UpdateString(json,'accessToken','string');
CkJsonObject_UpdateString(json,'autoBranchCreationConfig.basicAuthCredentials','string');
CkJsonObject_UpdateString(json,'autoBranchCreationConfig.buildSpec','string');
CkJsonObject_UpdateInt(json,'autoBranchCreationConfig.enableAutoBuild',123);
CkJsonObject_UpdateInt(json,'autoBranchCreationConfig.enableBasicAuth',123);
CkJsonObject_UpdateInt(json,'autoBranchCreationConfig.enablePerformanceMode',123);
CkJsonObject_UpdateInt(json,'autoBranchCreationConfig.enablePullRequestPreview',123);
CkJsonObject_UpdateString(json,'autoBranchCreationConfig.environmentVariables.string','string');
CkJsonObject_UpdateString(json,'autoBranchCreationConfig.framework','string');
CkJsonObject_UpdateString(json,'autoBranchCreationConfig.pullRequestEnvironmentName','string');
CkJsonObject_UpdateString(json,'autoBranchCreationConfig.stage','string');
CkJsonObject_UpdateString(json,'autoBranchCreationPatterns[0]','string');
CkJsonObject_UpdateString(json,'basicAuthCredentials','string');
CkJsonObject_UpdateString(json,'buildSpec','string');
CkJsonObject_UpdateString(json,'customHeaders','string');
CkJsonObject_UpdateString(json,'customRules[0].condition','string');
CkJsonObject_UpdateString(json,'customRules[0].source','string');
CkJsonObject_UpdateString(json,'customRules[0].status','string');
CkJsonObject_UpdateString(json,'customRules[0].target','string');
CkJsonObject_UpdateString(json,'description','string');
CkJsonObject_UpdateInt(json,'enableAutoBranchCreation',123);
CkJsonObject_UpdateInt(json,'enableBasicAuth',123);
CkJsonObject_UpdateInt(json,'enableBranchAutoBuild',123);
CkJsonObject_UpdateInt(json,'enableBranchAutoDeletion',123);
CkJsonObject_UpdateString(json,'environmentVariables.string','string');
CkJsonObject_UpdateString(json,'iamServiceRoleArn','string');
CkJsonObject_UpdateString(json,'name','string');
CkJsonObject_UpdateString(json,'oauthToken','string');
CkJsonObject_UpdateString(json,'platform','string');
CkJsonObject_UpdateString(json,'repository','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"
// }

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

sbRequestBody := CkStringBuilder_Create();
CkJsonObject_EmitSb(json,sbRequestBody);
sbResponseBody := CkStringBuilder_Create();
success := CkRest_FullRequestSb(rest,'POST','/apps/{appId}',sbRequestBody,sbResponseBody);
if (success <> True) then
  begin
    Memo1.Lines.Add(CkRest__lastErrorText(rest));
    Exit;
  end;
respStatusCode := CkRest_getResponseStatusCode(rest);
Memo1.Lines.Add('response status code = ' + IntToStr(respStatusCode));
if (respStatusCode <> 200) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkRest__responseHeader(rest));
    Memo1.Lines.Add('Response Body:');
    Memo1.Lines.Add(CkStringBuilder__getAsString(sbResponseBody));
    Exit;
  end;

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

AppArn := CkJsonObject__stringOf(jResp,'app.appArn');
AppId := CkJsonObject__stringOf(jResp,'app.appId');
BasicAuthCredentials := CkJsonObject__stringOf(jResp,'app.autoBranchCreationConfig.basicAuthCredentials');
BuildSpec := CkJsonObject__stringOf(jResp,'app.autoBranchCreationConfig.buildSpec');
EnableAutoBuild := CkJsonObject_IntOf(jResp,'app.autoBranchCreationConfig.enableAutoBuild');
EnableBasicAuth := CkJsonObject_IntOf(jResp,'app.autoBranchCreationConfig.enableBasicAuth');
EnablePerformanceMode := CkJsonObject_IntOf(jResp,'app.autoBranchCreationConfig.enablePerformanceMode');
EnablePullRequestPreview := CkJsonObject_IntOf(jResp,'app.autoBranchCreationConfig.enablePullRequestPreview');
v_String := CkJsonObject__stringOf(jResp,'app.autoBranchCreationConfig.environmentVariables.string');
Framework := CkJsonObject__stringOf(jResp,'app.autoBranchCreationConfig.framework');
PullRequestEnvironmentName := CkJsonObject__stringOf(jResp,'app.autoBranchCreationConfig.pullRequestEnvironmentName');
Stage := CkJsonObject__stringOf(jResp,'app.autoBranchCreationConfig.stage');
appBasicAuthCredentials := CkJsonObject__stringOf(jResp,'app.basicAuthCredentials');
appBuildSpec := CkJsonObject__stringOf(jResp,'app.buildSpec');
CreateTime := CkJsonObject_IntOf(jResp,'app.createTime');
CustomHeaders := CkJsonObject__stringOf(jResp,'app.customHeaders');
DefaultDomain := CkJsonObject__stringOf(jResp,'app.defaultDomain');
Description := CkJsonObject__stringOf(jResp,'app.description');
EnableAutoBranchCreation := CkJsonObject_IntOf(jResp,'app.enableAutoBranchCreation');
appEnableBasicAuth := CkJsonObject_IntOf(jResp,'app.enableBasicAuth');
EnableBranchAutoBuild := CkJsonObject_IntOf(jResp,'app.enableBranchAutoBuild');
EnableBranchAutoDeletion := CkJsonObject_IntOf(jResp,'app.enableBranchAutoDeletion');
EnvironmentVariablesString := CkJsonObject__stringOf(jResp,'app.environmentVariables.string');
IamServiceRoleArn := CkJsonObject__stringOf(jResp,'app.iamServiceRoleArn');
Name := CkJsonObject__stringOf(jResp,'app.name');
Platform := CkJsonObject__stringOf(jResp,'app.platform');
BranchName := CkJsonObject__stringOf(jResp,'app.productionBranch.branchName');
LastDeployTime := CkJsonObject_IntOf(jResp,'app.productionBranch.lastDeployTime');
Status := CkJsonObject__stringOf(jResp,'app.productionBranch.status');
ThumbnailUrl := CkJsonObject__stringOf(jResp,'app.productionBranch.thumbnailUrl');
Repository := CkJsonObject__stringOf(jResp,'app.repository');
RepositoryCloneMethod := CkJsonObject__stringOf(jResp,'app.repositoryCloneMethod');
TagsString := CkJsonObject__stringOf(jResp,'app.tags.string');
UpdateTime := CkJsonObject_IntOf(jResp,'app.updateTime');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'app.autoBranchCreationPatterns');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'app.autoBranchCreationPatterns[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'app.customRules');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    condition := CkJsonObject__stringOf(jResp,'app.customRules[i].condition');
    source := CkJsonObject__stringOf(jResp,'app.customRules[i].source');
    status := CkJsonObject__stringOf(jResp,'app.customRules[i].status');
    target := CkJsonObject__stringOf(jResp,'app.customRules[i].target');
    i := i + 1;
  end;

// 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
//   }
// }

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