PureBasic
PureBasic
Amazon Voice ID - Describe Domain
See more Amazon Voice ID Examples
Describes the specified domain.Chilkat PureBasic Downloads
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkAuthAws.pb"
IncludeFile "CkJsonObject.pb"
IncludeFile "CkRest.pb"
Procedure ChilkatExample()
success.i = 0
; 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
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, "voiceid")
; SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
CkRest::ckSetAuthAws(rest,authAws)
; URL: https://voiceid.us-west-2.amazonaws.com/
bTls.i = 1
port.i = 443
bAutoReconnect.i = 1
; Use the same region as specified above.
success = CkRest::ckConnect(rest,"voiceid.us-west-2.amazonaws.com",port,bTls,bAutoReconnect)
If success <> 1
Debug "ConnectFailReason: " + Str(CkRest::ckConnectFailReason(rest))
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
ProcedureReturn
EndIf
; Use this online tool to generate code from sample JSON:
; Generate Code to Create JSON
; The following JSON is sent in the request body.
; {
; "DomainId": "<domainId>"
; }
;
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckUpdateString(json,"DomainId","<domainId>")
CkRest::ckAddHeader(rest,"Content-Type","application/x-amz-json-1.0")
CkRest::ckAddHeader(rest,"X-Amz-Target","VoiceID.DescribeDomain")
CkRest::ckAddHeader(rest,"Accept-Encoding","identity")
sbRequestBody.i = CkStringBuilder::ckCreate()
If sbRequestBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckEmitSb(json,sbRequestBody)
sbResponseBody.i = CkStringBuilder::ckCreate()
If sbResponseBody.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkRest::ckFullRequestSb(rest,"POST","/",sbRequestBody,sbResponseBody)
If success <> 1
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
CkStringBuilder::ckDispose(sbResponseBody)
ProcedureReturn
EndIf
respStatusCode.i = CkRest::ckResponseStatusCode(rest)
Debug "response status code = " + Str(respStatusCode)
If respStatusCode <> 200
Debug "Response Status Code = " + Str(respStatusCode)
Debug "Response Header:"
Debug CkRest::ckResponseHeader(rest)
Debug "Response Body:"
Debug CkStringBuilder::ckGetAsString(sbResponseBody)
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
CkStringBuilder::ckDispose(sbResponseBody)
ProcedureReturn
EndIf
jsonResponse.i = CkJsonObject::ckCreate()
If jsonResponse.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoadSb(jsonResponse,sbResponseBody)
CkJsonObject::setCkEmitCompact(jsonResponse, 0)
Debug CkJsonObject::ckEmit(jsonResponse)
; If successful, the response status code is 200, and the response syntax:
; {
; "Domain": {
; "Arn": "string",
; "CreatedAt": number,
; "Description": "string",
; "DomainId": "string",
; "DomainStatus": "string",
; "Name": "string",
; "ServerSideEncryptionConfiguration": {
; "KmsKeyId": "string"
; },
; "UpdatedAt": number
; }
; }
DomainArn.s = CkJsonObject::ckStringOf(jsonResponse,"Domain.Arn")
DomainCreatedAt.i = CkJsonObject::ckIntOf(jsonResponse,"Domain.CreatedAt")
DomainDescription.s = CkJsonObject::ckStringOf(jsonResponse,"Domain.Description")
DomainDomainId.s = CkJsonObject::ckStringOf(jsonResponse,"Domain.DomainId")
DomainDomainStatus.s = CkJsonObject::ckStringOf(jsonResponse,"Domain.DomainStatus")
DomainName.s = CkJsonObject::ckStringOf(jsonResponse,"Domain.Name")
DomainServerSideEncryptionConfigurationKmsKeyId.s = CkJsonObject::ckStringOf(jsonResponse,"Domain.ServerSideEncryptionConfiguration.KmsKeyId")
DomainUpdatedAt.i = CkJsonObject::ckIntOf(jsonResponse,"Domain.UpdatedAt")
CkRest::ckDispose(rest)
CkAuthAws::ckDispose(authAws)
CkJsonObject::ckDispose(json)
CkStringBuilder::ckDispose(sbRequestBody)
CkStringBuilder::ckDispose(sbResponseBody)
CkJsonObject::ckDispose(jsonResponse)
ProcedureReturn
EndProcedure