Sha256: f1697990e6e711105186ea032e4f633d39b04cc4360c94e0928163b50c2ac946
Contents?: true
Size: 1.57 KB
Versions: 1
Compression:
Stored size: 1.57 KB
Contents
module LazyGoogleAnalytics class Client CLIENT_OPTIONS = %w(api_method parameters ids start_date end_date dimensions metrics sort filters) attr_accessor :options, :auth def initialize(opts = {}) @auth ||= LazyGoogleAnalytics::Auth.new @auth.authorize # check expiration and cache ? self.tap do |client| client.options ||= {} client.defaults_options(opts) client.options ||= opts yield client if block_given? end end def defaults_options(opts) start_date = opts[:start_date] ||= DateTime.now.prev_month.strftime("%Y-%m-%d") end_date = opts[:end_date] ||= DateTime.now.strftime("%Y-%m-%d") self.api_method(@auth.analytics.data.ga.get) self.parameters({'ids' => "ga:#{LazyGoogleAnalytics::Config.profile_id}", 'start-date' => start_date, 'end-date' => end_date, 'dimensions' => "ga:day,ga:month", 'metrics' => "ga:visits", 'sort' => "ga:month,ga:day" }) end def results @results = @auth.client.execute(@options) end def formatted_columns (@results || self.results).data.column_headers.map { |c| c.name }.join("\t") end def formatted_rows (@results || self.results).data.rows.each do |r| print r.join("\t"), "\n" end end def method_missing(meth, opts = {}) merge_options meth, opts end private def merge_options(name, opts) @options.merge! name => opts end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lazy_google_analytics-0.1.0 | lib/lazy_google_analytics/client.rb |