Skip to content

Instantly share code, notes, and snippets.

@commuterjoy
Created May 29, 2013 14:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save commuterjoy/5670640 to your computer and use it in GitHub Desktop.
Save commuterjoy/5670640 to your computer and use it in GitHub Desktop.
Generate a report via the SiteCatalyst / Omniture API via Ruby & CURL
{
"reportDescription":{
"reportSuiteID":"<report-suite-id>",
"date":"2013-05-11",
"dateFrom":"",
"dateTo":"",
"dateGranularity":"hour",
"metrics":[
{
"id":"event37"
}
],
"sortBy":"",
"elements":[
{
"id":"evar37",
"search":{
"type":"AND",
"keywords":[
"social-fb",
"social-twitter",
"social-gplus"
]
}
}
],
"locale":"",
"segment_id":""
},
"validate":true
}
require 'time'
require 'digest/md5'
require 'digest/sha1'
require 'base64'
url = 'https://api.omniture.com/admin/1.3/rest/?method=Report.QueueTrended'
username = '<username>'
password = '<password>'
nonce = Array.new(10){ rand(0x100000000) }.pack('I*')
nonce_base64 = [nonce].pack("m").chomp
created = Time.now.utc.iso8601
pd = [Digest::SHA1.digest(nonce + created + password)].pack("m").chomp
auth = 'UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"' % [username, pd, nonce_base64, created]
cmd = "curl -sH 'Content-Type: application/json' -H 'X-WSSE: %s' -d @body %s" % [auth, url]
puts cmd
puts `#{cmd}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment