Created
January 8, 2013 01:29
-
-
Save hrysd/4480286 to your computer and use it in GitHub Desktop.
define_method かっこいい。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'garb' | |
| require 'active_support/time' | |
| class Visitor | |
| extend Garb::Model | |
| metrics :visitors, :percent_new_visits | |
| end | |
| module Reporter | |
| class << self | |
| %w(day week month).each do |period| | |
| define_method("between_a_#{period}") do |time| | |
| Garb::Session.login(ENV['ACCOUNT'], ENV['PASSWORD']) | |
| profile = Garb::Management::Profile.all.detect { |p| p.web_property_id == ENV['WPID'] } | |
| analytics = profile.visitor( | |
| start_date: time.send(:"beginning_of_#{period}"), | |
| end_date: time.send(:"end_of_#{period}") | |
| ) | |
| result = {} | |
| analytics.each do |r| | |
| result[:visitors] = r.visitors | |
| result[:percent_new_visits] = r.percent_new_visits | |
| end | |
| result | |
| end | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| source :rubygems | |
| gem 'garb' | |
| gem 'active_support' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment