Chilkat Online Tools

ListDevices autoit Example

AWS Device Farm

; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.

$oRest = ObjCreate("Chilkat_9_5_0.Rest")
Local $bSuccess

$oAuthAws = ObjCreate("Chilkat_9_5_0.AuthAws")
$oAuthAws.AccessKey = "AWS_ACCESS_KEY"
$oAuthAws.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.)
$oAuthAws.Region = "us-west-2"
$oAuthAws.ServiceName = "devicefarm"
; SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
$oRest.SetAuthAws($oAuthAws)

; URL: https://devicefarm.us-west-2.amazonaws.com/
; Use the same region as specified above.
$bSuccess = $oRest.Connect("devicefarm.us-west-2.amazonaws.com",443,True,True)
If ($bSuccess <> True) Then
    ConsoleWrite("ConnectFailReason: " & $oRest.ConnectFailReason & @CRLF)
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
EndIf

; 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

$oJson = ObjCreate("Chilkat_9_5_0.JsonObject")
$oJson.UpdateString("arn","string")
$oJson.UpdateString("filters[0].attribute","string")
$oJson.UpdateString("filters[0].operator","string")
$oJson.UpdateString("filters[0].values[0]","string")
$oJson.UpdateString("nextToken","string")

; The JSON request body created by the above code:

; {
;   "arn": "string",
;   "filters": [
;     {
;       "attribute": "string",
;       "operator": "string",
;       "values": [
;         "string"
;       ]
;     }
;   ],
;   "nextToken": "string"
; }

$oRest.AddHeader("Content-Type","application/x-amz-json-1.1")
$oRest.AddHeader("X-Amz-Target","DeviceFarm_20150623.ListDevices")

$oSbRequestBody = ObjCreate("Chilkat_9_5_0.StringBuilder")
$oJson.EmitSb($oSbRequestBody)
$oSbResponseBody = ObjCreate("Chilkat_9_5_0.StringBuilder")
$bSuccess = $oRest.FullRequestSb("POST","/",$oSbRequestBody,$oSbResponseBody)
If ($bSuccess <> True) Then
    ConsoleWrite($oRest.LastErrorText & @CRLF)
    Exit
EndIf

