Chilkat Online Tools

GetJob Swift3 Example

Amplify

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

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

    let sbResponseBody = CkoStringBuilder()!
    success = rest.fullRequestNoBodySb("GET", uriPath: "/apps/{appId}/branches/{branchName}/jobs/{jobId}", sb: 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 artifactsUrl: String?
    var context: String?
    var endTime: Int
    var logUrl: String?
    var v_String: String?
    var startTime: Int
    var status: String?
    var statusReason: String?
    var stepName: String?
    var testArtifactsUrl: String?
    var testConfigUrl: String?

    var CommitId: String? = jResp.string(of: "job.summary.commitId")
    var CommitMessage: String? = jResp.string(of: "job.summary.commitMessage")
    var CommitTime: Int = jResp.int(of: "job.summary.commitTime").intValue
    var EndTime: Int = jResp.int(of: "job.summary.endTime").intValue
    var JobArn: String? = jResp.string(of: "job.summary.jobArn")
    var JobId: String? = jResp.string(of: "job.summary.jobId")
    var JobType: String? = jResp.string(of: "job.summary.jobType")
    var StartTime: Int = jResp.int(of: "job.summary.startTime").intValue
    var Status: String? = jResp.string(of: "job.summary.status")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "job.steps").intValue
    while i < count_i {
        jResp.i = i
        artifactsUrl = jResp.string(of: "job.steps[i].artifactsUrl")
        context = jResp.string(of: "job.steps[i].context")
        endTime = jResp.int(of: "job.steps[i].endTime").intValue
        logUrl = jResp.string(of: "job.steps[i].logUrl")
        v_String = jResp.string(of: "job.steps[i].screenshots.string")
        startTime = jResp.int(of: "job.steps[i].startTime").intValue
        status = jResp.string(of: "job.steps[i].status")
        statusReason = jResp.string(of: "job.steps[i].statusReason")
        stepName = jResp.string(of: "job.steps[i].stepName")
        testArtifactsUrl = jResp.string(of: "job.steps[i].testArtifactsUrl")
        testConfigUrl = jResp.string(of: "job.steps[i].testConfigUrl")
        i = i + 1
    }

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

    // {
    //   "job": {
    //     "steps": [
    //       {
    //         "artifactsUrl": "string",
    //         "context": "string",
    //         "endTime": number,
    //         "logUrl": "string",
    //         "screenshots": {
    //           "string": "string"
    //         },
    //         "startTime": number,
    //         "status": "string",
    //         "statusReason": "string",
    //         "stepName": "string",
    //         "testArtifactsUrl": "string",
    //         "testConfigUrl": "string"
    //       }
    //     ],
    //     "summary": {
    //       "commitId": "string",
    //       "commitMessage": "string",
    //       "commitTime": number,
    //       "endTime": number,
    //       "jobArn": "string",
    //       "jobId": "string",
    //       "jobType": "string",
    //       "startTime": number,
    //       "status": "string"
    //     }
    //   }
    // }

}