GetPipelineState Swift3 Example
func chilkatTest() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let rest = CkoRest()!
var success: Bool
let authAws = CkoAuthAws()!
authAws.accessKey = "AWS_ACCESS_KEY"
authAws.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.)
authAws.region = "us-west-2"
authAws.serviceName = "codepipeline"
// SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
rest.setAuthAws(authAws)
// URL: https://codepipeline.us-west-2.amazonaws.com/
// Use the same region as specified above.
success = rest.connect("codepipeline.us-west-2.amazonaws.com", port: 443, tls: true, autoReconnect: true)
if success != true {
print("ConnectFailReason: \(rest.connectFailReason.intValue)")
print("\(rest.lastErrorText!)")
return
}
// 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
let json = CkoJsonObject()!
json.update("name", value: "string")
// The JSON request body created by the above code:
// {
// "name": "string"
// }
rest.addHeader("Content-Type", value: "application/x-amz-json-1.1")
rest.addHeader("X-Amz-Target", value: "CodePipeline_20150709.GetPipelineState")
let sbRequestBody = CkoStringBuilder()!
json.emitSb(sbRequestBody)
let sbResponseBody = CkoStringBuilder()!
success = rest.fullRequestSb("POST", uriPath: "/", requestBody: sbRequestBody, responseBody: sbResponseBody)
if success != true {
print("\(rest.lastErrorText!)")
return
}
var respStatusCode: Int = rest.responseStatusCode.intValue
print("response status code = \(respStatusCode)")
if respStatusCode != 200 {
print("Response Header:")
print("\(rest.responseHeader!)")
print("Response Body:")
print("\(sbResponseBody.getAsString()!)")
return
}
let jResp = CkoJsonObject()!
jResp.loadSb(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
var PipelineExecutionId: String?
var Status: String?
var DisabledReason: String?
var Enabled: Int
var LastChangedAt: Int
var LastChangedBy: String?
var latestExecutionPipelineExecutionId: String?
var latestExecutionStatus: String?
var stageName: String?
var j: Int
var count_j: Int
var actionName: String?
var Created: Int
var RevisionChangeId: String?
var RevisionId: String?
var entityUrl: String?
var ActionExecutionId: String?
var Code: String?
var Message: String?
var ExternalExecutionId: String?
var ExternalExecutionUrl: String?
var LastStatusChange: Int
var LastUpdatedBy: String?
var PercentComplete: Int
var Summary: String?
var Token: String?
var revisionUrl: String?
var created: Int = jResp.int(of: "created").intValue
var pipelineName: String? = jResp.string(of: "pipelineName")
var pipelineVersion: Int = jResp.int(of: "pipelineVersion").intValue
var updated: Int = jResp.int(of: "updated").intValue
var i: Int = 0
var count_i: Int = jResp.size(ofArray: "stageStates").intValue
while i < count_i {
jResp.i = i
PipelineExecutionId = jResp.string(of: "stageStates[i].inboundExecution.pipelineExecutionId")
Status = jResp.string(of: "stageStates[i].inboundExecution.status")
DisabledReason = jResp.string(of: "stageStates[i].inboundTransitionState.disabledReason")
Enabled = jResp.int(of: "stageStates[i].inboundTransitionState.enabled").intValue
LastChangedAt = jResp.int(of: "stageStates[i].inboundTransitionState.lastChangedAt").intValue
LastChangedBy = jResp.string(of: "stageStates[i].inboundTransitionState.lastChangedBy")
latestExecutionPipelineExecutionId = jResp.string(of: "stageStates[i].latestExecution.pipelineExecutionId")
latestExecutionStatus = jResp.string(of: "stageStates[i].latestExecution.status")
stageName = jResp.string(of: "stageStates[i].stageName")
j = 0
count_j = jResp.size(ofArray: "stageStates[i].actionStates").intValue
while j < count_j {
jResp.j = j
actionName = jResp.string(of: "stageStates[i].actionStates[j].actionName")
Created = jResp.int(of: "stageStates[i].actionStates[j].currentRevision.created").intValue
RevisionChangeId = jResp.string(of: "stageStates[i].actionStates[j].currentRevision.revisionChangeId")
RevisionId = jResp.string(of: "stageStates[i].actionStates[j].currentRevision.revisionId")
entityUrl = jResp.string(of: "stageStates[i].actionStates[j].entityUrl")
ActionExecutionId = jResp.string(of: "stageStates[i].actionStates[j].latestExecution.actionExecutionId")
Code = jResp.string(of: "stageStates[i].actionStates[j].latestExecution.errorDetails.code")
Message = jResp.string(of: "stageStates[i].actionStates[j].latestExecution.errorDetails.message")
ExternalExecutionId = jResp.string(of: "stageStates[i].actionStates[j].latestExecution.externalExecutionId")
ExternalExecutionUrl = jResp.string(of: "stageStates[i].actionStates[j].latestExecution.externalExecutionUrl")
LastStatusChange = jResp.int(of: "stageStates[i].actionStates[j].latestExecution.lastStatusChange").intValue
LastUpdatedBy = jResp.string(of: "stageStates[i].actionStates[j].latestExecution.lastUpdatedBy")
PercentComplete = jResp.int(of: "stageStates[i].actionStates[j].latestExecution.percentComplete").intValue
latestExecutionStatus = jResp.string(of: "stageStates[i].actionStates[j].latestExecution.status")
Summary = jResp.string(of: "stageStates[i].actionStates[j].latestExecution.summary")
Token = jResp.string(of: "stageStates[i].actionStates[j].latestExecution.token")
revisionUrl = jResp.string(of: "stageStates[i].actionStates[j].revisionUrl")
j = j + 1
}
i = i + 1
}
// A sample JSON response body parsed by the above code:
// {
// "created": number,
// "pipelineName": "string",
// "pipelineVersion": number,
// "stageStates": [
// {
// "actionStates": [
// {
// "actionName": "string",
// "currentRevision": {
// "created": number,
// "revisionChangeId": "string",
// "revisionId": "string"
// },
// "entityUrl": "string",
// "latestExecution": {
// "actionExecutionId": "string",
// "errorDetails": {
// "code": "string",
// "message": "string"
// },
// "externalExecutionId": "string",
// "externalExecutionUrl": "string",
// "lastStatusChange": number,
// "lastUpdatedBy": "string",
// "percentComplete": number,
// "status": "string",
// "summary": "string",
// "token": "string"
// },
// "revisionUrl": "string"
// }
// ],
// "inboundExecution": {
// "pipelineExecutionId": "string",
// "status": "string"
// },
// "inboundTransitionState": {
// "disabledReason": "string",
// "enabled": boolean,
// "lastChangedAt": number,
// "lastChangedBy": "string"
// },
// "latestExecution": {
// "pipelineExecutionId": "string",
// "status": "string"
// },
// "stageName": "string"
// }
// ],
// "updated": number
// }
}