Local $iRespStatusCode = $oRest.ResponseStatusCode
ConsoleWrite("response status code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode <> 200) Then
    ConsoleWrite("Response Header:" & @CRLF)
    ConsoleWrite($oRest.ResponseHeader & @CRLF)
    ConsoleWrite("Response Body:" & @CRLF)
    ConsoleWrite($oSbResponseBody.GetAsString() & @CRLF)
    Exit
EndIf

$oJResp = ObjCreate("Chilkat_9_5_0.JsonObject")
$oJResp.LoadSb($oSbResponseBody)

; 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

Local $sArn
Local $sAvailability
Local $sCarrier
Local $sArchitecture
Local $iClock
Local $sFrequency
Local $sFleetName
Local $sFleetType
Local $sFormFactor
Local $iHeapSize
Local $sImage
Local $sManufacturer
Local $iMemory
Local $sModel
Local $sModelId
Local $sName
Local $sOs
Local $sPlatform
Local $sRadio
Local $iRemoteAccessEnabled
Local $iRemoteDebugEnabled
Local $iHeight
Local $iWidth
Local $iJ
Local $iCount_j
Local $sDeviceArn
Local $sArn
Local $sDescription
Local $sName
Local $iPackageCleanup
Local $iRebootAfterUse
Local $status
Local $sUdid
Local $iK
Local $iCount_k
Local $strVal

Local $sNextToken = $oJResp.StringOf("nextToken")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("devices")
While $i < $iCount_i
    $oJResp.I = $i
    $sArn = $oJResp.StringOf("devices[i].arn")
    $sAvailability = $oJResp.StringOf("devices[i].availability")
    $sCarrier = $oJResp.StringOf("devices[i].carrier")
    $sArchitecture = $oJResp.StringOf("devices[i].cpu.architecture")
    $iClock = $oJResp.IntOf("devices[i].cpu.clock")
    $sFrequency = $oJResp.StringOf("devices[i].cpu.frequency")
    $sFleetName = $oJResp.StringOf("devices[i].fleetName")
    $sFleetType = $oJResp.StringOf("devices[i].fleetType")
    $sFormFactor = $oJResp.StringOf("devices[i].formFactor")
    $iHeapSize = $oJResp.IntOf("devices[i].heapSize")
    $sImage = $oJResp.StringOf("devices[i].image")
    $sManufacturer = $oJResp.StringOf("devices[i].manufacturer")
    $iMemory = $oJResp.IntOf("devices[i].memory")
    $sModel = $oJResp.StringOf("devices[i].model")
    $sModelId = $oJResp.StringOf("devices[i].modelId")
    $sName = $oJResp.StringOf("devices[i].name")
    $sOs = $oJResp.StringOf("devices[i].os")
    $sPlatform = $oJResp.StringOf("devices[i].platform")
    $sRadio = $oJResp.StringOf("devices[i].radio")
    $iRemoteAccessEnabled = $oJResp.IntOf("devices[i].remoteAccessEnabled")
    $iRemoteDebugEnabled = $oJResp.IntOf("devices[i].remoteDebugEnabled")
    $iHeight = $oJResp.IntOf("devices[i].resolution.height")
    $iWidth = $oJResp.IntOf("devices[i].resolution.width")
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("devices[i].instances")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $sArn = $oJResp.StringOf("devices[i].instances[j].arn")
        $sDeviceArn = $oJResp.StringOf("devices[i].instances[j].deviceArn")
        $sArn = $oJResp.StringOf("devices[i].instances[j].instanceProfile.arn")
        $sDescription = $oJResp.StringOf("devices[i].instances[j].instanceProfile.description")
        $sName = $oJResp.StringOf("devices[i].instances[j].instanceProfile.name")
        $iPackageCleanup = $oJResp.IntOf("devices[i].instances[j].instanceProfile.packageCleanup")
        $iRebootAfterUse = $oJResp.IntOf("devices[i].instances[j].instanceProfile.rebootAfterUse")
        $status = $oJResp.StringOf("devices[i].instances[j].status")
        $sUdid = $oJResp.StringOf("devices[i].instances[j].udid")
        $iK = 0
        $iCount_k = $oJResp.SizeOfArray("devices[i].instances[j].instanceProfile.excludeAppPackagesFromCleanup")
        While $iK < $iCount_k
            $oJResp.K = $iK
            $strVal = $oJResp.StringOf("devices[i].instances[j].instanceProfile.excludeAppPackagesFromCleanup[k]")
            $iK = $iK + 1
        Wend
        $iK = 0
        $iCount_k = $oJResp.SizeOfArray("devices[i].instances[j].labels")
        While $iK < $iCount_k
            $oJResp.K = $iK
            $strVal = $oJResp.StringOf("devices[i].instances[j].labels[k]")
            $iK = $iK + 1
        Wend
        $iJ = $iJ + 1
    Wend
    $i = $i + 1
Wend

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

; {
;   "devices": [
;     {
;       "arn": "string",
;       "availability": "string",
;       "carrier": "string",
;       "cpu": {
;         "architecture": "string",
;         "clock": number,
;         "frequency": "string"
;       },
;       "fleetName": "string",
;       "fleetType": "string",
;       "formFactor": "string",
;       "heapSize": number,
;       "image": "string",
;       "instances": [
;         {
;           "arn": "string",
;           "deviceArn": "string",
;           "instanceProfile": {
;             "arn": "string",
;             "description": "string",
;             "excludeAppPackagesFromCleanup": [
;               "string"
;             ],
;             "name": "string",
;             "packageCleanup": boolean,
;             "rebootAfterUse": boolean
;           },
;           "labels": [
;             "string"
;           ],
;           "status": "string",
;           "udid": "string"
;         }
;       ],
;       "manufacturer": "string",
;       "memory": number,
;       "model": "string",
;       "modelId": "string",
;       "name": "string",
;       "os": "string",
;       "platform": "string",
;       "radio": "string",
;       "remoteAccessEnabled": boolean,
;       "remoteDebugEnabled": boolean,
;       "resolution": {
;         "height": number,
;         "width": number
;       }
;     }
;   ],
;   "nextToken": "string"
; }