Skip to content

Instantly share code, notes, and snippets.

@m-gagne
Created February 2, 2012 20:25
Show Gist options
  • Save m-gagne/1725555 to your computer and use it in GitHub Desktop.
Save m-gagne/1725555 to your computer and use it in GitHub Desktop.
RareLogic Query API - Pages Report Sample
require 'oauth'
# A simple Pages pivoted by Category report for the current week
query_json = <<EOS
{
"report": {
"report_type": "standard",
"pivots_attributes": [
{
"family": "content",
"name": "category",
"label": "Category"
},
{
"family": "content",
"name": "page",
"label": "Page"
}
],
"columns_attributes": [
{
"attribute_family": "entity",
"attribute_name": "uuid",
"title": "People",
"aggregator": "COUNT",
"quantifier": "DISTINCT",
"sort": "DESC"
},
{
"attribute_family": "content",
"attribute_name": "page",
"title": "Page Views",
"aggregator": "COUNT",
"sort": "DESC"
}
],
"segment_attributes": {
"name": "All Customers"
}
},
"date_range": {
"type": "this week"
}
}
EOS
# Create the oAuth consumer
consumer = OAuth::Consumer.new( "_APP_KEY_", "_APP_SECRET_" )
# Create a request and get the response
response = consumer.request(
:post,
"https://api.rare.io/profiles/_PROFILE_ID_/query.csv",
nil,
{},
query_json,
{ 'Content-Type' => 'application/json' }
)
# response contains the result in JSON, CSV or XML
puts response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment