(Swift 2) SugarCRM Logout
Demonstrates how to logout of a session.
func chilkatTest() {
let rest = CkoRest()
var success: Bool
success = rest.Connect("your.site.domain", port: 443, tls: true, autoReconnect: true)
if success != true {
print("\(rest.LastErrorText)")
return
}
rest.AddHeader("Cache-Control", value: "no-cache")
rest.AddHeader("OAuth-Token", value: "<access_token>")
let sbReq = CkoStringBuilder()
let sbJson = CkoStringBuilder()
success = rest.FullRequestSb("POST", uriPath: "/rest/v10/oauth2/logout", requestBody: sbReq, responseBody: sbJson)
if success != true {
print("\(rest.LastErrorText)")
return
}
if rest.ResponseStatusCode.intValue != 200 {
print("Received error response code: \(rest.ResponseStatusCode.intValue)")
print("Response body:")
print("\(sbJson.GetAsString())")
return
}
let json = CkoJsonObject()
json.LoadSb(sbJson)
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
var success: Bool
success = json.BoolOf("success")
// A sample JSON response body that is parsed by the above code:
// {
// "success": true
// }
print("Example Completed.")
}
|