Chilkat Online Tools

GetThirdPartyJobDetails Foxpro Example

AWS CodePipeline

LOCAL loRest
LOCAL lnSuccess
LOCAL loAuthAws
LOCAL loJson
LOCAL loSbRequestBody
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJResp
LOCAL lcBucketName
LOCAL lcObjectKey
LOCAL lcLocationType
LOCAL lcName
LOCAL lcRevision
LOCAL lcS3LocationBucketName
LOCAL lcS3LocationObjectKey
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 lcJobDetailsId
LOCAL lcNonce
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("clientToken","string")
loJson.UpdateString("jobId","string")

* The JSON request body created by the above code:

* {
*   "clientToken": "string",
*   "jobId": "string"
* }

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

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

lcV_String = loJResp.StringOf("jobDetails.data.actionConfiguration.configuration.string")
lcCategory = loJResp.StringOf("jobDetails.data.actionTypeId.category")
lcOwner = loJResp.StringOf("jobDetails.data.actionTypeId.owner")
lcProvider = loJResp.StringOf("jobDetails.data.actionTypeId.provider")
lcVersion = loJResp.StringOf("jobDetails.data.actionTypeId.version")
lcAccessKeyId = loJResp.StringOf("jobDetails.data.artifactCredentials.accessKeyId")
lcSecretAccessKey = loJResp.StringOf("jobDetails.data.artifactCredentials.secretAccessKey")
lcSessionToken = loJResp.StringOf("jobDetails.data.artifactCredentials.sessionToken")
lcContinuationToken = loJResp.StringOf("jobDetails.data.continuationToken")
lcId = loJResp.StringOf("jobDetails.data.encryptionKey.id")
lcV_Type = loJResp.StringOf("jobDetails.data.encryptionKey.type")
lcActionExecutionId = loJResp.StringOf("jobDetails.data.pipelineContext.action.actionExecutionId")
lcName = loJResp.StringOf("jobDetails.data.pipelineContext.action.name")
lcPipelineArn = loJResp.StringOf("jobDetails.data.pipelineContext.pipelineArn")
lcPipelineExecutionId = loJResp.StringOf("jobDetails.data.pipelineContext.pipelineExecutionId")
lcPipelineName = loJResp.StringOf("jobDetails.data.pipelineContext.pipelineName")
lcStageName = loJResp.StringOf("jobDetails.data.pipelineContext.stage.name")
lcJobDetailsId = loJResp.StringOf("jobDetails.id")
lcNonce = loJResp.StringOf("jobDetails.nonce")
i = 0
lnCount_i = loJResp.SizeOfArray("jobDetails.data.inputArtifacts")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcBucketName = loJResp.StringOf("jobDetails.data.inputArtifacts[i].location.s3Location.bucketName")
    lcObjectKey = loJResp.StringOf("jobDetails.data.inputArtifacts[i].location.s3Location.objectKey")
    lcLocationType = loJResp.StringOf("jobDetails.data.inputArtifacts[i].location.type")
    lcName = loJResp.StringOf("jobDetails.data.inputArtifacts[i].name")
    lcRevision = loJResp.StringOf("jobDetails.data.inputArtifacts[i].revision")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("jobDetails.data.outputArtifacts")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcS3LocationBucketName = loJResp.StringOf("jobDetails.data.outputArtifacts[i].location.s3Location.bucketName")
    lcS3LocationObjectKey = loJResp.StringOf("jobDetails.data.outputArtifacts[i].location.s3Location.objectKey")
    lcLocationType = loJResp.StringOf("jobDetails.data.outputArtifacts[i].location.type")
    lcName = loJResp.StringOf("jobDetails.data.outputArtifacts[i].name")
    lcRevision = loJResp.StringOf("jobDetails.data.outputArtifacts[i].revision")
    i = i + 1
ENDDO

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

* {
*   "jobDetails": {
*     "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