Chilkat Online Tools

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

    i = 0
    count_i = jResp.SizeOfArray("run.customerArtifactPaths.deviceHostPaths").intValue
    while i < count_i {
        jResp.I = i
        strVal = jResp.StringOf("run.customerArtifactPaths.deviceHostPaths[i]")
        i = i + 1
    }

    i = 0
    count_i = jResp.SizeOfArray("run.customerArtifactPaths.iosPaths").intValue
    while i < count_i {
        jResp.I = i
        strVal = jResp.StringOf("run.customerArtifactPaths.iosPaths[i]")
        i = i + 1
    }

    i = 0
    count_i = jResp.SizeOfArray("run.deviceSelectionResult.filters").intValue
    while i < count_i {
        jResp.I = i
        attribute = jResp.StringOf("run.deviceSelectionResult.filters[i].attribute")
        operator = jResp.StringOf("run.deviceSelectionResult.filters[i].operator")
        j = 0
        count_j = jResp.SizeOfArray("run.deviceSelectionResult.filters[i].values").intValue
        while j < count_j {
            jResp.J = j
            strVal = jResp.StringOf("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"
    //   }
    // }

}