Chilkat Online Tools

GetRun Swift3 Example

AWS Device Farm

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 = "devicefarm"
    // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    rest.setAuthAws(authAws)

    // URL: https://devicefarm.us-west-2.amazonaws.com/
    // Use the same region as specified above.
    success = rest.connect("devicefarm.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("arn", value: "string")

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

    // {
    //   "arn": "string"
    // }

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

    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 strVal: String?
    var attribute: String?
    var operator: String?
    var j: Int
    var count_j: Int

    var AppUpload: String? = jResp.string(of: "run.appUpload")
    var Arn: String? = jResp.string(of: "run.arn")
    var BillingMethod: String? = jResp.string(of: "run.billingMethod")
    var CompletedJobs: Int = jResp.int(of: "run.completedJobs").intValue
    var Errored: Int = jResp.int(of: "run.counters.errored").intValue
    var Failed: Int = jResp.int(of: "run.counters.failed").intValue
    var Passed: Int = jResp.int(of: "run.counters.passed").intValue
    var Skipped: Int = jResp.int(of: "run.counters.skipped").intValue
    var Stopped: Int = jResp.int(of: "run.counters.stopped").intValue
    var Total: Int = jResp.int(of: "run.counters.total").intValue
    var Warned: Int = jResp.int(of: "run.counters.warned").intValue
    var Created: Int = jResp.int(of: "run.created").intValue
    var Metered: Int = jResp.int(of: "run.deviceMinutes.metered").intValue
    var DeviceMinutesTotal: Int = jResp.int(of: "run.deviceMinutes.total").intValue
    var Unmetered: Int = jResp.int(of: "run.deviceMinutes.unmetered").intValue
    var DevicePoolArn: String? = jResp.string(of: "run.devicePoolArn")
    var MatchedDevicesCount: Int = jResp.int(of: "run.deviceSelectionResult.matchedDevicesCount").intValue
    var MaxDevices: Int = jResp.int(of: "run.deviceSelectionResult.maxDevices").intValue
    var EventCount: Int = jResp.int(of: "run.eventCount").intValue
    var JobTimeoutMinutes: Int = jResp.int(of: "run.jobTimeoutMinutes").intValue
    var Locale: String? = jResp.string(of: "run.locale")
    var Latitude: Int = jResp.int(of: "run.location.latitude").intValue
    var Longitude: Int = jResp.int(of: "run.location.longitude").intValue
    var Message: String? = jResp.string(of: "run.message")
    var Name: String? = jResp.string(of: "run.name")
    var NetworkProfileArn: String? = jResp.string(of: "run.networkProfile.arn")
    var Description: String? = jResp.string(of: "run.networkProfile.description")
    var DownlinkBandwidthBits: Int = jResp.int(of: "run.networkProfile.downlinkBandwidthBits").intValue
    var DownlinkDelayMs: Int = jResp.int(of: "run.networkProfile.downlinkDelayMs").intValue
    var DownlinkJitterMs: Int = jResp.int(of: "run.networkProfile.downlinkJitterMs").intValue
    var DownlinkLossPercent: Int = jResp.int(of: "run.networkProfile.downlinkLossPercent").intValue
    var NetworkProfileName: String? = jResp.string(of: "run.networkProfile.name")
    var v_Type: String? = jResp.string(of: "run.networkProfile.type")
    var UplinkBandwidthBits: Int = jResp.int(of: "run.networkProfile.uplinkBandwidthBits").intValue
    var UplinkDelayMs: Int = jResp.int(of: "run.networkProfile.uplinkDelayMs").intValue
    var UplinkJitterMs: Int = jResp.int(of: "run.networkProfile.uplinkJitterMs").intValue
    var UplinkLossPercent: Int = jResp.int(of: "run.networkProfile.uplinkLossPercent").intValue
    var ParsingResultUrl: String? = jResp.string(of: "run.parsingResultUrl")
    var Platform: String? = jResp.string(of: "run.platform")
    var Bluetooth: Int = jResp.int(of: "run.radios.bluetooth").intValue
    var Gps: Int = jResp.int(of: "run.radios.gps").intValue
    var Nfc: Int = jResp.int(of: "run.radios.nfc").intValue
    var Wifi: Int = jResp.int(of: "run.radios.wifi").intValue
    var Result: String? = jResp.string(of: "run.result")
    var ResultCode: String? = jResp.string(of: "run.resultCode")
    var Seed: Int = jResp.int(of: "run.seed").intValue
    var SkipAppResign: Int = jResp.int(of: "run.skipAppResign").intValue
    var Started: Int = jResp.int(of: "run.started").intValue
    var Status: String? = jResp.string(of: "run.status")
    var runStopped: Int = jResp.int(of: "run.stopped").intValue
    var TestSpecArn: String? = jResp.string(of: "run.testSpecArn")
    var TotalJobs: Int = jResp.int(of: "run.totalJobs").intValue
    var runType: String? = jResp.string(of: "run.type")
    var WebUrl: String? = jResp.string(of: "run.webUrl")
    var i: Int = 0
    var count_i: Int = jResp.size(ofArray: "run.customerArtifactPaths.androidPaths").intValue
    while i < count_i {
        jResp.i = i
        strVal = jResp.string(of: "run.customerArtifactPaths.androidPaths[i]")
        i = i + 1
    }

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

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

    i = 0
    count_i = jResp.size(ofArray: "run.deviceSelectionResult.filters").intValue
    while i < count_i {
        jResp.i = i
        attribute = jResp.string(of: "run.deviceSelectionResult.filters[i].attribute")
        operator = jResp.string(of: "run.deviceSelectionResult.filters[i].operator")
        j = 0
        count_j = jResp.size(ofArray: "run.deviceSelectionResult.filters[i].values").intValue
        while j < count_j {
            jResp.j = j
            strVal = jResp.string(of: "run.deviceSelectionResult.filters[i].values[j]")
            j = j + 1
        }

        i = i + 1
    }

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

    // {
    //   "run": {
    //     "appUpload": "string",
    //     "arn": "string",
    //     "billingMethod": "string",
    //     "completedJobs": number,
    //     "counters": {
    //       "errored": number,
    //       "failed": number,
    //       "passed": number,
    //       "skipped": number,
    //       "stopped": number,
    //       "total": number,
    //       "warned": number
    //     },
    //     "created": number,
    //     "customerArtifactPaths": {
    //       "androidPaths": [
    //         "string"
    //       ],
    //       "deviceHostPaths": [
    //         "string"
    //       ],
    //       "iosPaths": [
    //         "string"
    //       ]
    //     },
    //     "deviceMinutes": {
    //       "metered": number,
    //       "total": number,
    //       "unmetered": number
    //     },
    //     "devicePoolArn": "string",
    //     "deviceSelectionResult": {
    //       "filters": [
    //         {
    //           "attribute": "string",
    //           "operator": "string",
    //           "values": [
    //             "string"
    //           ]
    //         }
    //       ],
    //       "matchedDevicesCount": number,
    //       "maxDevices": number
    //     },
    //     "eventCount": number,
    //     "jobTimeoutMinutes": number,
    //     "locale": "string",
    //     "location": {
    //       "latitude": number,
    //       "longitude": number
    //     },
    //     "message": "string",
    //     "name": "string",
    //     "networkProfile": {
    //       "arn": "string",
    //       "description": "string",
    //       "downlinkBandwidthBits": number,
    //       "downlinkDelayMs": number,
    //       "downlinkJitterMs": number,
    //       "downlinkLossPercent": number,
    //       "name": "string",
    //       "type": "string",
    //       "uplinkBandwidthBits": number,
    //       "uplinkDelayMs": number,
    //       "uplinkJitterMs": number,
    //       "uplinkLossPercent": number
    //     },
    //     "parsingResultUrl": "string",
    //     "platform": "string",
    //     "radios": {
    //       "bluetooth": boolean,
    //       "gps": boolean,
    //       "nfc": boolean,
    //       "wifi": boolean
    //     },
    //     "result": "string",
    //     "resultCode": "string",
    //     "seed": number,
    //     "skipAppResign": boolean,
    //     "started": number,
    //     "status": "string",
    //     "stopped": number,
    //     "testSpecArn": "string",
    //     "totalJobs": number,
    //     "type": "string",
    //     "webUrl": "string"
    //   }
    // }

}