Class: Orange::AnalyticsResource
- Defined in:
- lib/orange-more/analytics/resources/analytics_resource.rb
Instance Method Summary collapse
Methods inherited from Resource
#afterLoad, call_me, #do_view, #find_extras, #init, #initialize, #options, #orange, #orange_name, #routable, #set_orange, set_orange, #view, #view_opts
Methods included from ClassInheritableAttributes
#cattr_accessor, #cattr_reader, #cattr_writer, eval_in_accessor_module, fetch_value, store_value
Constructor Details
This class inherits a constructor from Orange::Resource
Instance Method Details
#gattica ⇒ Object
11 12 13 14 |
# File 'lib/orange-more/analytics/resources/analytics_resource.rb', line 11 def gattica return false unless [:email] @gattica ||= Gattica.new() end |
#pageviews(route, opts = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/orange-more/analytics/resources/analytics_resource.rb', line 16 def pageviews(route, opts = {}) return "No GA" unless gattica r = route.to_s # Strip trailing slash if present. GA doesn't like it. if r.rindex('/') > 0 r[r.rindex('/')] = '' end # authenticate with the API via email/password ga = gattica accounts = ga.accounts ga.profile_id = accounts.first.profile_id views = "" data = ga.get({ :start_date => '2009-01-01', :end_date => Time.now.localtime.strftime("%Y-%m-%d"), :dimensions => ['pagePath'], :metrics => ['pageviews'], :filters => ['pagePath == '+route.to_s[0..-1]] }.merge(opts)) unless data.points.length == 0 views = data.points[0].metrics[0][:pageviews] views else 0 end end |
#stack_init ⇒ Object
6 7 8 9 |
# File 'lib/orange-more/analytics/resources/analytics_resource.rb', line 6 def stack_init [:email] = orange.['ga_email'] [:password] = orange.['ga_password'] end |