Chilkat Online Tools

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

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestNoBodySb: @"GET" uriPath: @"/apps/{appId}/branches/{branchName}" 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 *strVal = 0;

NSString *ActiveJobId = [jResp StringOf: @"branch.activeJobId"];
NSString *BackendEnvironmentArn = [jResp StringOf: @"branch.backendEnvironmentArn"];
NSString *BasicAuthCredentials = [jResp StringOf: @"branch.basicAuthCredentials"];
NSString *BranchArn = [jResp StringOf: @"branch.branchArn"];
NSString *BranchName = [jResp StringOf: @"branch.branchName"];
NSString *BuildSpec = [jResp StringOf: @"branch.buildSpec"];
int CreateTime = [[jResp IntOf: @"branch.createTime"] intValue];
NSString *Description = [jResp StringOf: @"branch.description"];
NSString *DestinationBranch = [jResp StringOf: @"branch.destinationBranch"];
NSString *DisplayName = [jResp StringOf: @"branch.displayName"];
int EnableAutoBuild = [[jResp IntOf: @"branch.enableAutoBuild"] intValue];
int EnableBasicAuth = [[jResp IntOf: @"branch.enableBasicAuth"] intValue];
int EnableNotification = [[jResp IntOf: @"branch.enableNotification"] intValue];
int EnablePerformanceMode = [[jResp IntOf: @"branch.enablePerformanceMode"] intValue];
int EnablePullRequestPreview = [[jResp IntOf: @"branch.enablePullRequestPreview"] intValue];
NSString *v_String = [jResp StringOf: @"branch.environmentVariables.string"];
NSString *Framework = [jResp StringOf: @"branch.framework"];
NSString *PullRequestEnvironmentName = [jResp StringOf: @"branch.pullRequestEnvironmentName"];
NSString *SourceBranch = [jResp StringOf: @"branch.sourceBranch"];
NSString *Stage = [jResp StringOf: @"branch.stage"];
NSString *TagsString = [jResp StringOf: @"branch.tags.string"];
NSString *ThumbnailUrl = [jResp StringOf: @"branch.thumbnailUrl"];
NSString *TotalNumberOfJobs = [jResp StringOf: @"branch.totalNumberOfJobs"];
NSString *Ttl = [jResp StringOf: @"branch.ttl"];
int UpdateTime = [[jResp IntOf: @"branch.updateTime"] intValue];
int i = 0;
int count_i = [[jResp SizeOfArray: @"branch.associatedResources"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    strVal = [jResp StringOf: @"branch.associatedResources[i]"];
    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"branch.customDomains"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    strVal = [jResp StringOf: @"branch.customDomains[i]"];
    i = i + 1;
}

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

// {
//   "branch": {
//     "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
//   }
// }