Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Various changes to key namespaces to support JSON correctly.

  • Loading branch information...
commit 3e47e6aebfdb823e6cf992d780073630b2bc1f5b 1 parent 45db83c
James Cook authored
View
2  lib/garb.rb
@@ -66,7 +66,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['dxp$property'].map {|p| [Garb.from_ga(p['name']),p['value']]}]
end
def parse_link(entry, rel)
View
4 lib/garb/report_response.rb
@@ -1,6 +1,6 @@
module Garb
class ReportResponse
- KEYS = ['dxp:metric', 'dxp:dimension']
+ KEYS = ['dxp$metric', 'dxp$dimension']
def initialize(response_body, instance_klass = OpenStruct)
@data = response_body
@@ -38,7 +38,7 @@ def parse_total_results
end
def parse_sampled_flag
- feed? ? (parsed_data['feed']['dxp:containsSampledData'] == 'true') : false
+ feed? ? (parsed_data['feed']['dxp$containsSampledData'] == 'true') : false
end
def parsed_data
View
6 lib/garb/request/data.rb
@@ -11,8 +11,12 @@ def initialize(session, base_url, parameters={})
@parameters = parameters
end
+ def parameters
+ @parameters ||= {}
+ end
+
def query_string
- @parameters.merge!("alt" => format) if @parameters.keys.any?
+ parameters.merge!("alt" => format)
parameter_list = @parameters.map {|k,v| "#{k}=#{v}" }
parameter_list.empty? ? '' : "?#{parameter_list.join('&')}"
end
View
2  test/fixtures/profile_feed.json
@@ -1 +1 @@
-{"feed":{"id":"http://www.google.com/analytics/feeds/accounts/blah@gmail.com","updated":"2010-05-06T19:27:28.028-07:00","title":"Profile list for blah@gmail.com","link":{"rel":"self","type":"application/atom+xml","href":"https://www.google.com/analytics/feeds/accounts/default"},"author":{"name":"Google Analytics"},"generator":"Google Analytics","openSearch:totalResults":"2","openSearch:startIndex":"1","openSearch:itemsPerPage":"2","dxp:segment":[{"dxp:definition":null,"id":"gaid::-1","name":"All Visits"},{"dxp:definition":"ga:visitorType==New Visitor","id":"gaid::-2","name":"New Visitors"},{"dxp:definition":"ga:medium==cpa,ga:medium==cpc,ga:medium==cpm,ga:medium==cpp,ga:medium==cpv,ga:medium==ppc","id":"gaid::-3","name":"Paid Search Traffic"},{"dxp:definition":"ga:city!=New York","id":"gaid::0","name":"Not New York"}],"entry":[{"id":"http://www.google.com/analytics/feeds/accounts/ga:12345","updated":"2008-07-21T14:05:57.000-07:00","title":"Historical","link":{"rel":"alternate","type":"text/html","href":"http://www.google.com/analytics"},"ga:goal":[{"ga:destination":{"caseSensitive":"false","expression":"/blog.html","matchType":"head","step1Required":"false"},"active":"true","name":"Read Blog","number":"1","value":"10.0"},{"ga:destination":{"caseSensitive":"false","expression":"/support.html","matchType":"head","step1Required":"false"},"active":"true","name":"Go for Support","number":"2","value":"5.0"},{"ga:destination":{"ga:step":{"name":"Contact Form Page","number":"1","path":"/contact.html"},"caseSensitive":"false","expression":"/contact-submit","matchType":"exact","step1Required":"true"},"active":"true","name":"Contact Form Submission","number":"3","value":"100.0"},{"ga:destination":{"caseSensitive":"false","expression":"/newsletter-submit","matchType":"exact","step1Required":"false"},"active":"true","name":"Newsletter Form Submission","number":"4","value":"25.0"}],"dxp:property":[{"name":"ga:accountId","value":"1111"},{"name":"ga:accountName","value":"Blog Beta"},{"name":"ga:profileId","value":"1212"},{"name":"ga:webPropertyId","value":"UA-1111-1"},{"name":"ga:currency","value":"USD"},{"name":"ga:timezone","value":"America/New_York"}],"dxp:tableId":"ga:12345","gd:etag":"W/\"CUcHSXs8fip7I2A9WxBUFUg.\"","gd:kind":"analytics#account"},{"id":"http://www.google.com/analytics/feeds/accounts/ga:12346","updated":"2008-11-24T11:51:07.000-08:00","title":"Presently","link":{"rel":"alternate","type":"text/html","href":"http://www.google.com/analytics"},"ga:goal":[{"ga:destination":{"ga:step":{"name":"Contact Form Page","number":"1","path":"/contact.html"},"caseSensitive":"false","expression":"/contact-submit","matchType":"exact","step1Required":"true"},"active":"true","name":"Contact Form Submission","number":"1","value":"100.0"},{"ga:destination":{"caseSensitive":"false","expression":"/newsletter-submit","matchType":"exact","step1Required":"false"},"active":"true","name":"Newsletter Form Submission","number":"2","value":"25.0"}],"dxp:property":[{"name":"ga:accountId","value":"1111"},{"name":"ga:accountName","value":"Blog Beta"},{"name":"ga:profileId","value":"1213"},{"name":"ga:webPropertyId","value":"UA-1111-2"},{"name":"ga:currency","value":"USD"},{"name":"ga:timezone","value":"America/New_York"}],"dxp:tableId":"ga:12346","gd:etag":"W/\"A0UASX45cCp7I2A9WxFQEUQ.\"","gd:kind":"analytics#account"}],"xmlns":"http://www.w3.org/2005/Atom","xmlns:dxp":"http://schemas.google.com/analytics/2009","xmlns:ga":"http://schemas.google.com/ga/2009","xmlns:openSearch":"http://a9.com/-/spec/opensearch/1.1/","xmlns:gd":"http://schemas.google.com/g/2005","gd:etag":"W/\"A0UASX45cCp7I2A9WxFQEUQ.\"","gd:kind":"analytics#accounts"}}
+{"feed":{"id":"http://www.google.com/analytics/feeds/accounts/blah@gmail.com","updated":"2010-05-06T19:27:28.028-07:00","title":"Profile list for blah@gmail.com","link":{"rel":"self","type":"application/atom+xml","href":"https://www.google.com/analytics/feeds/accounts/default"},"author":{"name":"Google Analytics"},"generator":"Google Analytics","openSearch:totalResults":"2","openSearch:startIndex":"1","openSearch:itemsPerPage":"2","dxp$segment":[{"dxp$definition":null,"id":"gaid::-1","name":"All Visits"},{"dxp$definition":"ga:visitorType==New Visitor","id":"gaid::-2","name":"New Visitors"},{"dxp$definition":"ga:medium==cpa,ga:medium==cpc,ga:medium==cpm,ga:medium==cpp,ga:medium==cpv,ga:medium==ppc","id":"gaid::-3","name":"Paid Search Traffic"},{"dxp$definition":"ga:city!=New York","id":"gaid::0","name":"Not New York"}],"entry":[{"id":"http://www.google.com/analytics/feeds/accounts/ga:12345","updated":"2008-07-21T14:05:57.000-07:00","title":"Historical","link":{"rel":"alternate","type":"text/html","href":"http://www.google.com/analytics"},"ga:goal":[{"ga:destination":{"caseSensitive":"false","expression":"/blog.html","matchType":"head","step1Required":"false"},"active":"true","name":"Read Blog","number":"1","value":"10.0"},{"ga:destination":{"caseSensitive":"false","expression":"/support.html","matchType":"head","step1Required":"false"},"active":"true","name":"Go for Support","number":"2","value":"5.0"},{"ga:destination":{"ga:step":{"name":"Contact Form Page","number":"1","path":"/contact.html"},"caseSensitive":"false","expression":"/contact-submit","matchType":"exact","step1Required":"true"},"active":"true","name":"Contact Form Submission","number":"3","value":"100.0"},{"ga:destination":{"caseSensitive":"false","expression":"/newsletter-submit","matchType":"exact","step1Required":"false"},"active":"true","name":"Newsletter Form Submission","number":"4","value":"25.0"}],"dxp$property":[{"name":"ga:accountId","value":"1111"},{"name":"ga:accountName","value":"Blog Beta"},{"name":"ga:profileId","value":"1212"},{"name":"ga:webPropertyId","value":"UA-1111-1"},{"name":"ga:currency","value":"USD"},{"name":"ga:timezone","value":"America/New_York"}],"dxp:tableId":"ga:12345","gd:etag":"W/\"CUcHSXs8fip7I2A9WxBUFUg.\"","gd:kind":"analytics#account"},{"id":"http://www.google.com/analytics/feeds/accounts/ga:12346","updated":"2008-11-24T11:51:07.000-08:00","title":"Presently","link":{"rel":"alternate","type":"text/html","href":"http://www.google.com/analytics"},"ga:goal":[{"ga:destination":{"ga:step":{"name":"Contact Form Page","number":"1","path":"/contact.html"},"caseSensitive":"false","expression":"/contact-submit","matchType":"exact","step1Required":"true"},"active":"true","name":"Contact Form Submission","number":"1","value":"100.0"},{"ga:destination":{"caseSensitive":"false","expression":"/newsletter-submit","matchType":"exact","step1Required":"false"},"active":"true","name":"Newsletter Form Submission","number":"2","value":"25.0"}],"dxp$property":[{"name":"ga:accountId","value":"1111"},{"name":"ga:accountName","value":"Blog Beta"},{"name":"ga:profileId","value":"1213"},{"name":"ga:webPropertyId","value":"UA-1111-2"},{"name":"ga:currency","value":"USD"},{"name":"ga:timezone","value":"America/New_York"}],"dxp:tableId":"ga:12346","gd:etag":"W/\"A0UASX45cCp7I2A9WxFQEUQ.\"","gd:kind":"analytics#account"}],"xmlns":"http://www.w3.org/2005/Atom","xmlns:dxp":"http://schemas.google.com/analytics/2009","xmlns:ga":"http://schemas.google.com/ga/2009","xmlns:openSearch":"http://a9.com/-/spec/opensearch/1.1/","xmlns:gd":"http://schemas.google.com/g/2005","gd:etag":"W/\"A0UASX45cCp7I2A9WxFQEUQ.\"","gd:kind":"analytics#accounts"}}
View
2  test/fixtures/report_feed.json
@@ -1 +1 @@
-{"feed":{"id":"http://www.google.com/analytics/feeds/data?ids=ga:123456&dimensions=ga:country,ga:city&metrics=ga:pageViews&start-date=2008-01-01&end-date=2008-01-02","updated":"2008-01-02T15:59:59.999-08:00 ","title":"Google Analytics Data for Profile 123456","link":[{"href":"http://www.google.com/analytics/feeds/data","rel":"http://schemas.google.com/g/2005#feed","type":"application/atom+xml"},{"href":"http://www.google.com/analytics/feeds/data?end-date=2008-01-02&start-date=2008-01-01&metrics=ga%3ApageViews&ids=ga%3A983247&dimensions=ga%3Acountry%2Cga%3Acity","rel":"self","type":"application/atom+xml"},{"href":"http://www.google.com/analytics/feeds/data?start-index=1001&max-results=1000&end-date=2008-01-02&start-date=2008-01-01&metrics=ga%3ApageViews&ids=ga%3A983247&dimensions=ga%3Acountry%2Cga%3Acity","rel":"next","type":"application/atom+xml"}],"author":{"name":"Google Analytics"},"openSearch:startIndex":"3","openSearch:itemsPerPage":"4","openSearch:totalResults":"18","dxp:containsSampledData":"true","ga:webPropertyID":"UA-123456-78","ga:start_date":"2008-01-01","ga:end_date":"2008-01-02","entry":[{"id":" http://www.google.com/analytics/feeds/data?ids=ga:1174&ga:country=%28not%20set%29&ga:city=%28not%20set%29&start-date=2008-01-01&end-date=2008-01-02 ","updated":" 2008-01-01T16:00:00.001-08:00 ","title":" ga:country=(not set) | ga:city=(not set) ","link":{"href":"http://www.google.com/analytics/feeds/data","rel":"self","type":"application/atom+xml"},"dxp:dimension":[{"name":"ga:country","value":"(not set)"},{"name":"ga:city","value":"(not set)"}],"dxp:metric":{"name":"ga:pageviews","value":"33"}},{"id":" http://www.google.com/analytics/feeds/data?ids=ga:1174&ga:country=Afghanistan&ga:city=Kabul&start-date=2008-01-01&end-date=2008-01-02 ","updated":" 2008-01-01T16:00:00.001-08:00 ","title":" ga:country=Afghanistan | ga:city=Kabul ","dxp:dimension":[{"name":"ga:country","value":"Afghanistan"},{"name":"ga:city","value":"Kabul"}],"dxp:metric":{"name":"ga:pageviews","value":"2"}},{"id":" http://www.google.com/analytics/feeds/data?ids=ga:1174&ga:country=Albania&ga:city=Tirana&start-date=2008-01-01&end-date=2008-01-02 ","updated":" 2008-01-01T16:00:00.001-08:00 ","title":" ga:country=Albania | ga:city=Tirana ","dxp:dimension":[{"name":"ga:country","value":"Albania"},{"name":"ga:city","value":"Tirana"}],"dxp:metric":{"name":"ga:pageviews","value":"1"}}],"xmlns":"http://www.w3.org/2005/Atom","xmlns:openSearch":"http://a9.com/-/spec/opensearchrss/1.0/","xmlns:dxp":"http://schemas.google.com/analytics/2009","xmlns:ga":"http://schemas.google.com/analytics/2008"}}
+{"feed":{"id":"http://www.google.com/analytics/feeds/data?ids=ga:123456&dimensions=ga:country,ga:city&metrics=ga:pageViews&start-date=2008-01-01&end-date=2008-01-02","updated":"2008-01-02T15:59:59.999-08:00 ","title":"Google Analytics Data for Profile 123456","link":[{"href":"http://www.google.com/analytics/feeds/data","rel":"http://schemas.google.com/g/2005#feed","type":"application/atom+xml"},{"href":"http://www.google.com/analytics/feeds/data?end-date=2008-01-02&start-date=2008-01-01&metrics=ga%3ApageViews&ids=ga%3A983247&dimensions=ga%3Acountry%2Cga%3Acity","rel":"self","type":"application/atom+xml"},{"href":"http://www.google.com/analytics/feeds/data?start-index=1001&max-results=1000&end-date=2008-01-02&start-date=2008-01-01&metrics=ga%3ApageViews&ids=ga%3A983247&dimensions=ga%3Acountry%2Cga%3Acity","rel":"next","type":"application/atom+xml"}],"author":{"name":"Google Analytics"},"openSearch:startIndex":"3","openSearch:itemsPerPage":"4","openSearch:totalResults":"18","dxp$containsSampledData":"true","ga:webPropertyID":"UA-123456-78","ga:start_date":"2008-01-01","ga:end_date":"2008-01-02","entry":[{"id":" http://www.google.com/analytics/feeds/data?ids=ga:1174&ga:country=%28not%20set%29&ga:city=%28not%20set%29&start-date=2008-01-01&end-date=2008-01-02 ","updated":" 2008-01-01T16:00:00.001-08:00 ","title":" ga:country=(not set) | ga:city=(not set) ","link":{"href":"http://www.google.com/analytics/feeds/data","rel":"self","type":"application/atom+xml"},"dxp$dimension":[{"name":"ga:country","value":"(not set)"},{"name":"ga:city","value":"(not set)"}],"dxp$metric":{"name":"ga:pageviews","value":"33"}},{"id":" http://www.google.com/analytics/feeds/data?ids=ga:1174&ga:country=Afghanistan&ga:city=Kabul&start-date=2008-01-01&end-date=2008-01-02 ","updated":" 2008-01-01T16:00:00.001-08:00 ","title":" ga:country=Afghanistan | ga:city=Kabul ","dxp$dimension":[{"name":"ga:country","value":"Afghanistan"},{"name":"ga:city","value":"Kabul"}],"dxp$metric":{"name":"ga:pageviews","value":"2"}},{"id":" http://www.google.com/analytics/feeds/data?ids=ga:1174&ga:country=Albania&ga:city=Tirana&start-date=2008-01-01&end-date=2008-01-02 ","updated":" 2008-01-01T16:00:00.001-08:00 ","title":" ga:country=Albania | ga:city=Tirana ","dxp$dimension":[{"name":"ga:country","value":"Albania"},{"name":"ga:city","value":"Tirana"}],"dxp$metric":{"name":"ga:pageviews","value":"1"}}],"xmlns":"http://www.w3.org/2005/Atom","xmlns:openSearch":"http://a9.com/-/spec/opensearchrss/1.0/","xmlns:dxp":"http://schemas.google.com/analytics/2009","xmlns:ga":"http://schemas.google.com/analytics/2008"}}
View
2  test/unit/garb/management/account_test.rb
@@ -22,7 +22,7 @@ class AccountTest < MiniTest::Unit::TestCase
entry = {
"title" => "Google Analytics Account Garb",
"link" => [{"rel" => "self", "href" => Feed::BASE_URL+"/accounts/123456"}],
- "dxp:property" => [
+ "dxp$property" => [
{"name" => "ga:accountId", "value" => "123456"},
{"name" => "ga:accountName", "value" => "Garb"}
]
View
2  test/unit/garb/management/profile_test.rb
@@ -33,7 +33,7 @@ class ProfileTest < MiniTest::Unit::TestCase
setup do
entry = {
"link" => [{"rel" => "self", "href" => Feed::BASE_URL+"/accounts/1189765/webproperties/UA-1189765-1/profiles/98765"}],
- "dxp:property" => [
+ "dxp$property" => [
{"name" => "ga:profileId", "value" => "98765"},
{"name" => "ga:accountId", "value" => "1189765"},
{"name" => "ga:webPropertyId", "value" => 'UA-1189765-1'},
View
2  test/unit/garb/management/web_property_test.rb
@@ -30,7 +30,7 @@ class WebPropertyTest < MiniTest::Unit::TestCase
setup do
entry = {
"link" => [{"rel" => "self", "href" => Feed::BASE_URL+"/accounts/1189765/webproperties/UA-1189765-1"}],
- "dxp:property" => [
+ "dxp$property" => [
{"name" => "ga:accountId", "value" => "1189765"},
{"name" => "ga:webPropertyId", "value" => 'UA-1189765-1'}
]
View
2  test/unit/garb/model_test.rb
@@ -44,7 +44,7 @@ class ModelTest < MiniTest::Unit::TestCase
entry = {
"title" => "Google Analytics Profile example.com",
"link" => [{"rel" => "self", "href" => Garb::Management::Feed::BASE_URL+"/accounts/1189765/webproperties/UA-1189765-1/profiles/98765"}],
- "dxp:property" => [
+ "dxp$property" => [
{"name" => "ga:profileId", "value" => "98765"},
{"name" => "ga:accountId", "value" => "1189765"},
{"name" => "ga:webPropertyId", "value" => 'UA-1189765-1'}
View
4 test/unit/garb/request/data_test.rb
@@ -28,9 +28,9 @@ class DataTest < MiniTest::Unit::TestCase
assert_equal ["alt=json", "ids=12345", "metrics=country"], query_string.split('&').sort
end
- should "return an empty query string if parameters are empty" do
+ should "only contain JSON response option if parameters are empty" do
data_request = Request::Data.new(@session, "")
- assert_equal "", data_request.query_string
+ assert_equal "?alt=json", data_request.query_string
end
should "be able to build a uri" do
View
2  test/unit/garb_test.rb
@@ -12,7 +12,7 @@ class GarbTest < MiniTest::Unit::TestCase
end
should "have a helper to parse properties out of entries" do
- entry = {"dxp:property"=>[{"name"=>"ga:accountId", "value"=>"1189765"}, {"name"=>"ga:webPropertyId", "value"=>"UA-1189765-1"}]}
+ entry = {"dxp$property"=>[{"name"=>"ga:accountId", "value"=>"1189765"}, {"name"=>"ga:webPropertyId", "value"=>"UA-1189765-1"}]}
assert_equal({"account_id" => '1189765', "web_property_id" => "UA-1189765-1"}, Garb.parse_properties(entry))
end
Please sign in to comment.
Something went wrong with that request. Please try again.