PollForJobs Foxpro Example
LOCAL loRest
LOCAL lnSuccess
LOCAL loAuthAws
LOCAL loJson
LOCAL loSbRequestBody
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJResp
LOCAL lcAccountId
LOCAL lcV_String
LOCAL lcCategory
LOCAL lcOwner
LOCAL lcProvider
LOCAL lcVersion
LOCAL lcAccessKeyId
LOCAL lcSecretAccessKey
LOCAL lcSessionToken
LOCAL lcContinuationToken
LOCAL lcId
LOCAL lcV_Type
LOCAL lcActionExecutionId
LOCAL lcName
LOCAL lcPipelineArn
LOCAL lcPipelineExecutionId
LOCAL lcPipelineName
LOCAL lcStageName
LOCAL lcId
LOCAL lcNonce
LOCAL j
LOCAL lnCount_j
LOCAL lcBucketName
LOCAL lcObjectKey
LOCAL lcLocationType
LOCAL lcName
LOCAL lcRevision
LOCAL lcS3LocationBucketName
LOCAL lcS3LocationObjectKey
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 = "codepipeline"
* SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
loRest.SetAuthAws(loAuthAws)
* URL: https://codepipeline.us-west-2.amazonaws.com/
* Use the same region as specified above.
lnSuccess = loRest.Connect("codepipeline.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("actionTypeId.category","string")
loJson.UpdateString("actionTypeId.owner","string")
loJson.UpdateString("actionTypeId.provider","string")
loJson.UpdateString("actionTypeId.version","string")
loJson.UpdateInt("maxBatchSize",123)
loJson.UpdateString("queryParam.string","string")
* The JSON request body created by the above code:
* {
* "actionTypeId": {
* "category": "string",
* "owner": "string",
* "provider": "string",
* "version": "string"
* },
* "maxBatchSize": number,
* "queryParam": {
* "string": "string"
* }
* }
loRest.AddHeader("Content-Type","application/x-amz-json-1.1")
loRest.AddHeader("X-Amz-Target","CodePipeline_20150709.PollForJobs")
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
i = 0
lnCount_i = loJResp.SizeOfArray("jobs")
DO WHILE i < lnCount_i
loJResp.I = i
lcAccountId = loJResp.StringOf("jobs[i].accountId")
lcV_String = loJResp.StringOf("jobs[i].data.actionConfiguration.configuration.string")
lcCategory = loJResp.StringOf("jobs[i].data.actionTypeId.category")
lcOwner = loJResp.StringOf("jobs[i].data.actionTypeId.owner")
lcProvider = loJResp.StringOf("jobs[i].data.actionTypeId.provider")
lcVersion = loJResp.StringOf("jobs[i].data.actionTypeId.version")
lcAccessKeyId = loJResp.StringOf("jobs[i].data.artifactCredentials.accessKeyId")
lcSecretAccessKey = loJResp.StringOf("jobs[i].data.artifactCredentials.secretAccessKey")
lcSessionToken = loJResp.StringOf("jobs[i].data.artifactCredentials.sessionToken")
lcContinuationToken = loJResp.StringOf("jobs[i].data.continuationToken")
lcId = loJResp.StringOf("jobs[i].data.encryptionKey.id")
lcV_Type = loJResp.StringOf("jobs[i].data.encryptionKey.type")
lcActionExecutionId = loJResp.StringOf("jobs[i].data.pipelineContext.action.actionExecutionId")
lcName = loJResp.StringOf("jobs[i].data.pipelineContext.action.name")
lcPipelineArn = loJResp.StringOf("jobs[i].data.pipelineContext.pipelineArn")
lcPipelineExecutionId = loJResp.StringOf("jobs[i].data.pipelineContext.pipelineExecutionId")
lcPipelineName = loJResp.StringOf("jobs[i].data.pipelineContext.pipelineName")
lcStageName = loJResp.StringOf("jobs[i].data.pipelineContext.stage.name")
lcId = loJResp.StringOf("jobs[i].id")
lcNonce = loJResp.StringOf("jobs[i].nonce")
j = 0
lnCount_j = loJResp.SizeOfArray("jobs[i].data.inputArtifacts")
DO WHILE j < lnCount_j
loJResp.J = j
lcBucketName = loJResp.StringOf("jobs[i].data.inputArtifacts[j].location.s3Location.bucketName")
lcObjectKey = loJResp.StringOf("jobs[i].data.inputArtifacts[j].location.s3Location.objectKey")
lcLocationType = loJResp.StringOf("jobs[i].data.inputArtifacts[j].location.type")
lcName = loJResp.StringOf("jobs[i].data.inputArtifacts[j].name")
lcRevision = loJResp.StringOf("jobs[i].data.inputArtifacts[j].revision")
j = j + 1
ENDDO
j = 0
lnCount_j = loJResp.SizeOfArray("jobs[i].data.outputArtifacts")
DO WHILE j < lnCount_j
loJResp.J = j
lcS3LocationBucketName = loJResp.StringOf("jobs[i].data.outputArtifacts[j].location.s3Location.bucketName")
lcS3LocationObjectKey = loJResp.StringOf("jobs[i].data.outputArtifacts[j].location.s3Location.objectKey")
lcLocationType = loJResp.StringOf("jobs[i].data.outputArtifacts[j].location.type")
lcName = loJResp.StringOf("jobs[i].data.outputArtifacts[j].name")
lcRevision = loJResp.StringOf("jobs[i].data.outputArtifacts[j].revision")
j = j + 1
ENDDO
i = i + 1
ENDDO
* A sample JSON response body parsed by the above code:
* {
* "jobs": [
* {
* "accountId": "string",
* "data": {
* "actionConfiguration": {
* "configuration": {
* "string": "string"
* }
* },
* "actionTypeId": {
* "category": "string",
* "owner": "string",
* "provider": "string",
* "version": "string"
* },
* "artifactCredentials": {
* "accessKeyId": "string",
* "secretAccessKey": "string",
* "sessionToken": "string"
* },
* "continuationToken": "string",
* "encryptionKey": {
* "id": "string",
* "type": "string"
* },
* "inputArtifacts": [
* {
* "location": {
* "s3Location": {
* "bucketName": "string",
* "objectKey": "string"
* },
* "type": "string"
* },
* "name": "string",
* "revision": "string"
* }
* ],
* "outputArtifacts": [
* {
* "location": {
* "s3Location": {
* "bucketName": "string",
* "objectKey": "string"
* },
* "type": "string"
* },
* "name": "string",
* "revision": "string"
* }
* ],
* "pipelineContext": {
* "action": {
* "actionExecutionId": "string",
* "name": "string"
* },
* "pipelineArn": "string",
* "pipelineExecutionId": "string",
* "pipelineName": "string",
* "stage": {
* "name": "string"
* }
* }
* },
* "id": "string",
* "nonce": "string"
* }
* ]
* }
RELEASE loRest
RELEASE loAuthAws
RELEASE loJson
RELEASE loSbRequestBody
RELEASE loSbResponseBody
RELEASE loJResp