Chilkat Online Tools

GetExperiment Foxpro Example

AWS Fault Injection Simulator

LOCAL loRest
LOCAL lnSuccess
LOCAL loAuthAws
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJResp
LOCAL lcStrVal
LOCAL lcSource
LOCAL lcValue
LOCAL lcPath
LOCAL j
LOCAL lnCount_j
LOCAL lcActionId
LOCAL lcDescription
LOCAL lnEndTime
LOCAL lcV_String
LOCAL lnStartTime
LOCAL lcReason
LOCAL lcStatus
LOCAL lcTargetsString
LOCAL lnCreationTime
LOCAL lnExperimentEndTime
LOCAL lcExperimentTemplateId
LOCAL lcId
LOCAL lcLogGroupArn
LOCAL lnLogSchemaVersion
LOCAL lcBucketName
LOCAL lcPrefix
LOCAL lcRoleArn
LOCAL lnExperimentStartTime
LOCAL lcStateReason
LOCAL lcStateStatus
LOCAL lcTagsString
LOCAL lcParametersString
LOCAL lcResourceTagsString
LOCAL lcResourceType
LOCAL lcSelectionMode
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 = "fis"
* SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
loRest.SetAuthAws(loAuthAws)

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

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

loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestNoBodySb("GET","/experiments/{id}",loSbResponseBody)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loAuthAws
    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 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

lcActionId = loJResp.StringOf("experiment.actions.string.actionId")
lcDescription = loJResp.StringOf("experiment.actions.string.description")
lnEndTime = loJResp.IntOf("experiment.actions.string.endTime")
lcV_String = loJResp.StringOf("experiment.actions.string.parameters.string")
lnStartTime = loJResp.IntOf("experiment.actions.string.startTime")
lcReason = loJResp.StringOf("experiment.actions.string.state.reason")
lcStatus = loJResp.StringOf("experiment.actions.string.state.status")
lcTargetsString = loJResp.StringOf("experiment.actions.string.targets.string")
lnCreationTime = loJResp.IntOf("experiment.creationTime")
lnExperimentEndTime = loJResp.IntOf("experiment.endTime")
lcExperimentTemplateId = loJResp.StringOf("experiment.experimentTemplateId")
lcId = loJResp.StringOf("experiment.id")
lcLogGroupArn = loJResp.StringOf("experiment.logConfiguration.cloudWatchLogsConfiguration.logGroupArn")
lnLogSchemaVersion = loJResp.IntOf("experiment.logConfiguration.logSchemaVersion")
lcBucketName = loJResp.StringOf("experiment.logConfiguration.s3Configuration.bucketName")
lcPrefix = loJResp.StringOf("experiment.logConfiguration.s3Configuration.prefix")
lcRoleArn = loJResp.StringOf("experiment.roleArn")
lnExperimentStartTime = loJResp.IntOf("experiment.startTime")
lcStateReason = loJResp.StringOf("experiment.state.reason")
lcStateStatus = loJResp.StringOf("experiment.state.status")
lcTagsString = loJResp.StringOf("experiment.tags.string")
lcParametersString = loJResp.StringOf("experiment.targets.string.parameters.string")
lcResourceTagsString = loJResp.StringOf("experiment.targets.string.resourceTags.string")
lcResourceType = loJResp.StringOf("experiment.targets.string.resourceType")
lcSelectionMode = loJResp.StringOf("experiment.targets.string.selectionMode")
i = 0
lnCount_i = loJResp.SizeOfArray("experiment.actions.string.startAfter")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcStrVal = loJResp.StringOf("experiment.actions.string.startAfter[i]")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("experiment.stopConditions")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcSource = loJResp.StringOf("experiment.stopConditions[i].source")
    lcValue = loJResp.StringOf("experiment.stopConditions[i].value")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("experiment.targets.string.filters")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcPath = loJResp.StringOf("experiment.targets.string.filters[i].path")
    j = 0
    lnCount_j = loJResp.SizeOfArray("experiment.targets.string.filters[i].values")
    DO WHILE j < lnCount_j
        loJResp.J = j
        lcStrVal = loJResp.StringOf("experiment.targets.string.filters[i].values[j]")
        j = j + 1
    ENDDO
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("experiment.targets.string.resourceArns")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcStrVal = loJResp.StringOf("experiment.targets.string.resourceArns[i]")
    i = i + 1
ENDDO

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

* {
*   "experiment": {
*     "actions": {
*       "string": {
*         "actionId": "string",
*         "description": "string",
*         "endTime": number,
*         "parameters": {
*           "string": "string"
*         },
*         "startAfter": [
*           "string"
*         ],
*         "startTime": number,
*         "state": {
*           "reason": "string",
*           "status": "string"
*         },
*         "targets": {
*           "string": "string"
*         }
*       }
*     },
*     "creationTime": number,
*     "endTime": number,
*     "experimentTemplateId": "string",
*     "id": "string",
*     "logConfiguration": {
*       "cloudWatchLogsConfiguration": {
*         "logGroupArn": "string"
*       },
*       "logSchemaVersion": number,
*       "s3Configuration": {
*         "bucketName": "string",
*         "prefix": "string"
*       }
*     },
*     "roleArn": "string",
*     "startTime": number,
*     "state": {
*       "reason": "string",
*       "status": "string"
*     },
*     "stopConditions": [
*       {
*         "source": "string",
*         "value": "string"
*       }
*     ],
*     "tags": {
*       "string": "string"
*     },
*     "targets": {
*       "string": {
*         "filters": [
*           {
*             "path": "string",
*             "values": [
*               "string"
*             ]
*           }
*         ],
*         "parameters": {
*           "string": "string"
*         },
*         "resourceArns": [
*           "string"
*         ],
*         "resourceTags": {
*           "string": "string"
*         },
*         "resourceType": "string",
*         "selectionMode": "string"
*       }
*     }
*   }
* }

RELEASE loRest
RELEASE loAuthAws
RELEASE loSbResponseBody
RELEASE loJResp