Swift
Swift
Adobe Analytics Reporting API (1.4)
See more HTTP Misc Examples
Demonstrates a simple POST of JSON to the Adobe Analytics Reporting API (v1.4)Chilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// In this example, replace "rsid" with your report suite id, and update the URL to use the correct endpoint
var url: String? = "https://api.omniture.com/admin/1.4/rest/?method=Report.Queue"
let json = CkoJsonObject()!
json.updateString(jsonPath: "reportDescription.reportSuiteID", value: "rsid")
json.updateString(jsonPath: "reportDescription.dateGranularity", value: "hour")
let http = CkoHttp()!
let dt = CkoDateTime()!
dt.setFromCurrentSystemTime()
var timecreated: String? = dt.get(asTimestamp: false)
let prng = CkoPrng()!
var nonce: String? = prng.genRandom(numBytes: 12, encoding: "hex")
var secret: String? = "SECRET"
let sb = CkoStringBuilder()!
sb.append(value: nonce)
sb.append(value: timecreated)
sb.append(value: secret)
let crypt = CkoCrypt2()!
crypt.hashAlgorithm = "sha1"
crypt.encodingMode = "base64"
var digest: String? = crypt.hashStringENC(str: sb.getAsString())
let sbNonce = CkoStringBuilder()!
sbNonce.append(value: nonce)
sbNonce.encode(encoding: "base64")
sb.clear()
sb.append(value: "UsernameToken Username=\"USERNAME\", PasswordDigest=\"")
sb.append(value: digest)
sb.append(value: "\", Nonce=\"")
sb.append(value: sbNonce.getAsString())
sb.append(value: "\", Created=\"")
sb.append(value: timecreated)
sb.append(value: "\"")
print("\(sb.getAsString()!)")
http.setRequestHeader(name: "X-WSSE", value: sb.getAsString())
let resp = CkoHttpResponse()!
success = http.httpJson(verb: "POST", url: url, json: json, contentType: "text/json", response: resp)
if success == false {
print("\(http.lastErrorText!)")
return
}
print("Http Status code: \(resp.statusCode.intValue)")
print("JSON response:")
print("\(resp.bodyStr!)")
}