Chilkat Online Tools

RetryBuild Objective-C Example

AWS CodeBuild

#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 = @"codebuild";
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
[rest SetAuthAws: authAws];

// URL: https://codebuild.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = [rest Connect: @"codebuild.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: @"id" value: @"string"];
[json UpdateString: @"idempotencyToken" value: @"string"];

// The JSON request body created by the above code:

// {
//   "id": "string",
//   "idempotencyToken": "string"
// }

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

CkoStringBuilder *sbRequestBody = [[CkoStringBuilder alloc] init];
[json EmitSb: sbRequestBody];
CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestSb: @"POST" uriPath: @"/" 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 *name = 0;
NSString *v_type = 0;
NSString *value = 0;
NSString *identifier = 0;
NSString *location = 0;
NSString *mountOptions = 0;
NSString *mountPoint = 0;
int durationInSeconds;
int endTime;
NSString *phaseStatus = 0;
NSString *phaseType = 0;
int startTime;
int j;
int count_j;
NSString *message = 0;
NSString *statusCode = 0;
NSString *artifactIdentifier = 0;
NSString *bucketOwnerAccess = 0;
int encryptionDisabled;
NSString *md5sum = 0;
int overrideArtifactName;
NSString *sha256sum = 0;
NSString *authResource = 0;
NSString *authType = 0;
NSString *buildspec = 0;
NSString *buildStatusConfigContext = 0;
NSString *buildStatusConfigTargetUrl = 0;
int gitCloneDepth;
int gitSubmodulesConfigFetchSubmodules;
int insecureSsl;
int reportBuildStatus;
NSString *sourceIdentifier = 0;
NSString *sourceVersion = 0;

