Chilkat Online Tools

ListApps PureBasic Example

Amplify

IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkRest.pb"
IncludeFile "CkAuthAws.pb"

Procedure ChilkatExample()

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

    rest.i = CkRest::ckCreate()
    If rest.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    authAws.i = CkAuthAws::ckCreate()
    If authAws.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkAuthAws::setCkAccessKey(authAws, "AWS_ACCESS_KEY")
    CkAuthAws::setCkSecretKey(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::setCkRegion(authAws, "us-west-2")
    CkAuthAws::setCkServiceName(authAws, "amplify")
    ; SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
    CkRest::ckSetAuthAws(rest,authAws)

    ; URL: https://amplify.us-west-2.amazonaws.com/
    ; Use the same region as specified above.
    success = CkRest::ckConnect(rest,"amplify.us-west-2.amazonaws.com",443,1,1)
    If success <> 1
        Debug "ConnectFailReason: " + Str(CkRest::ckConnectFailReason(rest))
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        CkAuthAws::ckDispose(authAws)
        ProcedureReturn
    EndIf

    CkRest::ckAddHeader(rest,"Content-Type","application/x-amz-json-1.1")
    CkRest::ckAddHeader(rest,"X-Amz-Target","ListApps")

    sbResponseBody.i = CkStringBuilder::ckCreate()
    If sbResponseBody.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkRest::ckFullRequestNoBodySb(rest,"GET","/apps",sbResponseBody)
    If success <> 1
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        CkAuthAws::ckDispose(authAws)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    respStatusCode.i = CkRest::ckResponseStatusCode(rest)
    Debug "response status code = " + Str(respStatusCode)
    If respStatusCode <> 200
        Debug "Response Header:"
        Debug CkRest::ckResponseHeader(rest)
        Debug "Response Body:"
        Debug CkStringBuilder::ckGetAsString(sbResponseBody)
        CkRest::ckDispose(rest)
        CkAuthAws::ckDispose(authAws)
        CkStringBuilder::ckDispose(sbResponseBody)
        ProcedureReturn
    EndIf

    jResp.i = CkJsonObject::ckCreate()
    If jResp.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(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

    appArn.s
    appId.s
    BasicAuthCredentials.s
    BuildSpec.s
    EnableAutoBuild.i
    EnableBasicAuth.i
    EnablePerformanceMode.i
    EnablePullRequestPreview.i
    v_String.s
    Framework.s
    PullRequestEnvironmentName.s
    Stage.s
    basicAuthCredentials.s
    buildSpec.s
    createTime.i
    customHeaders.s
    defaultDomain.s
    description.s
    enableAutoBranchCreation.i
    enableBasicAuth.i
    enableBranchAutoBuild.i
    enableBranchAutoDeletion.i
    environmentVariablesString.s
    iamServiceRoleArn.s
    name.s
    platform.s
    BranchName.s
    LastDeployTime.i
    Status.s
    ThumbnailUrl.s
    repository.s
    repositoryCloneMethod.s
    tagsString.s
    updateTime.i
    j.i
    count_j.i
    strVal.s
    condition.s
    source.s
    status.s
    target.s

    nextToken.s = CkJsonObject::ckStringOf(jResp,"nextToken")
    i.i = 0
    count_i.i = CkJsonObject::ckSizeOfArray(jResp,"apps")
    While i < count_i
        CkJsonObject::setCkI(jResp, i)
        appArn = CkJsonObject::ckStringOf(jResp,"apps[i].appArn")
        appId = CkJsonObject::ckStringOf(jResp,"apps[i].appId")
        BasicAuthCredentials = CkJsonObject::ckStringOf(jResp,"apps[i].autoBranchCreationConfig.basicAuthCredentials")
        BuildSpec = CkJsonObject::ckStringOf(jResp,"apps[i].autoBranchCreationConfig.buildSpec")
        EnableAutoBuild = CkJsonObject::ckIntOf(jResp,"apps[i].autoBranchCreationConfig.enableAutoBuild")
        EnableBasicAuth = CkJsonObject::ckIntOf(jResp,"apps[i].autoBranchCreationConfig.enableBasicAuth")
        EnablePerformanceMode = CkJsonObject::ckIntOf(jResp,"apps[i].autoBranchCreationConfig.enablePerformanceMode")
        EnablePullRequestPreview = CkJsonObject::ckIntOf(jResp,"apps[i].autoBranchCreationConfig.enablePullRequestPreview")
        v_String = CkJsonObject::ckStringOf(jResp,"apps[i].autoBranchCreationConfig.environmentVariables.string")
        Framework = CkJsonObject::ckStringOf(jResp,"apps[i].autoBranchCreationConfig.framework")
        PullRequestEnvironmentName = CkJsonObject::ckStringOf(jResp,"apps[i].autoBranchCreationConfig.pullRequestEnvironmentName")
        Stage = CkJsonObject::ckStringOf(jResp,"apps[i].autoBranchCreationConfig.stage")
        basicAuthCredentials = CkJsonObject::ckStringOf(jResp,"apps[i].basicAuthCredentials")
        buildSpec = CkJsonObject::ckStringOf(jResp,"apps[i].buildSpec")
        createTime = CkJsonObject::ckIntOf(jResp,"apps[i].createTime")
        customHeaders = CkJsonObject::ckStringOf(jResp,"apps[i].customHeaders")
        defaultDomain = CkJsonObject::ckStringOf(jResp,"apps[i].defaultDomain")
        description = CkJsonObject::ckStringOf(jResp,"apps[i].description")
        enableAutoBranchCreation = CkJsonObject::ckIntOf(jResp,"apps[i].enableAutoBranchCreation")
        enableBasicAuth = CkJsonObject::ckIntOf(jResp,"apps[i].enableBasicAuth")
        enableBranchAutoBuild = CkJsonObject::ckIntOf(jResp,"apps[i].enableBranchAutoBuild")
        enableBranchAutoDeletion = CkJsonObject::ckIntOf(jResp,"apps[i].enableBranchAutoDeletion")
        environmentVariablesString = CkJsonObject::ckStringOf(jResp,"apps[i].environmentVariables.string")
        iamServiceRoleArn = CkJsonObject::ckStringOf(jResp,"apps[i].iamServiceRoleArn")
        name = CkJsonObject::ckStringOf(jResp,"apps[i].name")
        platform = CkJsonObject::ckStringOf(jResp,"apps[i].platform")
        BranchName = CkJsonObject::ckStringOf(jResp,"apps[i].productionBranch.branchName")
        LastDeployTime = CkJsonObject::ckIntOf(jResp,"apps[i].productionBranch.lastDeployTime")
        Status = CkJsonObject::ckStringOf(jResp,"apps[i].productionBranch.status")
        ThumbnailUrl = CkJsonObject::ckStringOf(jResp,"apps[i].productionBranch.thumbnailUrl")
        repository = CkJsonObject::ckStringOf(jResp,"apps[i].repository")
        repositoryCloneMethod = CkJsonObject::ckStringOf(jResp,"apps[i].repositoryCloneMethod")
        tagsString = CkJsonObject::ckStringOf(jResp,"apps[i].tags.string")
        updateTime = CkJsonObject::ckIntOf(jResp,"apps[i].updateTime")
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"apps[i].autoBranchCreationPatterns")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            strVal = CkJsonObject::ckStringOf(jResp,"apps[i].autoBranchCreationPatterns[j]")
            j = j + 1
        Wend
        j = 0
        count_j = CkJsonObject::ckSizeOfArray(jResp,"apps[i].customRules")
        While j < count_j
            CkJsonObject::setCkJ(jResp, j)
            condition = CkJsonObject::ckStringOf(jResp,"apps[i].customRules[j].condition")
            source = CkJsonObject::ckStringOf(jResp,"apps[i].customRules[j].source")
            status = CkJsonObject::ckStringOf(jResp,"apps[i].customRules[j].status")
            target = CkJsonObject::ckStringOf(jResp,"apps[i].customRules[j].target")
            j = j + 1
        Wend
        i = i + 1
    Wend

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

    ; {
    ;   "apps": [
    ;     {
    ;       "appArn": "string",
    ;       "appId": "string",
    ;       "autoBranchCreationConfig": {
    ;         "basicAuthCredentials": "string",
    ;         "buildSpec": "string",
    ;         "enableAutoBuild": boolean,
    ;         "enableBasicAuth": boolean,
    ;         "enablePerformanceMode": boolean,
    ;         "enablePullRequestPreview": boolean,
    ;         "environmentVariables": {
    ;           "string": "string"
    ;         },
    ;         "framework": "string",
    ;         "pullRequestEnvironmentName": "string",
    ;         "stage": "string"
    ;       },
    ;       "autoBranchCreationPatterns": [
    ;         "string"
    ;       ],
    ;       "basicAuthCredentials": "string",
    ;       "buildSpec": "string",
    ;       "createTime": number,
    ;       "customHeaders": "string",
    ;       "customRules": [
    ;         {
    ;           "condition": "string",
    ;           "source": "string",
    ;           "status": "string",
    ;           "target": "string"
    ;         }
    ;       ],
    ;       "defaultDomain": "string",
    ;       "description": "string",
    ;       "enableAutoBranchCreation": boolean,
    ;       "enableBasicAuth": boolean,
    ;       "enableBranchAutoBuild": boolean,
    ;       "enableBranchAutoDeletion": boolean,
    ;       "environmentVariables": {
    ;         "string": "string"
    ;       },
    ;       "iamServiceRoleArn": "string",
    ;       "name": "string",
    ;       "platform": "string",
    ;       "productionBranch": {
    ;         "branchName": "string",
    ;         "lastDeployTime": number,
    ;         "status": "string",
    ;         "thumbnailUrl": "string"
    ;       },
    ;       "repository": "string",
    ;       "repositoryCloneMethod": "string",
    ;       "tags": {
    ;         "string": "string"
    ;       },
    ;       "updateTime": number
    ;     }
    ;   ],
    ;   "nextToken": "string"
    ; }


    CkRest::ckDispose(rest)
    CkAuthAws::ckDispose(authAws)
    CkStringBuilder::ckDispose(sbResponseBody)
    CkJsonObject::ckDispose(jResp)


    ProcedureReturn
EndProcedure