Chilkat Online Tools

ListApps Objective-C Example

Amplify

#import <CkoRest.h>
#import <CkoAuthAws.h>
#import <CkoStringBuilder.h>
#import <CkoJsonObject.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;
}

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

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestNoBodySb: @"GET" uriPath: @"/apps" sb: 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 *appArn = 0;
NSString *appId = 0;
NSString *BasicAuthCredentials = 0;
NSString *BuildSpec = 0;
int EnableAutoBuild;
int EnableBasicAuth;
int EnablePerformanceMode;
int EnablePullRequestPreview;
NSString *v_String = 0;
NSString *Framework = 0;
NSString *PullRequestEnvironmentName = 0;
NSString *Stage = 0;
NSString *basicAuthCredentials = 0;
NSString *buildSpec = 0;
int createTime;
NSString *customHeaders = 0;
NSString *defaultDomain = 0;
NSString *description = 0;
int enableAutoBranchCreation;
int enableBasicAuth;
int enableBranchAutoBuild;
int enableBranchAutoDeletion;
NSString *environmentVariablesString = 0;
NSString *iamServiceRoleArn = 0;
NSString *name = 0;
NSString *platform = 0;
NSString *BranchName = 0;
int LastDeployTime;
NSString *Status = 0;
NSString *ThumbnailUrl = 0;
NSString *repository = 0;
NSString *repositoryCloneMethod = 0;
NSString *tagsString = 0;
int updateTime;
int j;
int count_j;
NSString *strVal = 0;
NSString *condition = 0;
NSString *source = 0;
NSString *status = 0;
NSString *target = 0;

NSString *nextToken = [jResp StringOf: @"nextToken"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"apps"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    appArn = [jResp StringOf: @"apps[i].appArn"];
    appId = [jResp StringOf: @"apps[i].appId"];
    BasicAuthCredentials = [jResp StringOf: @"apps[i].autoBranchCreationConfig.basicAuthCredentials"];
    BuildSpec = [jResp StringOf: @"apps[i].autoBranchCreationConfig.buildSpec"];
    EnableAutoBuild = [[jResp IntOf: @"apps[i].autoBranchCreationConfig.enableAutoBuild"] intValue];
    EnableBasicAuth = [[jResp IntOf: @"apps[i].autoBranchCreationConfig.enableBasicAuth"] intValue];
    EnablePerformanceMode = [[jResp IntOf: @"apps[i].autoBranchCreationConfig.enablePerformanceMode"] intValue];
    EnablePullRequestPreview = [[jResp IntOf: @"apps[i].autoBranchCreationConfig.enablePullRequestPreview"] intValue];
    v_String = [jResp StringOf: @"apps[i].autoBranchCreationConfig.environmentVariables.string"];
    Framework = [jResp StringOf: @"apps[i].autoBranchCreationConfig.framework"];
    PullRequestEnvironmentName = [jResp StringOf: @"apps[i].autoBranchCreationConfig.pullRequestEnvironmentName"];
    Stage = [jResp StringOf: @"apps[i].autoBranchCreationConfig.stage"];
    basicAuthCredentials = [jResp StringOf: @"apps[i].basicAuthCredentials"];
    buildSpec = [jResp StringOf: @"apps[i].buildSpec"];
    createTime = [[jResp IntOf: @"apps[i].createTime"] intValue];
    customHeaders = [jResp StringOf: @"apps[i].customHeaders"];
    defaultDomain = [jResp StringOf: @"apps[i].defaultDomain"];
    description = [jResp StringOf: @"apps[i].description"];
    enableAutoBranchCreation = [[jResp IntOf: @"apps[i].enableAutoBranchCreation"] intValue];
    enableBasicAuth = [[jResp IntOf: @"apps[i].enableBasicAuth"] intValue];
    enableBranchAutoBuild = [[jResp IntOf: @"apps[i].enableBranchAutoBuild"] intValue];
    enableBranchAutoDeletion = [[jResp IntOf: @"apps[i].enableBranchAutoDeletion"] intValue];
    environmentVariablesString = [jResp StringOf: @"apps[i].environmentVariables.string"];
    iamServiceRoleArn = [jResp StringOf: @"apps[i].iamServiceRoleArn"];
    name = [jResp StringOf: @"apps[i].name"];
    platform = [jResp StringOf: @"apps[i].platform"];
    BranchName = [jResp StringOf: @"apps[i].productionBranch.branchName"];
    LastDeployTime = [[jResp IntOf: @"apps[i].productionBranch.lastDeployTime"] intValue];
    Status = [jResp StringOf: @"apps[i].productionBranch.status"];
    ThumbnailUrl = [jResp StringOf: @"apps[i].productionBranch.thumbnailUrl"];
    repository = [jResp StringOf: @"apps[i].repository"];
    repositoryCloneMethod = [jResp StringOf: @"apps[i].repositoryCloneMethod"];
    tagsString = [jResp StringOf: @"apps[i].tags.string"];
    updateTime = [[jResp IntOf: @"apps[i].updateTime"] intValue];
    j = 0;
    count_j = [[jResp SizeOfArray: @"apps[i].autoBranchCreationPatterns"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        strVal = [jResp StringOf: @"apps[i].autoBranchCreationPatterns[j]"];
        j = j + 1;
    }

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