NSString *Arn = [jResp StringOf: @"build.arn"];
NSString *ArtifactIdentifier = [jResp StringOf: @"build.artifacts.artifactIdentifier"];
NSString *BucketOwnerAccess = [jResp StringOf: @"build.artifacts.bucketOwnerAccess"];
int EncryptionDisabled = [[jResp IntOf: @"build.artifacts.encryptionDisabled"] intValue];
NSString *Location = [jResp StringOf: @"build.artifacts.location"];
NSString *Md5sum = [jResp StringOf: @"build.artifacts.md5sum"];
int OverrideArtifactName = [[jResp IntOf: @"build.artifacts.overrideArtifactName"] intValue];
NSString *Sha256sum = [jResp StringOf: @"build.artifacts.sha256sum"];
NSString *BuildBatchArn = [jResp StringOf: @"build.buildBatchArn"];
int BuildComplete = [[jResp IntOf: @"build.buildComplete"] intValue];
int BuildNumber = [[jResp IntOf: @"build.buildNumber"] intValue];
NSString *BuildStatus = [jResp StringOf: @"build.buildStatus"];
NSString *CacheLocation = [jResp StringOf: @"build.cache.location"];
NSString *v_Type = [jResp StringOf: @"build.cache.type"];
NSString *CurrentPhase = [jResp StringOf: @"build.currentPhase"];
int SessionEnabled = [[jResp IntOf: @"build.debugSession.sessionEnabled"] intValue];
NSString *SessionTarget = [jResp StringOf: @"build.debugSession.sessionTarget"];
NSString *EncryptionKey = [jResp StringOf: @"build.encryptionKey"];
int EndTime = [[jResp IntOf: @"build.endTime"] intValue];
NSString *Certificate = [jResp StringOf: @"build.environment.certificate"];
NSString *ComputeType = [jResp StringOf: @"build.environment.computeType"];
NSString *Image = [jResp StringOf: @"build.environment.image"];
NSString *ImagePullCredentialsType = [jResp StringOf: @"build.environment.imagePullCredentialsType"];
int PrivilegedMode = [[jResp IntOf: @"build.environment.privilegedMode"] intValue];
NSString *Credential = [jResp StringOf: @"build.environment.registryCredential.credential"];
NSString *CredentialProvider = [jResp StringOf: @"build.environment.registryCredential.credentialProvider"];
NSString *EnvironmentType = [jResp StringOf: @"build.environment.type"];
NSString *Id = [jResp StringOf: @"build.id"];
NSString *Initiator = [jResp StringOf: @"build.initiator"];
NSString *GroupName = [jResp StringOf: @"build.logs.cloudWatchLogs.groupName"];
NSString *Status = [jResp StringOf: @"build.logs.cloudWatchLogs.status"];
NSString *StreamName = [jResp StringOf: @"build.logs.cloudWatchLogs.streamName"];
NSString *CloudWatchLogsArn = [jResp StringOf: @"build.logs.cloudWatchLogsArn"];
NSString *DeepLink = [jResp StringOf: @"build.logs.deepLink"];
NSString *LogsGroupName = [jResp StringOf: @"build.logs.groupName"];
NSString *S3DeepLink = [jResp StringOf: @"build.logs.s3DeepLink"];
NSString *S3LogsBucketOwnerAccess = [jResp StringOf: @"build.logs.s3Logs.bucketOwnerAccess"];
int S3LogsEncryptionDisabled = [[jResp IntOf: @"build.logs.s3Logs.encryptionDisabled"] intValue];
NSString *S3LogsLocation = [jResp StringOf: @"build.logs.s3Logs.location"];
NSString *S3LogsStatus = [jResp StringOf: @"build.logs.s3Logs.status"];
NSString *S3LogsArn = [jResp StringOf: @"build.logs.s3LogsArn"];
NSString *LogsStreamName = [jResp StringOf: @"build.logs.streamName"];
NSString *NetworkInterfaceId = [jResp StringOf: @"build.networkInterface.networkInterfaceId"];
NSString *SubnetId = [jResp StringOf: @"build.networkInterface.subnetId"];
NSString *ProjectName = [jResp StringOf: @"build.projectName"];
int QueuedTimeoutInMinutes = [[jResp IntOf: @"build.queuedTimeoutInMinutes"] intValue];
NSString *ResolvedSourceVersion = [jResp StringOf: @"build.resolvedSourceVersion"];
NSString *ServiceRole = [jResp StringOf: @"build.serviceRole"];
NSString *Resource = [jResp StringOf: @"build.source.auth.resource"];
NSString *AuthType = [jResp StringOf: @"build.source.auth.type"];
NSString *Buildspec = [jResp StringOf: @"build.source.buildspec"];
NSString *Context = [jResp StringOf: @"build.source.buildStatusConfig.context"];
NSString *TargetUrl = [jResp StringOf: @"build.source.buildStatusConfig.targetUrl"];
int GitCloneDepth = [[jResp IntOf: @"build.source.gitCloneDepth"] intValue];
int FetchSubmodules = [[jResp IntOf: @"build.source.gitSubmodulesConfig.fetchSubmodules"] intValue];
int InsecureSsl = [[jResp IntOf: @"build.source.insecureSsl"] intValue];
NSString *SourceLocation = [jResp StringOf: @"build.source.location"];
int ReportBuildStatus = [[jResp IntOf: @"build.source.reportBuildStatus"] intValue];
NSString *SourceIdentifier = [jResp StringOf: @"build.source.sourceIdentifier"];
NSString *SourceType = [jResp StringOf: @"build.source.type"];
NSString *SourceVersion = [jResp StringOf: @"build.sourceVersion"];
int StartTime = [[jResp IntOf: @"build.startTime"] intValue];
int TimeoutInMinutes = [[jResp IntOf: @"build.timeoutInMinutes"] intValue];
NSString *VpcId = [jResp StringOf: @"build.vpcConfig.vpcId"];
int i = 0;
int count_i = [[jResp SizeOfArray: @"build.cache.modes"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    strVal = [jResp StringOf: @"build.cache.modes[i]"];
    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"build.environment.environmentVariables"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    name = [jResp StringOf: @"build.environment.environmentVariables[i].name"];
    v_type = [jResp StringOf: @"build.environment.environmentVariables[i].type"];
    value = [jResp StringOf: @"build.environment.environmentVariables[i].value"];
    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"build.exportedEnvironmentVariables"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    name = [jResp StringOf: @"build.exportedEnvironmentVariables[i].name"];
    value = [jResp StringOf: @"build.exportedEnvironmentVariables[i].value"];
    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"build.fileSystemLocations"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    identifier = [jResp StringOf: @"build.fileSystemLocations[i].identifier"];
    location = [jResp StringOf: @"build.fileSystemLocations[i].location"];
    mountOptions = [jResp StringOf: @"build.fileSystemLocations[i].mountOptions"];
    mountPoint = [jResp StringOf: @"build.fileSystemLocations[i].mountPoint"];
    v_type = [jResp StringOf: @"build.fileSystemLocations[i].type"];
    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"build.phases"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    durationInSeconds = [[jResp IntOf: @"build.phases[i].durationInSeconds"] intValue];
    endTime = [[jResp IntOf: @"build.phases[i].endTime"] intValue];
    phaseStatus = [jResp StringOf: @"build.phases[i].phaseStatus"];
    phaseType = [jResp StringOf: @"build.phases[i].phaseType"];
    startTime = [[jResp IntOf: @"build.phases[i].startTime"] intValue];
    j = 0;
    count_j = [[jResp SizeOfArray: @"build.phases[i].contexts"] intValue];
    while (j < count_j) {
        jResp.J = [NSNumber numberWithInt: j];
        message = [jResp StringOf: @"build.phases[i].contexts[j].message"];
        statusCode = [jResp StringOf: @"build.phases[i].contexts[j].statusCode"];
        j = j + 1;
    }

    i = i + 1;
}

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

i = 0;
count_i = [[jResp SizeOfArray: @"build.secondaryArtifacts"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    artifactIdentifier = [jResp StringOf: @"build.secondaryArtifacts[i].artifactIdentifier"];
    bucketOwnerAccess = [jResp StringOf: @"build.secondaryArtifacts[i].bucketOwnerAccess"];
    encryptionDisabled = [[jResp IntOf: @"build.secondaryArtifacts[i].encryptionDisabled"] intValue];
    location = [jResp StringOf: @"build.secondaryArtifacts[i].location"];
    md5sum = [jResp StringOf: @"build.secondaryArtifacts[i].md5sum"];
    overrideArtifactName = [[jResp IntOf: @"build.secondaryArtifacts[i].overrideArtifactName"] intValue];
    sha256sum = [jResp StringOf: @"build.secondaryArtifacts[i].sha256sum"];
    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"build.secondarySources"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    authResource = [jResp StringOf: @"build.secondarySources[i].auth.resource"];
    authType = [jResp StringOf: @"build.secondarySources[i].auth.type"];
    buildspec = [jResp StringOf: @"build.secondarySources[i].buildspec"];
    buildStatusConfigContext = [jResp StringOf: @"build.secondarySources[i].buildStatusConfig.context"];
    buildStatusConfigTargetUrl = [jResp StringOf: @"build.secondarySources[i].buildStatusConfig.targetUrl"];
    gitCloneDepth = [[jResp IntOf: @"build.secondarySources[i].gitCloneDepth"] intValue];
    gitSubmodulesConfigFetchSubmodules = [[jResp IntOf: @"build.secondarySources[i].gitSubmodulesConfig.fetchSubmodules"] intValue];
    insecureSsl = [[jResp IntOf: @"build.secondarySources[i].insecureSsl"] intValue];
    location = [jResp StringOf: @"build.secondarySources[i].location"];
    reportBuildStatus = [[jResp IntOf: @"build.secondarySources[i].reportBuildStatus"] intValue];
    sourceIdentifier = [jResp StringOf: @"build.secondarySources[i].sourceIdentifier"];
    v_type = [jResp StringOf: @"build.secondarySources[i].type"];
    i = i + 1;
}

i = 0;
count_i = [[jResp SizeOfArray: @"build.secondarySourceVersions"] intValue];
while (i < count_i) {
    jResp.I = [NSNumber numberWithInt: i];
    sourceIdentifier = [jResp StringOf: @"build.secondarySourceVersions[i].sourceIdentifier"];
    sourceVersion = [jResp StringOf: @"build.secondarySourceVersions[i].sourceVersion"];
    i = i + 1;
}

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

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

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

// {
//   "build": {
//     "arn": "string",
//     "artifacts": {
//       "artifactIdentifier": "string",
//       "bucketOwnerAccess": "string",
//       "encryptionDisabled": boolean,
//       "location": "string",
//       "md5sum": "string",
//       "overrideArtifactName": boolean,
//       "sha256sum": "string"
//     },
//     "buildBatchArn": "string",
//     "buildComplete": boolean,
//     "buildNumber": number,
//     "buildStatus": "string",
//     "cache": {
//       "location": "string",
//       "modes": [
//         "string"
//       ],
//       "type": "string"
//     },
//     "currentPhase": "string",
//     "debugSession": {
//       "sessionEnabled": boolean,
//       "sessionTarget": "string"
//     },
//     "encryptionKey": "string",
//     "endTime": number,
//     "environment": {
//       "certificate": "string",
//       "computeType": "string",
//       "environmentVariables": [
//         {
//           "name": "string",
//           "type": "string",
//           "value": "string"
//         }
//       ],
//       "image": "string",
//       "imagePullCredentialsType": "string",
//       "privilegedMode": boolean,
//       "registryCredential": {
//         "credential": "string",
//         "credentialProvider": "string"
//       },
//       "type": "string"
//     },
//     "exportedEnvironmentVariables": [
//       {
//         "name": "string",
//         "value": "string"
//       }
//     ],
//     "fileSystemLocations": [
//       {
//         "identifier": "string",
//         "location": "string",
//         "mountOptions": "string",
//         "mountPoint": "string",
//         "type": "string"
//       }
//     ],
//     "id": "string",
//     "initiator": "string",
//     "logs": {
//       "cloudWatchLogs": {
//         "groupName": "string",
//         "status": "string",
//         "streamName": "string"
//       },
//       "cloudWatchLogsArn": "string",
//       "deepLink": "string",
//       "groupName": "string",
//       "s3DeepLink": "string",
//       "s3Logs": {
//         "bucketOwnerAccess": "string",
//         "encryptionDisabled": boolean,
//         "location": "string",
//         "status": "string"
//       },
//       "s3LogsArn": "string",
//       "streamName": "string"
//     },
//     "networkInterface": {
//       "networkInterfaceId": "string",
//       "subnetId": "string"
//     },
//     "phases": [
//       {
//         "contexts": [
//           {
//             "message": "string",
//             "statusCode": "string"
//           }
//         ],
//         "durationInSeconds": number,
//         "endTime": number,
//         "phaseStatus": "string",
//         "phaseType": "string",
//         "startTime": number
//       }
//     ],
//     "projectName": "string",
//     "queuedTimeoutInMinutes": number,
//     "reportArns": [
//       "string"
//     ],
//     "resolvedSourceVersion": "string",
//     "secondaryArtifacts": [
//       {
//         "artifactIdentifier": "string",
//         "bucketOwnerAccess": "string",
//         "encryptionDisabled": boolean,
//         "location": "string",
//         "md5sum": "string",
//         "overrideArtifactName": boolean,
//         "sha256sum": "string"
//       }
//     ],
//     "secondarySources": [
//       {
//         "auth": {
//           "resource": "string",
//           "type": "string"
//         },
//         "buildspec": "string",
//         "buildStatusConfig": {
//           "context": "string",
//           "targetUrl": "string"
//         },
//         "gitCloneDepth": number,
//         "gitSubmodulesConfig": {
//           "fetchSubmodules": boolean
//         },
//         "insecureSsl": boolean,
//         "location": "string",
//         "reportBuildStatus": boolean,
//         "sourceIdentifier": "string",
//         "type": "string"
//       }
//     ],
//     "secondarySourceVersions": [
//       {
//         "sourceIdentifier": "string",
//         "sourceVersion": "string"
//       }
//     ],
//     "serviceRole": "string",
//     "source": {
//       "auth": {
//         "resource": "string",
//         "type": "string"
//       },
//       "buildspec": "string",
//       "buildStatusConfig": {
//         "context": "string",
//         "targetUrl": "string"
//       },
//       "gitCloneDepth": number,
//       "gitSubmodulesConfig": {
//         "fetchSubmodules": boolean
//       },
//       "insecureSsl": boolean,
//       "location": "string",
//       "reportBuildStatus": boolean,
//       "sourceIdentifier": "string",
//       "type": "string"
//     },
//     "sourceVersion": "string",
//     "startTime": number,
//     "timeoutInMinutes": number,
//     "vpcConfig": {
//       "securityGroupIds": [
//         "string"
//       ],
//       "subnets": [
//         "string"
//       ],
//       "vpcId": "string"
//     }
//   }
// }