Sha256: 24d259df6682609ce40fa78e64ea251243ee395dd79c77d239e36b4af5a5f437

Contents?: true

Size: 676 Bytes

Versions: 7

Compression:

Stored size: 676 Bytes

Contents

# encoding: UTF-8
module Reports
  class AnalyticsDaily
    include Mongoid::Document
    include Mongoid::Timestamps
    include ReportDaily

    field :visitors, type: Integer, default: 0

    def update_report!
      previous_report = self.previous_report
      current_report  = self

      date1    = previous_report.report_date.strftime("%Y-%m-%d")
      date2    = current_report.report_date.strftime("%Y-%m-%d")
      ga       = ::GoogleAnalytics.new()
      visitors = ga.visitors(date1, date2)

      previous_report.visitors = visitors[date1]
      current_report.visitors  = visitors[date2]

      previous_report.save!
      current_report.save!
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
character-1.0.6 app/models/reports/analytics_daily.rb
character-1.0.5 app/models/reports/analytics_daily.rb
character-1.0.4 app/models/reports/analytics_daily.rb
character-1.0.3 app/models/reports/analytics_daily.rb
character-1.0.2 app/models/reports/analytics_daily.rb
character-1.0.1 app/models/reports/analytics_daily.rb
character-1.0.0 app/models/reports/analytics_daily.rb