Chilkat Online Tools

BatchGetProjects Swift3 Example

AWS CodeBuild

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

    let rest = CkoRest()!
    var success: Bool

    let authAws = CkoAuthAws()!
    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: 443, tls: true, autoReconnect: true)
    if success != true {
        print("ConnectFailReason: \(rest.connectFailReason.intValue)")
        print("\(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

    let json = CkoJsonObject()!
    json.update("names[0]", value: "string")

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

    // {
    //   "names": [
    //     "string"
    //   ]
    // }

    rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
    rest.addHeader("X-Amz-Target", value: "CodeBuild_20161006.BatchGetProjects")

    let sbRequestBody = CkoStringBuilder()!
    json.emitSb(sbRequestBody)
    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestSb("POST", uriPath: "/", requestBody: sbRequestBody, responseBody: sbResponseBody)
    if success != true {
        print("\(rest.lastErrorText!)")
        return
    }

    var respStatusCode: Int = rest.responseStatusCode.intValue
    print("response status code = \(respStatusCode)")
    if respStatusCode != 200 {
        print("Response Header:")
        print("\(rest.responseHeader!)")
        print("Response Body:")
        print("\(sbResponseBody.getAsString()!)")
        return
    }

    let jResp = CkoJsonObject()!
    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

    var arn: String?
    var ArtifactIdentifier: String?
    var BucketOwnerAccess: String?
    var EncryptionDisabled: Int
    var Location: String?
    var Name: String?
    var NamespaceType: String?
    var OverrideArtifactName: Int
    var Packaging: String?
    var Path: String?
    var v_Type: String?
    var BadgeEnabled: Int
    var BadgeRequestUrl: String?
    var BatchReportMode: String?
    var CombineArtifacts: Int
    var MaximumBuildsAllowed: Int
    var ServiceRole: String?
    var TimeoutInMins: Int
    var cacheLocation: String?
    var cacheType: String?
    var concurrentBuildLimit: Int
    var created: Int
    var description: String?
    var encryptionKey: String?
    var Certificate: String?
    var ComputeType: String?
    var Image: String?
    var ImagePullCredentialsType: String?
    var PrivilegedMode: Int
    var Credential: String?
    var CredentialProvider: String?
    var environmentType: String?
    var lastModified: Int
    var GroupName: String?
    var Status: String?
    var StreamName: String?
    var S3LogsBucketOwnerAccess: String?
    var S3LogsEncryptionDisabled: Int
    var S3LogsLocation: String?
    var S3LogsStatus: String?
    var name: String?
    var projectVisibility: String?
    var publicProjectAlias: String?
    var queuedTimeoutInMinutes: Int
    var resourceAccessRole: String?
    var serviceRole: String?
    var Resource: String?
    var AuthType: String?
    var Buildspec: String?
    var Context: String?
    var TargetUrl: String?
    var GitCloneDepth: Int
    var FetchSubmodules: Int
    var InsecureSsl: Int
    var sourceLocation: String?
    var ReportBuildStatus: Int
    var SourceIdentifier: String?
    var sourceType: String?
    var sourceVersion: String?
    var timeoutInMinutes: Int
    var VpcId: String?
    var BranchFilter: String?
    var BuildType: String?
    var LastModifiedSecret: Int
    var PayloadUrl: String?
    var Secret: String?
    var v_Url: String?
    var j: Int
    var count_j: Int
    var strVal: String?
    var v_type: String?
    var value: String?
    var identifier: String?
    var location: String?
    var mountOptions: String?
    var mountPoint: String?
    var artifactIdentifier: String?
    var bucketOwnerAccess: String?
    var encryptionDisabled: Int
    var namespaceType: String?
    var overrideArtifactName: Int
    var packaging: String?
    var path: String?
    var authResource: String?
    var authType: String?
    var buildspec: String?
    var buildStatusConfigContext: String?
    var buildStatusConfigTargetUrl: String?
    var gitCloneDepth: Int
    var gitSubmodulesConfigFetchSubmodules: Int
    var insecureSsl: Int
    var reportBuildStatus: Int
    var sourceIdentifier: String?
    var key: String?
    var k: Int
    var count_k: Int
    var excludeMatchedPattern: Int
    var pattern: String?

    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "projects").intValue
    while i < count_i {
        jResp.i = i
        arn = jResp.string(of: "projects[i].arn")
        ArtifactIdentifier = jResp.string(of: "projects[i].artifacts.artifactIdentifier")
        BucketOwnerAccess = jResp.string(of: "projects[i].artifacts.bucketOwnerAccess")
        EncryptionDisabled = jResp.int(of: "projects[i].artifacts.encryptionDisabled").intValue
        Location = jResp.string(of: "projects[i].artifacts.location")
        Name = jResp.string(of: "projects[i].artifacts.name")
        NamespaceType = jResp.string(of: "projects[i].artifacts.namespaceType")
        OverrideArtifactName = jResp.int(of: "projects[i].artifacts.overrideArtifactName").intValue
        Packaging = jResp.string(of: "projects[i].artifacts.packaging")
        Path = jResp.string(of: "projects[i].artifacts.path")
        v_Type = jResp.string(of: "projects[i].artifacts.type")
        BadgeEnabled = jResp.int(of: "projects[i].badge.badgeEnabled").intValue
        BadgeRequestUrl = jResp.string(of: "projects[i].badge.badgeRequestUrl")
        BatchReportMode = jResp.string(of: "projects[i].buildBatchConfig.batchReportMode")
        CombineArtifacts = jResp.int(of: "projects[i].buildBatchConfig.combineArtifacts").intValue
        MaximumBuildsAllowed = jResp.int(of: "projects[i].buildBatchConfig.restrictions.maximumBuildsAllowed").intValue
        ServiceRole = jResp.string(of: "projects[i].buildBatchConfig.serviceRole")
        TimeoutInMins = jResp.int(of: "projects[i].buildBatchConfig.timeoutInMins").intValue
        cacheLocation = jResp.string(of: "projects[i].cache.location")
        cacheType = jResp.string(of: "projects[i].cache.type")
        concurrentBuildLimit = jResp.int(of: "projects[i].concurrentBuildLimit").intValue
        created = jResp.int(of: "projects[i].created").intValue
        description = jResp.string(of: "projects[i].description")
        encryptionKey = jResp.string(of: "projects[i].encryptionKey")
        Certificate = jResp.string(of: "projects[i].environment.certificate")
        ComputeType = jResp.string(of: "projects[i].environment.computeType")
        Image = jResp.string(of: "projects[i].environment.image")
        ImagePullCredentialsType = jResp.string(of: "projects[i].environment.imagePullCredentialsType")
        PrivilegedMode = jResp.int(of: "projects[i].environment.privilegedMode").intValue
        Credential = jResp.string(of: "projects[i].environment.registryCredential.credential")
        CredentialProvider = jResp.string(of: "projects[i].environment.registryCredential.credentialProvider")
        environmentType = jResp.string(of: "projects[i].environment.type")
        lastModified = jResp.int(of: "projects[i].lastModified").intValue
        GroupName = jResp.string(of: "projects[i].logsConfig.cloudWatchLogs.groupName")
        Status = jResp.string(of: "projects[i].logsConfig.cloudWatchLogs.status")
        StreamName = jResp.string(of: "projects[i].logsConfig.cloudWatchLogs.streamName")
        S3LogsBucketOwnerAccess = jResp.string(of: "projects[i].logsConfig.s3Logs.bucketOwnerAccess")
        S3LogsEncryptionDisabled = jResp.int(of: "projects[i].logsConfig.s3Logs.encryptionDisabled").intValue
        S3LogsLocation = jResp.string(of: "projects[i].logsConfig.s3Logs.location")
        S3LogsStatus = jResp.string(of: "projects[i].logsConfig.s3Logs.status")
        name = jResp.string(of: "projects[i].name")
        projectVisibility = jResp.string(of: "projects[i].projectVisibility")
        publicProjectAlias = jResp.string(of: "projects[i].publicProjectAlias")
        queuedTimeoutInMinutes = jResp.int(of: "projects[i].queuedTimeoutInMinutes").intValue
        resourceAccessRole = jResp.string(of: "projects[i].resourceAccessRole")
        serviceRole = jResp.string(of: "projects[i].serviceRole")
        Resource = jResp.string(of: "projects[i].source.auth.resource")
        AuthType = jResp.string(of: "projects[i].source.auth.type")
        Buildspec = jResp.string(of: "projects[i].source.buildspec")
        Context = jResp.string(of: "projects[i].source.buildStatusConfig.context")
        TargetUrl = jResp.string(of: "projects[i].source.buildStatusConfig.targetUrl")
        GitCloneDepth = jResp.int(of: "projects[i].source.gitCloneDepth").intValue
        FetchSubmodules = jResp.int(of: "projects[i].source.gitSubmodulesConfig.fetchSubmodules").intValue
        InsecureSsl = jResp.int(of: "projects[i].source.insecureSsl").intValue
        sourceLocation = jResp.string(of: "projects[i].source.location")
        ReportBuildStatus = jResp.int(of: "projects[i].source.reportBuildStatus").intValue
        SourceIdentifier = jResp.string(of: "projects[i].source.sourceIdentifier")
        sourceType = jResp.string(of: "projects[i].source.type")
        sourceVersion = jResp.string(of: "projects[i].sourceVersion")
        timeoutInMinutes = jResp.int(of: "projects[i].timeoutInMinutes").intValue
        VpcId = jResp.string(of: "projects[i].vpcConfig.vpcId")
        BranchFilter = jResp.string(of: "projects[i].webhook.branchFilter")
        BuildType = jResp.string(of: "projects[i].webhook.buildType")
        LastModifiedSecret = jResp.int(of: "projects[i].webhook.lastModifiedSecret").intValue
        PayloadUrl = jResp.string(of: "projects[i].webhook.payloadUrl")
        Secret = jResp.string(of: "projects[i].webhook.secret")
        v_Url = jResp.string(of: "projects[i].webhook.url")
        j = 0
        count_j = jResp.size(ofArray: "projects[i].buildBatchConfig.restrictions.computeTypesAllowed").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "projects[i].buildBatchConfig.restrictions.computeTypesAllowed[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "projects[i].cache.modes").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "projects[i].cache.modes[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "projects[i].environment.environmentVariables").intValue
        while j < count_j {
            jResp.j = j
            name = jResp.string(of: "projects[i].environment.environmentVariables[j].name")
            v_type = jResp.string(of: "projects[i].environment.environmentVariables[j].type")
            value = jResp.string(of: "projects[i].environment.environmentVariables[j].value")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "projects[i].fileSystemLocations").intValue
        while j < count_j {
            jResp.j = j
            identifier = jResp.string(of: "projects[i].fileSystemLocations[j].identifier")
            location = jResp.string(of: "projects[i].fileSystemLocations[j].location")
            mountOptions = jResp.string(of: "projects[i].fileSystemLocations[j].mountOptions")
            mountPoint = jResp.string(of: "projects[i].fileSystemLocations[j].mountPoint")
            v_type = jResp.string(of: "projects[i].fileSystemLocations[j].type")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "projects[i].secondaryArtifacts").intValue
        while j < count_j {
            jResp.j = j
            artifactIdentifier = jResp.string(of: "projects[i].secondaryArtifacts[j].artifactIdentifier")
            bucketOwnerAccess = jResp.string(of: "projects[i].secondaryArtifacts[j].bucketOwnerAccess")
            encryptionDisabled = jResp.int(of: "projects[i].secondaryArtifacts[j].encryptionDisabled").intValue
            location = jResp.string(of: "projects[i].secondaryArtifacts[j].location")
            name = jResp.string(of: "projects[i].secondaryArtifacts[j].name")
            namespaceType = jResp.string(of: "projects[i].secondaryArtifacts[j].namespaceType")
            overrideArtifactName = jResp.int(of: "projects[i].secondaryArtifacts[j].overrideArtifactName").intValue
            packaging = jResp.string(of: "projects[i].secondaryArtifacts[j].packaging")
            path = jResp.string(of: "projects[i].secondaryArtifacts[j].path")
            v_type = jResp.string(of: "projects[i].secondaryArtifacts[j].type")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "projects[i].secondarySources").intValue
        while j < count_j {
            jResp.j = j
            authResource = jResp.string(of: "projects[i].secondarySources[j].auth.resource")
            authType = jResp.string(of: "projects[i].secondarySources[j].auth.type")
            buildspec = jResp.string(of: "projects[i].secondarySources[j].buildspec")
            buildStatusConfigContext = jResp.string(of: "projects[i].secondarySources[j].buildStatusConfig.context")
            buildStatusConfigTargetUrl = jResp.string(of: "projects[i].secondarySources[j].buildStatusConfig.targetUrl")
            gitCloneDepth = jResp.int(of: "projects[i].secondarySources[j].gitCloneDepth").intValue
            gitSubmodulesConfigFetchSubmodules = jResp.int(of: "projects[i].secondarySources[j].gitSubmodulesConfig.fetchSubmodules").intValue
            insecureSsl = jResp.int(of: "projects[i].secondarySources[j].insecureSsl").intValue
            location = jResp.string(of: "projects[i].secondarySources[j].location")
            reportBuildStatus = jResp.int(of: "projects[i].secondarySources[j].reportBuildStatus").intValue
            sourceIdentifier = jResp.string(of: "projects[i].secondarySources[j].sourceIdentifier")
            v_type = jResp.string(of: "projects[i].secondarySources[j].type")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "projects[i].secondarySourceVersions").intValue
        while j < count_j {
            jResp.j = j
            sourceIdentifier = jResp.string(of: "projects[i].secondarySourceVersions[j].sourceIdentifier")
            sourceVersion = jResp.string(of: "projects[i].secondarySourceVersions[j].sourceVersion")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "projects[i].tags").intValue
        while j < count_j {
            jResp.j = j
            key = jResp.string(of: "projects[i].tags[j].key")
            value = jResp.string(of: "projects[i].tags[j].value")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "projects[i].vpcConfig.securityGroupIds").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "projects[i].vpcConfig.securityGroupIds[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "projects[i].vpcConfig.subnets").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "projects[i].vpcConfig.subnets[j]")
            j = j + 1
        }

        j = 0
        count_j = jResp.size(ofArray: "projects[i].webhook.filterGroups").intValue
        while j < count_j {
            jResp.j = j
            k = 0
            count_k = jResp.size(ofArray: "projects[i].webhook.filterGroups[j]").intValue
            while k < count_k {
                jResp.k = k
                excludeMatchedPattern = jResp.int(of: "projects[i].webhook.filterGroups[j][k].excludeMatchedPattern").intValue
                pattern = jResp.string(of: "projects[i].webhook.filterGroups[j][k].pattern")
                v_type = jResp.string(of: "projects[i].webhook.filterGroups[j][k].type")
                k = k + 1
            }

            j = j + 1
        }

        i = i + 1
    }

    i = 0
    count_i = jResp.size(ofArray: "projectsNotFound").intValue
    while i < count_i {
        jResp.i = i
        strVal = jResp.string(of: "projectsNotFound[i]")
        i = i + 1
    }

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

    // {
    //   "projects": [
    //     {
    //       "arn": "string",
    //       "artifacts": {
    //         "artifactIdentifier": "string",
    //         "bucketOwnerAccess": "string",
    //         "encryptionDisabled": boolean,
    //         "location": "string",
    //         "name": "string",
    //         "namespaceType": "string",
    //         "overrideArtifactName": boolean,
    //         "packaging": "string",
    //         "path": "string",
    //         "type": "string"
    //       },
    //       "badge": {
    //         "badgeEnabled": boolean,
    //         "badgeRequestUrl": "string"
    //       },
    //       "buildBatchConfig": {
    //         "batchReportMode": "string",
    //         "combineArtifacts": boolean,
    //         "restrictions": {
    //           "computeTypesAllowed": [
    //             "string"
    //           ],
    //           "maximumBuildsAllowed": number
    //         },
    //         "serviceRole": "string",
    //         "timeoutInMins": number
    //       },
    //       "cache": {
    //         "location": "string",
    //         "modes": [
    //           "string"
    //         ],
    //         "type": "string"
    //       },
    //       "concurrentBuildLimit": number,
    //       "created": number,
    //       "description": "string",
    //       "encryptionKey": "string",
    //       "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"
    //       },
    //       "fileSystemLocations": [
    //         {
    //           "identifier": "string",
    //           "location": "string",
    //           "mountOptions": "string",
    //           "mountPoint": "string",
    //           "type": "string"
    //         }
    //       ],
    //       "lastModified": number,
    //       "logsConfig": {
    //         "cloudWatchLogs": {
    //           "groupName": "string",
    //           "status": "string",
    //           "streamName": "string"
    //         },
    //         "s3Logs": {
    //           "bucketOwnerAccess": "string",
    //           "encryptionDisabled": boolean,
    //           "location": "string",
    //           "status": "string"
    //         }
    //       },
    //       "name": "string",
    //       "projectVisibility": "string",
    //       "publicProjectAlias": "string",
    //       "queuedTimeoutInMinutes": number,
    //       "resourceAccessRole": "string",
    //       "secondaryArtifacts": [
    //         {
    //           "artifactIdentifier": "string",
    //           "bucketOwnerAccess": "string",
    //           "encryptionDisabled": boolean,
    //           "location": "string",
    //           "name": "string",
    //           "namespaceType": "string",
    //           "overrideArtifactName": boolean,
    //           "packaging": "string",
    //           "path": "string",
    //           "type": "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",
    //       "tags": [
    //         {
    //           "key": "string",
    //           "value": "string"
    //         }
    //       ],
    //       "timeoutInMinutes": number,
    //       "vpcConfig": {
    //         "securityGroupIds": [
    //           "string"
    //         ],
    //         "subnets": [
    //           "string"
    //         ],
    //         "vpcId": "string"
    //       },
    //       "webhook": {
    //         "branchFilter": "string",
    //         "buildType": "string",
    //         "filterGroups": [
    //           [
    //             {
    //               "excludeMatchedPattern": boolean,
    //               "pattern": "string",
    //               "type": "string"
    //             }
    //           ]
    //         ],
    //         "lastModifiedSecret": number,
    //         "payloadUrl": "string",
    //         "secret": "string",
    //         "url": "string"
    //       }
    //     }
    //   ],
    //   "projectsNotFound": [
    //     "string"
    //   ]
    // }

}