ListRuns SQL Server Example
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @sTmp0 nvarchar(max)
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @rest int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Rest', @rest OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
DECLARE @authAws int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.AuthAws', @authAws OUT
EXEC sp_OASetProperty @authAws, 'AccessKey', 'AWS_ACCESS_KEY'
EXEC sp_OASetProperty @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.)
EXEC sp_OASetProperty @authAws, 'Region', 'us-west-2'
EXEC sp_OASetProperty @authAws, 'ServiceName', 'devicefarm'
-- SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
EXEC sp_OAMethod @rest, 'SetAuthAws', @success OUT, @authAws
-- URL: https://devicefarm.us-west-2.amazonaws.com/
-- Use the same region as specified above.
EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'devicefarm.us-west-2.amazonaws.com', 443, 1, 1
IF @success <> 1
BEGIN
EXEC sp_OAGetProperty @rest, 'ConnectFailReason', @iTmp0 OUT
PRINT 'ConnectFailReason: ' + @iTmp0
EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @authAws
RETURN
END
-- 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
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'arn', 'string'
EXEC sp_OAMethod @json, 'UpdateString', @success OUT, 'nextToken', 'string'
-- The JSON request body created by the above code:
-- {
-- "arn": "string",
-- "nextToken": "string"
-- }
EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'Content-Type', 'application/x-amz-json-1.1'
EXEC sp_OAMethod @rest, 'AddHeader', @success OUT, 'X-Amz-Target', 'DeviceFarm_20150623.ListRuns'
DECLARE @sbRequestBody int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbRequestBody OUT
EXEC sp_OAMethod @json, 'EmitSb', @success OUT, @sbRequestBody
DECLARE @sbResponseBody int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbResponseBody OUT
EXEC sp_OAMethod @rest, 'FullRequestSb', @success OUT, 'POST', '/', @sbRequestBody, @sbResponseBody
IF @success <> 1
BEGIN
EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @authAws
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
EXEC @hr = sp_OADestroy @sbResponseBody
RETURN
END
DECLARE @respStatusCode int
EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @respStatusCode OUT
PRINT 'response status code = ' + @respStatusCode
IF @respStatusCode <> 200
BEGIN
PRINT 'Response Header:'
EXEC sp_OAGetProperty @rest, 'ResponseHeader', @sTmp0 OUT
PRINT @sTmp0
PRINT 'Response Body:'
EXEC sp_OAMethod @sbResponseBody, 'GetAsString', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @authAws
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
EXEC @hr = sp_OADestroy @sbResponseBody
RETURN
END
DECLARE @jResp int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @jResp OUT
EXEC sp_OAMethod @jResp, 'LoadSb', @success OUT, @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
DECLARE @appUpload nvarchar(max)
DECLARE @arn nvarchar(max)
DECLARE @billingMethod nvarchar(max)
DECLARE @completedJobs int
DECLARE @Errored int
DECLARE @Failed int
DECLARE @Passed int
DECLARE @Skipped int
DECLARE @Stopped int
DECLARE @Total int
DECLARE @Warned int
DECLARE @created int
DECLARE @Metered int
DECLARE @deviceMinutesTotal int
DECLARE @Unmetered int
DECLARE @devicePoolArn nvarchar(max)
DECLARE @MatchedDevicesCount int
DECLARE @MaxDevices int
DECLARE @eventCount int
DECLARE @jobTimeoutMinutes int
DECLARE @locale nvarchar(max)
DECLARE @Latitude int
DECLARE @Longitude int
DECLARE @message nvarchar(max)
DECLARE @name nvarchar(max)
DECLARE @Arn nvarchar(max)
DECLARE @Description nvarchar(max)
DECLARE @DownlinkBandwidthBits int
DECLARE @DownlinkDelayMs int
DECLARE @DownlinkJitterMs int
DECLARE @DownlinkLossPercent int
DECLARE @Name nvarchar(max)
DECLARE @v_Type nvarchar(max)
DECLARE @UplinkBandwidthBits int
DECLARE @UplinkDelayMs int
DECLARE @UplinkJitterMs int
DECLARE @UplinkLossPercent int
DECLARE @parsingResultUrl nvarchar(max)
DECLARE @platform nvarchar(max)
DECLARE @Bluetooth int
DECLARE @Gps int
DECLARE @Nfc int
DECLARE @Wifi int
DECLARE @result nvarchar(max)
DECLARE @resultCode nvarchar(max)
DECLARE @seed int
DECLARE @skipAppResign int
DECLARE @started int
DECLARE @status nvarchar(max)
DECLARE @stopped int
DECLARE @testSpecArn nvarchar(max)
DECLARE @totalJobs int
DECLARE @v_type nvarchar(max)
DECLARE @webUrl nvarchar(max)
DECLARE @j int
DECLARE @count_j int
DECLARE @strVal nvarchar(max)
DECLARE @attribute nvarchar(max)
DECLARE @operator nvarchar(max)
DECLARE @k int
DECLARE @count_k int
DECLARE @nextToken nvarchar(max)
EXEC sp_OAMethod @jResp, 'StringOf', @nextToken OUT, 'nextToken'
DECLARE @i int
SELECT @i = 0
DECLARE @count_i int
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_i OUT, 'runs'
WHILE @i < @count_i
BEGIN
EXEC sp_OASetProperty @jResp, 'I', @i
EXEC sp_OAMethod @jResp, 'StringOf', @appUpload OUT, 'runs[i].appUpload'
EXEC sp_OAMethod @jResp, 'StringOf', @arn OUT, 'runs[i].arn'
EXEC sp_OAMethod @jResp, 'StringOf', @billingMethod OUT, 'runs[i].billingMethod'
EXEC sp_OAMethod @jResp, 'IntOf', @completedJobs OUT, 'runs[i].completedJobs'
EXEC sp_OAMethod @jResp, 'IntOf', @Errored OUT, 'runs[i].counters.errored'
EXEC sp_OAMethod @jResp, 'IntOf', @Failed OUT, 'runs[i].counters.failed'
EXEC sp_OAMethod @jResp, 'IntOf', @Passed OUT, 'runs[i].counters.passed'
EXEC sp_OAMethod @jResp, 'IntOf', @Skipped OUT, 'runs[i].counters.skipped'
EXEC sp_OAMethod @jResp, 'IntOf', @Stopped OUT, 'runs[i].counters.stopped'
EXEC sp_OAMethod @jResp, 'IntOf', @Total OUT, 'runs[i].counters.total'
EXEC sp_OAMethod @jResp, 'IntOf', @Warned OUT, 'runs[i].counters.warned'
EXEC sp_OAMethod @jResp, 'IntOf', @created OUT, 'runs[i].created'
EXEC sp_OAMethod @jResp, 'IntOf', @Metered OUT, 'runs[i].deviceMinutes.metered'
EXEC sp_OAMethod @jResp, 'IntOf', @deviceMinutesTotal OUT, 'runs[i].deviceMinutes.total'
EXEC sp_OAMethod @jResp, 'IntOf', @Unmetered OUT, 'runs[i].deviceMinutes.unmetered'
EXEC sp_OAMethod @jResp, 'StringOf', @devicePoolArn OUT, 'runs[i].devicePoolArn'
EXEC sp_OAMethod @jResp, 'IntOf', @MatchedDevicesCount OUT, 'runs[i].deviceSelectionResult.matchedDevicesCount'
EXEC sp_OAMethod @jResp, 'IntOf', @MaxDevices OUT, 'runs[i].deviceSelectionResult.maxDevices'
EXEC sp_OAMethod @jResp, 'IntOf', @eventCount OUT, 'runs[i].eventCount'
EXEC sp_OAMethod @jResp, 'IntOf', @jobTimeoutMinutes OUT, 'runs[i].jobTimeoutMinutes'
EXEC sp_OAMethod @jResp, 'StringOf', @locale OUT, 'runs[i].locale'
EXEC sp_OAMethod @jResp, 'IntOf', @Latitude OUT, 'runs[i].location.latitude'
EXEC sp_OAMethod @jResp, 'IntOf', @Longitude OUT, 'runs[i].location.longitude'
EXEC sp_OAMethod @jResp, 'StringOf', @message OUT, 'runs[i].message'
EXEC sp_OAMethod @jResp, 'StringOf', @name OUT, 'runs[i].name'
EXEC sp_OAMethod @jResp, 'StringOf', @Arn OUT, 'runs[i].networkProfile.arn'
EXEC sp_OAMethod @jResp, 'StringOf', @Description OUT, 'runs[i].networkProfile.description'
EXEC sp_OAMethod @jResp, 'IntOf', @DownlinkBandwidthBits OUT, 'runs[i].networkProfile.downlinkBandwidthBits'
EXEC sp_OAMethod @jResp, 'IntOf', @DownlinkDelayMs OUT, 'runs[i].networkProfile.downlinkDelayMs'
EXEC sp_OAMethod @jResp, 'IntOf', @DownlinkJitterMs OUT, 'runs[i].networkProfile.downlinkJitterMs'
EXEC sp_OAMethod @jResp, 'IntOf', @DownlinkLossPercent OUT, 'runs[i].networkProfile.downlinkLossPercent'
EXEC sp_OAMethod @jResp, 'StringOf', @Name OUT, 'runs[i].networkProfile.name'
EXEC sp_OAMethod @jResp, 'StringOf', @v_Type OUT, 'runs[i].networkProfile.type'
EXEC sp_OAMethod @jResp, 'IntOf', @UplinkBandwidthBits OUT, 'runs[i].networkProfile.uplinkBandwidthBits'
EXEC sp_OAMethod @jResp, 'IntOf', @UplinkDelayMs OUT, 'runs[i].networkProfile.uplinkDelayMs'
EXEC sp_OAMethod @jResp, 'IntOf', @UplinkJitterMs OUT, 'runs[i].networkProfile.uplinkJitterMs'
EXEC sp_OAMethod @jResp, 'IntOf', @UplinkLossPercent OUT, 'runs[i].networkProfile.uplinkLossPercent'
EXEC sp_OAMethod @jResp, 'StringOf', @parsingResultUrl OUT, 'runs[i].parsingResultUrl'
EXEC sp_OAMethod @jResp, 'StringOf', @platform OUT, 'runs[i].platform'
EXEC sp_OAMethod @jResp, 'IntOf', @Bluetooth OUT, 'runs[i].radios.bluetooth'
EXEC sp_OAMethod @jResp, 'IntOf', @Gps OUT, 'runs[i].radios.gps'
EXEC sp_OAMethod @jResp, 'IntOf', @Nfc OUT, 'runs[i].radios.nfc'
EXEC sp_OAMethod @jResp, 'IntOf', @Wifi OUT, 'runs[i].radios.wifi'
EXEC sp_OAMethod @jResp, 'StringOf', @result OUT, 'runs[i].result'
EXEC sp_OAMethod @jResp, 'StringOf', @resultCode OUT, 'runs[i].resultCode'
EXEC sp_OAMethod @jResp, 'IntOf', @seed OUT, 'runs[i].seed'
EXEC sp_OAMethod @jResp, 'IntOf', @skipAppResign OUT, 'runs[i].skipAppResign'
EXEC sp_OAMethod @jResp, 'IntOf', @started OUT, 'runs[i].started'
EXEC sp_OAMethod @jResp, 'StringOf', @status OUT, 'runs[i].status'
EXEC sp_OAMethod @jResp, 'IntOf', @stopped OUT, 'runs[i].stopped'
EXEC sp_OAMethod @jResp, 'StringOf', @testSpecArn OUT, 'runs[i].testSpecArn'
EXEC sp_OAMethod @jResp, 'IntOf', @totalJobs OUT, 'runs[i].totalJobs'
EXEC sp_OAMethod @jResp, 'StringOf', @v_type OUT, 'runs[i].type'
EXEC sp_OAMethod @jResp, 'StringOf', @webUrl OUT, 'runs[i].webUrl'
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'runs[i].customerArtifactPaths.androidPaths'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'runs[i].customerArtifactPaths.androidPaths[j]'
SELECT @j = @j + 1
END
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'runs[i].customerArtifactPaths.deviceHostPaths'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'runs[i].customerArtifactPaths.deviceHostPaths[j]'
SELECT @j = @j + 1
END
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'runs[i].customerArtifactPaths.iosPaths'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'runs[i].customerArtifactPaths.iosPaths[j]'
SELECT @j = @j + 1
END
SELECT @j = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_j OUT, 'runs[i].deviceSelectionResult.filters'
WHILE @j < @count_j
BEGIN
EXEC sp_OASetProperty @jResp, 'J', @j
EXEC sp_OAMethod @jResp, 'StringOf', @attribute OUT, 'runs[i].deviceSelectionResult.filters[j].attribute'
EXEC sp_OAMethod @jResp, 'StringOf', @operator OUT, 'runs[i].deviceSelectionResult.filters[j].operator'
SELECT @k = 0
EXEC sp_OAMethod @jResp, 'SizeOfArray', @count_k OUT, 'runs[i].deviceSelectionResult.filters[j].values'
WHILE @k < @count_k
BEGIN
EXEC sp_OASetProperty @jResp, 'K', @k
EXEC sp_OAMethod @jResp, 'StringOf', @strVal OUT, 'runs[i].deviceSelectionResult.filters[j].values[k]'
SELECT @k = @k + 1
END
SELECT @j = @j + 1
END
SELECT @i = @i + 1
END
-- A sample JSON response body parsed by the above code:
-- {
-- "nextToken": "string",
-- "runs": [
-- {
-- "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"
-- }
-- ]
-- }
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @authAws
EXEC @hr = sp_OADestroy @json
EXEC @hr = sp_OADestroy @sbRequestBody
EXEC @hr = sp_OADestroy @sbResponseBody
EXEC @hr = sp_OADestroy @jResp
END
GO