Chilkat Online Tools

ListUniqueProblems Foxpro Example

AWS Device Farm

LOCAL loRest
LOCAL lnSuccess
LOCAL loAuthAws
LOCAL loJson
LOCAL loSbRequestBody
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJResp
LOCAL lcMessage
LOCAL j
LOCAL lnCount_j
LOCAL lcArn
LOCAL lcAvailability
LOCAL lcCarrier
LOCAL lcArchitecture
LOCAL lnClock
LOCAL lcFrequency
LOCAL lcFleetName
LOCAL lcFleetType
LOCAL lcFormFactor
LOCAL lnHeapSize
LOCAL lcImage
LOCAL lcManufacturer
LOCAL lnMemory
LOCAL lcModel
LOCAL lcModelId
LOCAL lcName
LOCAL lcOs
LOCAL lcPlatform
LOCAL lcRadio
LOCAL lnRemoteAccessEnabled
LOCAL lnRemoteDebugEnabled
LOCAL lnHeight
LOCAL lnWidth
LOCAL lcJobArn
LOCAL lcJobName
LOCAL lcResult
LOCAL lcRunArn
LOCAL lcRunName
LOCAL lcSuiteArn
LOCAL lcSuiteName
LOCAL lcTestArn
LOCAL lcTestName
LOCAL k
LOCAL lnCount_k
LOCAL lcArn
LOCAL lcDeviceArn
LOCAL lcInstanceProfileArn
LOCAL lcDescription
LOCAL lcInstanceProfileName
LOCAL lnPackageCleanup
LOCAL lnRebootAfterUse
LOCAL lcStatus
LOCAL lcUdid
LOCAL loJson1
LOCAL lnI1
LOCAL lnCount_i1
LOCAL lcStrVal
LOCAL lcNextToken
LOCAL i
LOCAL lnCount_i

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

loRest = CreateObject('Chilkat_9_5_0.Rest')

loAuthAws = CreateObject('Chilkat_9_5_0.AuthAws')
loAuthAws.AccessKey = "AWS_ACCESS_KEY"
loAuthAws.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.)
loAuthAws.Region = "us-west-2"
loAuthAws.ServiceName = "devicefarm"
* SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
loRest.SetAuthAws(loAuthAws)

* URL: https://devicefarm.us-west-2.amazonaws.com/
* Use the same region as specified above.
lnSuccess = loRest.Connect("devicefarm.us-west-2.amazonaws.com",443,1,1)
IF (lnSuccess <> 1) THEN
    ? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loAuthAws
    CANCEL
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

loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.UpdateString("arn","string")
loJson.UpdateString("nextToken","string")

* The JSON request body created by the above code:

* {
*   "arn": "string",
*   "nextToken": "string"
* }

loRest.AddHeader("Content-Type","application/x-amz-json-1.1")
loRest.AddHeader("X-Amz-Target","DeviceFarm_20150623.ListUniqueProblems")

