Chilkat Online Tools

ListBranches 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: @"ListBranches"];

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestNoBodySb: @"GET" uriPath: @"/apps/{appId}/branches" 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 *activeJobId = 0;
NSString *backendEnvironmentArn = 0;
NSString *basicAuthCredentials = 0;
NSString *branchArn = 0;
NSString *branchName = 0;
NSString *buildSpec = 0;
int createTime;
NSString *description = 0;
NSString *destinationBranch = 0;
NSString *displayName = 0;
int enableAutoBuild;
int enableBasicAuth;
int enableNotification;
int enablePerformanceMode;
int enablePullRequestPreview;
NSString *v_String = 0;
NSString *framework = 0;
NSString *pullRequestEnvironmentName = 0;
NSString *sourceBranch = 0;
NSString *stage = 0;
NSString *tagsString = 0;
NSString *thumbnailUrl = 0;
NSString *totalNumberOfJobs = 0;
NSString *ttl = 0;
int updateTime;
int j;
int count_j;
NSString *strVal = 0;

NSString *nextToken = [jResp StringOf: @"nextToken"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"branches"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    activeJobId = [jResp StringOf: @"branches[i].activeJobId"];
    backendEnvironmentArn = [jResp StringOf: @"branches[i].backendEnvironmentArn"];
    basicAuthCredentials = [jResp StringOf: @"branches[i].basicAuthCredentials"];
    branchArn = [jResp StringOf: @"branches[i].branchArn"];
    branchName = [jResp StringOf: @"branches[i].branchName"];
    buildSpec = [jResp StringOf: @"branches[i].buildSpec"];
    createTime = [[jResp IntOf: @"branches[i].createTime"] intValue];
    description = [jResp StringOf: @"branches[i].description"];
    destinationBranch = [jResp StringOf: @"branches[i].destinationBranch"];
    displayName = [jResp StringOf: @"branches[i].displayName"];
    enableAutoBuild = [[jResp IntOf: @"branches[i].enableAutoBuild"] intValue];
    enableBasicAuth = [[jResp IntOf: @"branches[i].enableBasicAuth"] intValue];
    enableNotification = [[jResp IntOf: @"branches[i].enableNotification"] intValue];
    enablePerformanceMode = [[jResp IntOf: @"branches[i].enablePerformanceMode"] intValue];
    enablePullRequestPreview = [[jResp IntOf: @"branches[i].enablePullRequestPreview"] intValue];
    v_String = [jResp StringOf: @"branches[i].environmentVariables.string"];
    framework = [jResp StringOf: @"branches[i].framework"];
    pullRequestEnvironmentName = [jResp StringOf: @"branches[i].pullRequestEnvironmentName"];
    sourceBranch = [jResp StringOf: @"branches[i].sourceBranch"];
    stage = [jResp StringOf: @"branches[i].stage"];
    tagsString = [jResp StringOf: @"branches[i].tags.string"];
    thumbnailUrl = [jResp StringOf: @"branches[i].thumbnailUrl"];
    totalNumberOfJobs = [jResp StringOf: @"branches[i].totalNumberOfJobs"];
    ttl = [jResp StringOf: @"branches[i].ttl"];
    updateTime = [[jResp IntOf: @"branches[i].updateTime"] intValue];
    j = 0;
    count_j = [[jResp SizeOfArray: @"branches[i].associatedResources"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        strVal = [jResp StringOf: @"branches[i].associatedResources[j]"];
        j = j + 1;
    }

    j = 0;
    count_j = [[jResp SizeOfArray: @"branches[i].customDomains"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        strVal = [jResp StringOf: @"branches[i].customDomains[j]"];
        j = j + 1;
    }

    i = i + 1;
}

// A sample JSON response body parsed by the above code:

// {
//   "branches": [
//     {
//       "activeJobId": "string",
//       "associatedResources": [
//         "string"
//       ],
//       "backendEnvironmentArn": "string",
//       "basicAuthCredentials": "string",
//       "branchArn": "string",
//       "branchName": "string",
//       "buildSpec": "string",
//       "createTime": number,
//       "customDomains": [
//         "string"
//       ],
//       "description": "string",
//       "destinationBranch": "string",
//       "displayName": "string",
//       "enableAutoBuild": boolean,
//       "enableBasicAuth": boolean,
//       "enableNotification": boolean,
//       "enablePerformanceMode": boolean,
//       "enablePullRequestPreview": boolean,
//       "environmentVariables": {
//         "string": "string"
//       },
//       "framework": "string",
//       "pullRequestEnvironmentName": "string",
//       "sourceBranch": "string",
//       "stage": "string",
//       "tags": {
//         "string": "string"
//       },
//       "thumbnailUrl": "string",
//       "totalNumberOfJobs": "string",
//       "ttl": "string",
//       "updateTime": number
//     }
//   ],
//   "nextToken": "string"
// }