Skip to content
Browse files

Management API v 2.4

Quick hack to upgrade management API to GData v 2.4.  Main change is the response is XML only
  • Loading branch information...
1 parent 6c03b02 commit f27f2f498cf1c23f08e4241d63c8be83ab885a8f @KentonWhite committed Jan 16, 2012
Showing with 13 additions and 7 deletions.
  1. +1 −1 lib/garb.rb
  2. +4 −1 lib/garb/management/feed.rb
  3. +6 −3 lib/garb/report_response.rb
  4. +2 −2 lib/garb/request/data.rb
View
2 lib/garb.rb
@@ -68,7 +68,7 @@ def from_google_analytics(thing)
alias :from_ga :from_google_analytics
def parse_properties(entry)
- Hash[entry['dxp$property'].map {|p| [Garb.from_ga(p['name']),p['value']]}]
+ Hash[entry['property'].map {|p| [Garb.from_ga(p['name']),p['value']]}]
end
def parse_link(entry, rel)
View
5 lib/garb/management/feed.rb
@@ -1,6 +1,8 @@
module Garb
module Management
class Feed
+ require 'xmlsimple'
+
BASE_URL = "https://www.google.com/analytics/feeds/datasources/ga"
attr_reader :request
@@ -10,7 +12,8 @@ def initialize(session, path)
end
def parsed_response
- @parsed_response ||= JSON.parse(response.body)
+ # @parsed_response ||= JSON.parse(response.body)
+ @parsed_response ||= {'feed' => XmlSimple.xml_in(response.body)}
end
def entries
View
9 lib/garb/report_response.rb
@@ -1,6 +1,8 @@
module Garb
class ReportResponse
- KEYS = ['dxp$metric', 'dxp$dimension']
+ require 'xmlsimple'
+
+ KEYS = ['metric', 'dimension']
def initialize(response_body, instance_klass = OpenStruct)
@data = response_body
@@ -30,7 +32,7 @@ def parse
end
def entries
- feed? ? [parsed_data['feed']['entry']].flatten.compact : []
+ feed? ? [parsed_data['feed']['aggregates']].flatten.compact : []
end
def parse_total_results
@@ -42,7 +44,8 @@ def parse_sampled_flag
end
def parsed_data
- @parsed_data ||= JSON.parse(@data)
+ # @parsed_data ||= JSON.parse(@data)
+ @parsed_data ||= {'feed' => XmlSimple.xml_in(@data)}
end
def feed?
View
4 lib/garb/request/data.rb
@@ -16,13 +16,13 @@ def parameters
end
def query_string
- parameters.merge!("alt" => format)
+ # parameters.merge!("alt" => format)
parameter_list = @parameters.map {|k,v| "#{k}=#{v}" }
parameter_list.empty? ? '' : "?#{parameter_list.join('&')}"
end
def format
- @format ||= "json" # TODO Support other formats?
+ # @format ||= "json" # TODO Support other formats?
end
def uri

0 comments on commit f27f2f4

Please sign in to comment.
Something went wrong with that request. Please try again.