loSbRequestBody = CreateObject('Chilkat_9_5_0.StringBuilder')
loJson.EmitSb(loSbRequestBody)
loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestSb("POST","/",loSbRequestBody,loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loAuthAws
    RELEASE loJson
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

lnRespStatusCode = loRest.ResponseStatusCode
? "response status code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode <> 200) THEN
    ? "Response Header:"
    ? loRest.ResponseHeader
    ? "Response Body:"
    ? loSbResponseBody.GetAsString()
    RELEASE loRest
    RELEASE loAuthAws
    RELEASE loJson
    RELEASE loSbRequestBody
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJResp = CreateObject('Chilkat_9_5_0.JsonObject')
loJResp.LoadSb(loSbResponseBody)

* 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

lcNextToken = loJResp.StringOf("nextToken")
i = 0
lnCount_i = loJResp.SizeOfArray("uniqueProblems.string")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcMessage = loJResp.StringOf("uniqueProblems.string[i].message")
    j = 0
    lnCount_j = loJResp.SizeOfArray("uniqueProblems.string[i].problems")
    DO WHILE j < lnCount_j
        loJResp.J = j
        lcArn = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.arn")
        lcAvailability = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.availability")
        lcCarrier = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.carrier")
        lcArchitecture = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.cpu.architecture")
        lnClock = loJResp.IntOf("uniqueProblems.string[i].problems[j].device.cpu.clock")
        lcFrequency = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.cpu.frequency")
        lcFleetName = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.fleetName")
        lcFleetType = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.fleetType")
        lcFormFactor = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.formFactor")
        lnHeapSize = loJResp.IntOf("uniqueProblems.string[i].problems[j].device.heapSize")
        lcImage = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.image")
        lcManufacturer = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.manufacturer")
        lnMemory = loJResp.IntOf("uniqueProblems.string[i].problems[j].device.memory")
        lcModel = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.model")
        lcModelId = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.modelId")
        lcName = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.name")
        lcOs = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.os")
        lcPlatform = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.platform")
        lcRadio = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.radio")
        lnRemoteAccessEnabled = loJResp.IntOf("uniqueProblems.string[i].problems[j].device.remoteAccessEnabled")
        lnRemoteDebugEnabled = loJResp.IntOf("uniqueProblems.string[i].problems[j].device.remoteDebugEnabled")
        lnHeight = loJResp.IntOf("uniqueProblems.string[i].problems[j].device.resolution.height")
        lnWidth = loJResp.IntOf("uniqueProblems.string[i].problems[j].device.resolution.width")
        lcJobArn = loJResp.StringOf("uniqueProblems.string[i].problems[j].job.arn")
        lcJobName = loJResp.StringOf("uniqueProblems.string[i].problems[j].job.name")
        lcMessage = loJResp.StringOf("uniqueProblems.string[i].problems[j].message")
        lcResult = loJResp.StringOf("uniqueProblems.string[i].problems[j].result")
        lcRunArn = loJResp.StringOf("uniqueProblems.string[i].problems[j].run.arn")
        lcRunName = loJResp.StringOf("uniqueProblems.string[i].problems[j].run.name")
        lcSuiteArn = loJResp.StringOf("uniqueProblems.string[i].problems[j].suite.arn")
        lcSuiteName = loJResp.StringOf("uniqueProblems.string[i].problems[j].suite.name")
        lcTestArn = loJResp.StringOf("uniqueProblems.string[i].problems[j].test.arn")
        lcTestName = loJResp.StringOf("uniqueProblems.string[i].problems[j].test.name")
        k = 0
        lnCount_k = loJResp.SizeOfArray("uniqueProblems.string[i].problems[j].device.instances")
        DO WHILE k < lnCount_k
            loJResp.K = k
            lcArn = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.instances[k].arn")
            lcDeviceArn = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.instances[k].deviceArn")
            lcInstanceProfileArn = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.instances[k].instanceProfile.arn")
            lcDescription = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.instances[k].instanceProfile.description")
            lcInstanceProfileName = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.instances[k].instanceProfile.name")
            lnPackageCleanup = loJResp.IntOf("uniqueProblems.string[i].problems[j].device.instances[k].instanceProfile.packageCleanup")
            lnRebootAfterUse = loJResp.IntOf("uniqueProblems.string[i].problems[j].device.instances[k].instanceProfile.rebootAfterUse")
            lcStatus = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.instances[k].status")
            lcUdid = loJResp.StringOf("uniqueProblems.string[i].problems[j].device.instances[k].udid")

            loJson1 = loJResp.ObjectOf("uniqueProblems.string[i].problems[j].device.instances[k]")
            lnI1 = 0
            lnCount_i1 = loJson1.SizeOfArray("instanceProfile.excludeAppPackagesFromCleanup")
            DO WHILE lnI1 < lnCount_i1
                loJson1.I = lnI1
                lcStrVal = loJson1.StringOf("instanceProfile.excludeAppPackagesFromCleanup[i]")
                lnI1 = lnI1 + 1
            ENDDO
            RELEASE loJson1

            loJson1 = loJResp.ObjectOf("uniqueProblems.string[i].problems[j].device.instances[k]")
            lnI1 = 0
            lnCount_i1 = loJson1.SizeOfArray("labels")
            DO WHILE lnI1 < lnCount_i1
                loJson1.I = lnI1
                lcStrVal = loJson1.StringOf("labels[i]")
                lnI1 = lnI1 + 1
            ENDDO
            RELEASE loJson1
            k = k + 1
        ENDDO
        j = j + 1
    ENDDO
    i = i + 1
ENDDO

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

* {
*   "nextToken": "string",
*   "uniqueProblems": {
*     "string": [
*       {
*         "message": "string",
*         "problems": [
*           {
*             "device": {
*               "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
*               }
*             },
*             "job": {
*               "arn": "string",
*               "name": "string"
*             },
*             "message": "string",
*             "result": "string",
*             "run": {
*               "arn": "string",
*               "name": "string"
*             },
*             "suite": {
*               "arn": "string",
*               "name": "string"
*             },
*             "test": {
*               "arn": "string",
*               "name": "string"
*             }
*           }
*         ]
*       }
*     ]
*   }
* }

RELEASE loRest
RELEASE loAuthAws
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loSbResponseBody
RELEASE loJResp