Fosome / garb

A Ruby wrapper for the Google Analytics API
http://www.viget.com/extend/
654 stars 89 forks source link

Dimensions and metrics accumulate themselves #103

Closed Javierchik closed 13 years ago

Javierchik commented 13 years ago

Hi, i run into a problem when performing this...

Controller.... data = GoogleData.load(profile, options) data2 = GoogleData.load(profile, options2) data3 = GoogleData.load(profile, options3)

Model... class GoogleData extend Garb::Model

class << self

def clear_all
  @metrics = Garb::ReportParameter.new(:metrics)
  @dimensions = Garb::ReportParameter.new(:dimensions)
end

def load_data(profile, opts)
  clear_all
  dimensions :date
  metrics opts[:metric]
  dimensions :visitorType unless opts[:visitor_type].blank?

  open_struct = self.results(profile, :start_date => opts[:start_date] || Time.parse('2010-07-01'),
  :end_date   => opts[:end_date] || Time.now)

end end end

the thing is that dimensions and metrics accumulate and need to be clean every time that i perform from the controller. Is this approach correct?... it is something similar with some function called clean_filters ...

Thanks

tpitale commented 13 years ago

If you're going to use Garb::Model you should be designing individual classes that have specific metrics and dimensions. Think of it as a Rails ActiveRecord class, you don't use one class to interact with every table in your database clearing out the column definitions and recreating every time you want to use it.