Chilkat Online Tools

ListUniqueProblems TCL Example

AWS Device Farm

load ./chilkat.dll

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

set rest [new_CkRest]

set authAws [new_CkAuthAws]

CkAuthAws_put_AccessKey $authAws "AWS_ACCESS_KEY"
CkAuthAws_put_SecretKey $authAws "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.)
CkAuthAws_put_Region $authAws "us-west-2"
CkAuthAws_put_ServiceName $authAws "devicefarm"
# SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest_SetAuthAws $rest $authAws

# URL: https://devicefarm.us-west-2.amazonaws.com/
# Use the same region as specified above.
set success [CkRest_Connect $rest "devicefarm.us-west-2.amazonaws.com" 443 1 1]
if {$success != 1} then {
    puts "ConnectFailReason: [CkRest_get_ConnectFailReason $rest]"
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    exit
}

# 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

set json [new_CkJsonObject]

CkJsonObject_UpdateString $json "arn" "string"
CkJsonObject_UpdateString $json "nextToken" "string"

# The JSON request body created by the above code:

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

CkRest_AddHeader $rest "Content-Type" "application/x-amz-json-1.1"
CkRest_AddHeader $rest "X-Amz-Target" "DeviceFarm_20150623.ListUniqueProblems"

set sbRequestBody [new_CkStringBuilder]

CkJsonObject_EmitSb $json $sbRequestBody
set sbResponseBody [new_CkStringBuilder]

set success [CkRest_FullRequestSb $rest "POST" "/" $sbRequestBody $sbResponseBody]
if {$success != 1} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbRequestBody
    delete_CkStringBuilder $sbResponseBody
    exit
}

set respStatusCode [CkRest_get_ResponseStatusCode $rest]
puts "response status code = $respStatusCode"
if {$respStatusCode != 200} then {
    puts "Response Header:"
    puts [CkRest_responseHeader $rest]
    puts "Response Body:"
    puts [CkStringBuilder_getAsString $sbResponseBody]
    delete_CkRest $rest
    delete_CkAuthAws $authAws
    delete_CkJsonObject $json
    delete_CkStringBuilder $sbRequestBody
    delete_CkStringBuilder $sbResponseBody
    exit
}

set jResp [new_CkJsonObject]

CkJsonObject_LoadSb $jResp $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

# json1 is a CkJsonObject

set nextToken [CkJsonObject_stringOf $jResp "nextToken"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "uniqueProblems.string"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set message [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].message"]
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "uniqueProblems.string[i].problems"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set Arn [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.arn"]
        set Availability [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.availability"]
        set Carrier [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.carrier"]
        set Architecture [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.cpu.architecture"]
        set Clock [CkJsonObject_IntOf $jResp "uniqueProblems.string[i].problems[j].device.cpu.clock"]
        set Frequency [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.cpu.frequency"]
        set FleetName [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.fleetName"]
        set FleetType [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.fleetType"]
        set FormFactor [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.formFactor"]
        set HeapSize [CkJsonObject_IntOf $jResp "uniqueProblems.string[i].problems[j].device.heapSize"]
        set Image [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.image"]
        set Manufacturer [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.manufacturer"]
        set Memory [CkJsonObject_IntOf $jResp "uniqueProblems.string[i].problems[j].device.memory"]
        set Model [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.model"]
        set ModelId [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.modelId"]
        set Name [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.name"]
        set Os [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.os"]
        set Platform [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.platform"]
        set Radio [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.radio"]
        set RemoteAccessEnabled [CkJsonObject_IntOf $jResp "uniqueProblems.string[i].problems[j].device.remoteAccessEnabled"]
        set RemoteDebugEnabled [CkJsonObject_IntOf $jResp "uniqueProblems.string[i].problems[j].device.remoteDebugEnabled"]
        set Height [CkJsonObject_IntOf $jResp "uniqueProblems.string[i].problems[j].device.resolution.height"]
        set Width [CkJsonObject_IntOf $jResp "uniqueProblems.string[i].problems[j].device.resolution.width"]
        set jobArn [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].job.arn"]
        set jobName [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].job.name"]
        set message [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].message"]
        set result [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].result"]
        set runArn [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].run.arn"]
        set runName [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].run.name"]
        set suiteArn [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].suite.arn"]
        set suiteName [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].suite.name"]
        set testArn [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].test.arn"]
        set testName [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].test.name"]
        set k 0
        set count_k [CkJsonObject_SizeOfArray $jResp "uniqueProblems.string[i].problems[j].device.instances"]
        while {$k < $count_k} {
            CkJsonObject_put_K $jResp $k
            set arn [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.instances[k].arn"]
            set deviceArn [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.instances[k].deviceArn"]
            set instanceProfileArn [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.instances[k].instanceProfile.arn"]
            set Description [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.instances[k].instanceProfile.description"]
            set instanceProfileName [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.instances[k].instanceProfile.name"]
            set PackageCleanup [CkJsonObject_IntOf $jResp "uniqueProblems.string[i].problems[j].device.instances[k].instanceProfile.packageCleanup"]
            set RebootAfterUse [CkJsonObject_IntOf $jResp "uniqueProblems.string[i].problems[j].device.instances[k].instanceProfile.rebootAfterUse"]
            set status [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.instances[k].status"]
            set udid [CkJsonObject_stringOf $jResp "uniqueProblems.string[i].problems[j].device.instances[k].udid"]

            set json1 [CkJsonObject_ObjectOf $jResp "uniqueProblems.string[i].problems[j].device.instances[k]"]
            set i1 0
            set count_i1 [CkJsonObject_SizeOfArray $json1 "instanceProfile.excludeAppPackagesFromCleanup"]
            while {$i1 < $count_i1} {
                CkJsonObject_put_I $json1 $i1
                set strVal [CkJsonObject_stringOf $json1 "instanceProfile.excludeAppPackagesFromCleanup[i]"]
                set i1 [expr $i1 + 1]
            }
            delete_CkJsonObject $json1

            set json1 [CkJsonObject_ObjectOf $jResp "uniqueProblems.string[i].problems[j].device.instances[k]"]
            set i1 0
            set count_i1 [CkJsonObject_SizeOfArray $json1 "labels"]
            while {$i1 < $count_i1} {
                CkJsonObject_put_I $json1 $i1
                set strVal [CkJsonObject_stringOf $json1 "labels[i]"]
                set i1 [expr $i1 + 1]
            }
            delete_CkJsonObject $json1

            set k [expr $k + 1]
        }
        set j [expr $j + 1]
    }
    set i [expr $i + 1]
}

# 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"
#             }
#           }
#         ]
#       }
#     ]
#   }
# }

delete_CkRest $rest
delete_CkAuthAws $authAws
delete_CkJsonObject $json
delete_CkStringBuilder $sbRequestBody
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp