Chilkat Online Tools

CreateApp Objective-C Example

Amplify

#import <CkoRest.h>
#import <CkoAuthAws.h>
#import <CkoJsonObject.h>
#import <CkoStringBuilder.h>
#import <NSString.h>

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

CkoRest *rest = [[CkoRest alloc] init];
BOOL success;

CkoAuthAws *authAws = [[CkoAuthAws alloc] init];
authAws.AccessKey = @"AWS_ACCESS_KEY";
authAws.SecretKey = @"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.Region = @"us-west-2";
authAws.ServiceName = @"amplify";
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
[rest SetAuthAws: authAws];

// URL: https://amplify.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = [rest Connect: @"amplify.us-west-2.amazonaws.com" port: [NSNumber numberWithInt: 443] tls: YES autoReconnect: YES];
if (success != YES) {
    NSLog(@"%@%d",@"ConnectFailReason: ",[rest.ConnectFailReason intValue]);
    NSLog(@"%@",rest.LastErrorText);
    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

CkoJsonObject *json = [[CkoJsonObject alloc] init];
[json UpdateString: @"accessToken" value: @"string"];
[json UpdateString: @"autoBranchCreationConfig.basicAuthCredentials" value: @"string"];
[json UpdateString: @"autoBranchCreationConfig.buildSpec" value: @"string"];
[json UpdateInt: @"autoBranchCreationConfig.enableAutoBuild" value: [NSNumber numberWithInt: 123]];
[json UpdateInt: @"autoBranchCreationConfig.enableBasicAuth" value: [NSNumber numberWithInt: 123]];
[json UpdateInt: @"autoBranchCreationConfig.enablePerformanceMode" value: [NSNumber numberWithInt: 123]];
[json UpdateInt: @"autoBranchCreationConfig.enablePullRequestPreview" value: [NSNumber numberWithInt: 123]];
[json UpdateString: @"autoBranchCreationConfig.environmentVariables.string" value: @"string"];
[json UpdateString: @"autoBranchCreationConfig.framework" value: @"string"];
[json UpdateString: @"autoBranchCreationConfig.pullRequestEnvironmentName" value: @"string"];
[json UpdateString: @"autoBranchCreationConfig.stage" value: @"string"];
[json UpdateString: @"autoBranchCreationPatterns[0]" value: @"string"];
[json UpdateString: @"basicAuthCredentials" value: @"string"];
[json UpdateString: @"buildSpec" value: @"string"];
[json UpdateString: @"customHeaders" value: @"string"];
[json UpdateString: @"customRules[0].condition" value: @"string"];
[json UpdateString: @"customRules[0].source" value: @"string"];
[json UpdateString: @"customRules[0].status" value: @"string"];
[json UpdateString: @"customRules[0].target" value: @"string"];
[json UpdateString: @"description" value: @"string"];
[json UpdateInt: @"enableAutoBranchCreation" value: [NSNumber numberWithInt: 123]];
[json UpdateInt: @"enableBasicAuth" value: [NSNumber numberWithInt: 123]];
[json UpdateInt: @"enableBranchAutoBuild" value: [NSNumber numberWithInt: 123]];
[json UpdateInt: @"enableBranchAutoDeletion" value: [NSNumber numberWithInt: 123]];
[json UpdateString: @"environmentVariables.string" value: @"string"];
[json UpdateString: @"iamServiceRoleArn" value: @"string"];
[json UpdateString: @"name" value: @"string"];
[json UpdateString: @"oauthToken" value: @"string"];
[json UpdateString: @"platform" value: @"string"];
[json UpdateString: @"repository" value: @"string"];
[json UpdateString: @"tags.string" value: @"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",
//   "tags": {
//     "string": "string"
//   }
// }

[rest AddHeader: @"Content-Type" value: @"application/x-amz-json-1.1"];
[rest AddHeader: @"X-Amz-Target" value: @"CreateApp"];

CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[json EmitSb: sbRequestBody];
CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestSb: @"POST" uriPath: @"/apps" requestBody: sbRequestBody responseBody: sbResponseBody];
if (success != YES) {
    NSLog(@"%@",rest.LastErrorText);
    return;
}

int respStatusCode = [rest.ResponseStatusCode intValue];
NSLog(@"%@%d",@"response status code = ",respStatusCode);
if (respStatusCode != 200) {
    NSLog(@"%@",@"Response Header:");
    NSLog(@"%@",rest.ResponseHeader);
    NSLog(@"%@",@"Response Body:");
    NSLog(@"%@",[sbResponseBody GetAsString]);
    return;
}

CkoJsonObject *jResp = [[CkoJsonObject alloc] init];
[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

NSString *strVal = 0;
NSString *condition = 0;
NSString *source = 0;
NSString *status = 0;
NSString *target = 0;

NSString *AppArn = [jResp StringOf: @"app.appArn"];
NSString *AppId = [jResp StringOf: @"app.appId"];
NSString *BasicAuthCredentials = [jResp StringOf: @"app.autoBranchCreationConfig.basicAuthCredentials"];
NSString *BuildSpec = [jResp StringOf: @"app.autoBranchCreationConfig.buildSpec"];
int EnableAutoBuild = [[jResp IntOf: @"app.autoBranchCreationConfig.enableAutoBuild"] intValue];
int EnableBasicAuth = [[jResp IntOf: @"app.autoBranchCreationConfig.enableBasicAuth"] intValue];
int EnablePerformanceMode = [[jResp IntOf: @"app.autoBranchCreationConfig.enablePerformanceMode"] intValue];
int EnablePullRequestPreview = [[jResp IntOf: @"app.autoBranchCreationConfig.enablePullRequestPreview"] intValue];
NSString *v_String = [jResp StringOf: @"app.autoBranchCreationConfig.environmentVariables.string"];
NSString *Framework = [jResp StringOf: @"app.autoBranchCreationConfig.framework"];
NSString *PullRequestEnvironmentName = [jResp StringOf: @"app.autoBranchCreationConfig.pullRequestEnvironmentName"];
NSString *Stage = [jResp StringOf: @"app.autoBranchCreationConfig.stage"];
NSString *appBasicAuthCredentials = [jResp StringOf: @"app.basicAuthCredentials"];
NSString *appBuildSpec = [jResp StringOf: @"app.buildSpec"];
int CreateTime = [[jResp IntOf: @"app.createTime"] intValue];
NSString *CustomHeaders = [jResp StringOf: @"app.customHeaders"];
NSString *DefaultDomain = [jResp StringOf: @"app.defaultDomain"];
NSString *Description = [jResp StringOf: @"app.description"];
int EnableAutoBranchCreation = [[jResp IntOf: @"app.enableAutoBranchCreation"] intValue];
int appEnableBasicAuth = [[jResp IntOf: @"app.enableBasicAuth"] intValue];
int EnableBranchAutoBuild = [[jResp IntOf: @"app.enableBranchAutoBuild"] intValue];
int EnableBranchAutoDeletion = [[jResp IntOf: @"app.enableBranchAutoDeletion"] intValue];
NSString *EnvironmentVariablesString = [jResp StringOf: @"app.environmentVariables.string"];
NSString *IamServiceRoleArn = [jResp StringOf: @"app.iamServiceRoleArn"];
NSString *Name = [jResp StringOf: @"app.name"];
NSString *Platform = [jResp StringOf: @"app.platform"];
NSString *BranchName = [jResp StringOf: @"app.productionBranch.branchName"];
int LastDeployTime = [[jResp IntOf: @"app.productionBranch.lastDeployTime"] intValue];
NSString *Status = [jResp StringOf: @"app.productionBranch.status"];
NSString *ThumbnailUrl = [jResp StringOf: @"app.productionBranch.thumbnailUrl"];
NSString *Repository = [jResp StringOf: @"app.repository"];
NSString *RepositoryCloneMethod = [jResp StringOf: @"app.repositoryCloneMethod"];
NSString *TagsString = [jResp StringOf: @"app.tags.string"];
int UpdateTime = [[jResp IntOf: @"app.updateTime"] intValue];
int i = 0;
int count_i = [[jResp SizeOfArray: @"app.autoBranchCreationPatterns"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    strVal = [jResp StringOf: @"app.autoBranchCreationPatterns[i]"];
    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"app.customRules"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    condition = [jResp StringOf: @"app.customRules[i].condition"];
    source = [jResp StringOf: @"app.customRules[i].source"];
    status = [jResp StringOf: @"app.customRules[i].status"];
    target = [jResp StringOf: @"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
//   }
// }