Permalink
Browse files

add dimensions and metrics to Garb::Model, fix error in tests when ad…

…ding to profile reports
  • Loading branch information...
1 parent 5d3d92e commit 7c2f6346e4c5e105e9458371e4e43fb2256327ac @tpitale tpitale committed Oct 11, 2010
Showing with 20 additions and 4 deletions.
  1. +1 −0 lib/garb.rb
  2. +6 −0 lib/garb/model.rb
  3. +2 −1 lib/garb/profile.rb
  4. +2 −1 lib/garb/profile_reports.rb
  5. +1 −1 lib/garb/report.rb
  6. +2 −0 lib/garb/resource.rb
  7. +6 −1 test/unit/garb/model_test.rb
View
@@ -7,6 +7,7 @@
begin
require 'active_support/inflector'
+ require 'active_support/deprecation'
rescue LoadError
require 'active_support'
end
View
@@ -3,6 +3,10 @@ module Model
MONTH = 2592000
URL = "https://www.google.com/analytics/feeds/data"
+ def self.extended(base)
+ ProfileReports.add_report_method(base)
+ end
+
def metrics(*fields)
@metrics ||= ReportParameter.new(:metrics)
@metrics << fields
@@ -26,6 +30,8 @@ def results(profile, options = {})
param_set = [
default_params,
+ metrics.to_params,
+ dimensions.to_params,
parse_filters(options).to_params,
parse_segment(options),
parse_sort(options).to_params,
View
@@ -21,11 +21,12 @@ def id
end
def self.all(session = Session)
+ ActiveSupport::Deprecation.warn("Garb::Profile.all is deprecated in favor of Garb::Management::Profile.all")
AccountFeedRequest.new(session).entries.map {|entry| new(entry, session)}
end
- # ActiveSupport::Deprecation.warn
def self.first(id, session = Session)
+ ActiveSupport::Deprecation.warn("Garb::Profile.first is deprecated in favor of Garb::Management::WebProperty")
all(session).detect {|profile| profile.id == id || profile.web_property_id == id }
end
end
@@ -3,7 +3,8 @@ module ProfileReports
def self.add_report_method(klass)
# demodulize leaves potential to redefine
# these methods given different namespaces
- method_name = klass.to_s.demodulize.underscore
+ method_name = klass.name.demodulize.underscore
+ return unless method_name.length > 0
class_eval <<-CODE
def #{method_name}(opts = {}, &block)
View
@@ -6,7 +6,7 @@ class Report
URL = "https://www.google.com/analytics/feeds/data"
def initialize(profile, opts={})
- # ActiveSupport::Deprecation.warn("The use of report will be removed in favor of extend Garb::Scheme")
+ ActiveSupport::Deprecation.warn("The use of Report will be removed in favor of 'extend Garb::Model'")
@profile = profile
View
@@ -9,6 +9,8 @@ def self.extended(base)
# to enable profile.exits(options_hash, &block)
# returns Exits.results(self, options_hash, &block)
# every class defined which extends Resource will add to the module
+
+ # ActiveSupport::Deprecation.warn
ProfileReports.add_report_method(base)
end
@@ -60,12 +60,17 @@ class ModelTest < MiniTest::Unit::TestCase
DataRequest.stubs(:new).returns(stub(:send_request => @response))
ReportResponse.stubs(:new).returns(stub(:results => ['result']))
+ @test_model.stubs(:metrics).returns(stub(:to_params => {'metrics' => 'ga:visits'}))
+ @test_model.stubs(:dimensions).returns(stub(:to_params => {'dimensions' => 'ga:pagePath'}))
+
now = Time.now
Time.stubs(:new).returns(now)
@params = {'ids' => Garb.to_ga(@profile.id),
'start-date' => (now - Model::MONTH).strftime('%Y-%m-%d'),
- 'end-date' => now.strftime('%Y-%m-%d')}
+ 'end-date' => now.strftime('%Y-%m-%d'),
+ 'metrics' => 'ga:visits',
+ 'dimensions' => 'ga:pagePath'}
end
should "get all results" do

0 comments on commit 7c2f634

Please sign in to comment.