rugalytics 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +2 -0
- data/README +24 -25
- data/README.rdoc +24 -25
- data/lib/rugalytics/graph.rb +2 -2
- data/lib/rugalytics/item.rb +1 -0
- data/lib/rugalytics/profile.rb +2 -2
- data/lib/rugalytics/report.rb +3 -12
- data/lib/rugalytics.rb +2 -1
- data/rugalytics.gemspec +3 -3
- data/spec/lib/rugalytics/graph_spec.rb +44 -32
- data/spec/lib/rugalytics/item_spec.rb +2 -2
- data/spec/lib/rugalytics/profile_spec.rb +20 -19
- data/spec/lib/rugalytics/report_spec.rb +93 -80
- metadata +2 -2
    
        data/CHANGELOG
    CHANGED
    
    
    
        data/README
    CHANGED
    
    | @@ -18,24 +18,6 @@ Should be up at rubyforge, so to install: | |
| 18 18 | 
             
             sudo gem install rugalytics
         | 
| 19 19 |  | 
| 20 20 |  | 
| 21 | 
            -
            == Changes in v0.0.5
         | 
| 22 | 
            -
             | 
| 23 | 
            -
            The load_report method has been deprecated, instead call the report name as
         | 
| 24 | 
            -
            a method, for example:
         | 
| 25 | 
            -
             | 
| 26 | 
            -
             # Instead of this
         | 
| 27 | 
            -
             report = profile.load_report('Pageviews', :from => '2007-01-01')
         | 
| 28 | 
            -
             | 
| 29 | 
            -
             # Do this
         | 
| 30 | 
            -
             report = profile.pageviews_report(:from => '2007-01-01')
         | 
| 31 | 
            -
             | 
| 32 | 
            -
             # Instead of this
         | 
| 33 | 
            -
             report = profile.load_report('TrafficSources')
         | 
| 34 | 
            -
             | 
| 35 | 
            -
             # Do this
         | 
| 36 | 
            -
             report = profile.traffic_sources_report
         | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 21 | 
             
            == Authenticate
         | 
| 40 22 |  | 
| 41 23 | 
             
            Login with your Google Analytics user name and password:
         | 
| @@ -58,6 +40,14 @@ If account name and profile name are the same: | |
| 58 40 | 
             
             profile = Rugalytics.find_profile('your_site.com')
         | 
| 59 41 |  | 
| 60 42 |  | 
| 43 | 
            +
            == Change Language Settings to English
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            At present your language setting for your Google Analytics account
         | 
| 46 | 
            +
            must be set to English for Rugalytics to work.
         | 
| 47 | 
            +
             | 
| 48 | 
            +
             Google: Settings -> Language: choose UK English or US English
         | 
| 49 | 
            +
             | 
| 50 | 
            +
             | 
| 61 51 | 
             
            == Get Profile Summary Statistics
         | 
| 62 52 |  | 
| 63 53 | 
             
            Obtaining page views:
         | 
| @@ -73,15 +63,24 @@ Obtaining page views: | |
| 73 63 |  | 
| 74 64 | 
             
            The +pageviews+ method is doing this under the hood:
         | 
| 75 65 |  | 
| 76 | 
            -
             report = profile.pageviews_report | 
| 66 | 
            +
             report = profile.pageviews_report :from=>'2007-01-01', :to=>'2007-01-02'
         | 
| 77 67 |  | 
| 78 | 
            -
             report. | 
| 79 | 
            -
             =>  | 
| 68 | 
            +
             report.pageviews_total
         | 
| 69 | 
            +
             => 16600
         | 
| 80 70 |  | 
| 81 | 
            -
             | 
| 71 | 
            +
            Using the report you can get +pageviews_by_day+:
         | 
| 72 | 
            +
             | 
| 73 | 
            +
             report.pageviews_by_day
         | 
| 74 | 
            +
             => [[Mon, 01 Jan 2007, 8200], [Tue, 02 Jan 2007, 8400]]
         | 
| 75 | 
            +
             | 
| 76 | 
            +
            In the report, there is a +pageviews_graph+ containing the points:
         | 
| 77 | 
            +
             | 
| 78 | 
            +
             report.pageviews_graph.sum_of_points
         | 
| 79 | 
            +
             => 16600
         | 
| 80 | 
            +
             | 
| 81 | 
            +
             report.pageviews_graph.points_by_day
         | 
| 82 | 
            +
             => [[Mon, 01 Jan 2007, 8200], [Tue, 02 Jan 2007, 8400]]
         | 
| 82 83 |  | 
| 83 | 
            -
             report.page_views_graph.sum_of_points
         | 
| 84 | 
            -
             => 24980
         | 
| 85 84 |  | 
| 86 85 | 
             
            == Load a Report
         | 
| 87 86 |  | 
| @@ -156,7 +155,7 @@ automatically, e.g.: | |
| 156 155 |  | 
| 157 156 | 
             
             profile = Rugalytics.default_profile
         | 
| 158 157 | 
             
             report = profile.top_content_report(:from=>(Date.today - 7) )
         | 
| 159 | 
            -
             top_items_over_week = report.items.sort_by{|i| i. | 
| 158 | 
            +
             top_items_over_week = report.items.sort_by{|i| i.unique_pageviews.to_i}.reverse
         | 
| 160 159 |  | 
| 161 160 |  | 
| 162 161 | 
             
            ==Acknowledgements
         | 
    
        data/README.rdoc
    CHANGED
    
    | @@ -18,24 +18,6 @@ Should be up at rubyforge, so to install: | |
| 18 18 | 
             
             sudo gem install rugalytics
         | 
| 19 19 |  | 
| 20 20 |  | 
| 21 | 
            -
            == Changes in v0.0.5
         | 
| 22 | 
            -
             | 
| 23 | 
            -
            The load_report method has been deprecated, instead call the report name as
         | 
| 24 | 
            -
            a method, for example:
         | 
| 25 | 
            -
             | 
| 26 | 
            -
             # Instead of this
         | 
| 27 | 
            -
             report = profile.load_report('Pageviews', :from => '2007-01-01')
         | 
| 28 | 
            -
             | 
| 29 | 
            -
             # Do this
         | 
| 30 | 
            -
             report = profile.pageviews_report(:from => '2007-01-01')
         | 
| 31 | 
            -
             | 
| 32 | 
            -
             # Instead of this
         | 
| 33 | 
            -
             report = profile.load_report('TrafficSources')
         | 
| 34 | 
            -
             | 
| 35 | 
            -
             # Do this
         | 
| 36 | 
            -
             report = profile.traffic_sources_report
         | 
| 37 | 
            -
             | 
| 38 | 
            -
             | 
| 39 21 | 
             
            == Authenticate
         | 
| 40 22 |  | 
| 41 23 | 
             
            Login with your Google Analytics user name and password:
         | 
| @@ -58,6 +40,14 @@ If account name and profile name are the same: | |
| 58 40 | 
             
             profile = Rugalytics.find_profile('your_site.com')
         | 
| 59 41 |  | 
| 60 42 |  | 
| 43 | 
            +
            == Change Language Settings to English
         | 
| 44 | 
            +
             | 
| 45 | 
            +
            At present your language setting for your Google Analytics account
         | 
| 46 | 
            +
            must be set to English for Rugalytics to work.
         | 
| 47 | 
            +
             | 
| 48 | 
            +
             Google: Settings -> Language: choose UK English or US English
         | 
| 49 | 
            +
             | 
| 50 | 
            +
             | 
| 61 51 | 
             
            == Get Profile Summary Statistics
         | 
| 62 52 |  | 
| 63 53 | 
             
            Obtaining page views:
         | 
| @@ -73,15 +63,24 @@ Obtaining page views: | |
| 73 63 |  | 
| 74 64 | 
             
            The +pageviews+ method is doing this under the hood:
         | 
| 75 65 |  | 
| 76 | 
            -
             report = profile.pageviews_report | 
| 66 | 
            +
             report = profile.pageviews_report :from=>'2007-01-01', :to=>'2007-01-02'
         | 
| 77 67 |  | 
| 78 | 
            -
             report. | 
| 79 | 
            -
             =>  | 
| 68 | 
            +
             report.pageviews_total
         | 
| 69 | 
            +
             => 16600
         | 
| 80 70 |  | 
| 81 | 
            -
             | 
| 71 | 
            +
            Using the report you can get +pageviews_by_day+:
         | 
| 72 | 
            +
             | 
| 73 | 
            +
             report.pageviews_by_day
         | 
| 74 | 
            +
             => [[Mon, 01 Jan 2007, 8200], [Tue, 02 Jan 2007, 8400]]
         | 
| 75 | 
            +
             | 
| 76 | 
            +
            In the report, there is a +pageviews_graph+ containing the points:
         | 
| 77 | 
            +
             | 
| 78 | 
            +
             report.pageviews_graph.sum_of_points
         | 
| 79 | 
            +
             => 16600
         | 
| 80 | 
            +
             | 
| 81 | 
            +
             report.pageviews_graph.points_by_day
         | 
| 82 | 
            +
             => [[Mon, 01 Jan 2007, 8200], [Tue, 02 Jan 2007, 8400]]
         | 
| 82 83 |  | 
| 83 | 
            -
             report.page_views_graph.sum_of_points
         | 
| 84 | 
            -
             => 24980
         | 
| 85 84 |  | 
| 86 85 | 
             
            == Load a Report
         | 
| 87 86 |  | 
| @@ -156,7 +155,7 @@ automatically, e.g.: | |
| 156 155 |  | 
| 157 156 | 
             
             profile = Rugalytics.default_profile
         | 
| 158 157 | 
             
             report = profile.top_content_report(:from=>(Date.today - 7) )
         | 
| 159 | 
            -
             top_items_over_week = report.items.sort_by{|i| i. | 
| 158 | 
            +
             top_items_over_week = report.items.sort_by{|i| i.unique_pageviews.to_i}.reverse
         | 
| 160 159 |  | 
| 161 160 |  | 
| 162 161 | 
             
            ==Acknowledgements
         | 
    
        data/lib/rugalytics/graph.rb
    CHANGED
    
    | @@ -25,8 +25,8 @@ module Rugalytics | |
| 25 25 |  | 
| 26 26 | 
             
                def with_dates_from_period period, list
         | 
| 27 27 | 
             
                  dates = period.split('-')
         | 
| 28 | 
            -
                  from = Date. | 
| 29 | 
            -
                  to = Date. | 
| 28 | 
            +
                  from = Date.i18n_parse(dates[0].strip)
         | 
| 29 | 
            +
                  to = Date.i18n_parse(dates[1].strip)
         | 
| 30 30 |  | 
| 31 31 | 
             
                  index = 0
         | 
| 32 32 | 
             
                  from.upto(to) do |date|
         | 
    
        data/lib/rugalytics/item.rb
    CHANGED
    
    
    
        data/lib/rugalytics/profile.rb
    CHANGED
    
    | @@ -77,11 +77,11 @@ module Rugalytics | |
| 77 77 | 
             
                end
         | 
| 78 78 |  | 
| 79 79 | 
             
                def pageviews(options={})
         | 
| 80 | 
            -
                  pageviews_report(options). | 
| 80 | 
            +
                  pageviews_report(options).pageviews_total
         | 
| 81 81 | 
             
                end
         | 
| 82 82 |  | 
| 83 83 | 
             
                def pageviews_by_day(options={})
         | 
| 84 | 
            -
                  pageviews_report(options). | 
| 84 | 
            +
                  pageviews_report(options).pageviews_by_day
         | 
| 85 85 | 
             
                end
         | 
| 86 86 |  | 
| 87 87 | 
             
                def visits(options={})
         | 
    
        data/lib/rugalytics/report.rb
    CHANGED
    
    | @@ -19,7 +19,6 @@ module Rugalytics | |
| 19 19 | 
             
                end
         | 
| 20 20 |  | 
| 21 21 | 
             
                def method_missing symbol, *args
         | 
| 22 | 
            -
             | 
| 23 22 | 
             
                  if is_writer = symbol.to_s[/=$/]
         | 
| 24 23 | 
             
                    morph_method_missing(symbol, *args)
         | 
| 25 24 |  | 
| @@ -43,16 +42,8 @@ module Rugalytics | |
| 43 42 | 
             
                  @base_url = lines[1]
         | 
| 44 43 | 
             
                  @report_name = lines[2].chomp(',')
         | 
| 45 44 | 
             
                  dates = lines[3].include?('","') ? lines[3].split('","') : lines[3].split(',')
         | 
| 46 | 
            -
                  @start_date =  | 
| 47 | 
            -
                  @end_date =  | 
| 48 | 
            -
                end
         | 
| 49 | 
            -
             | 
| 50 | 
            -
                def parse_date text
         | 
| 51 | 
            -
                  begin
         | 
| 52 | 
            -
                    Date.parse(text)
         | 
| 53 | 
            -
                  rescue Exception => e
         | 
| 54 | 
            -
                    raise "#{e}: #{text}"
         | 
| 55 | 
            -
                  end
         | 
| 45 | 
            +
                  @start_date = Date.i18n_parse(dates[0])
         | 
| 46 | 
            +
                  @end_date = Date.i18n_parse(dates[1])
         | 
| 56 47 | 
             
                end
         | 
| 57 48 |  | 
| 58 49 | 
             
                def handle_graphs lines
         | 
| @@ -75,7 +66,7 @@ module Rugalytics | |
| 75 66 | 
             
                    end
         | 
| 76 67 |  | 
| 77 68 | 
             
                    graph = Graph.new name, graph_period, points, start_date, end_date
         | 
| 78 | 
            -
                    morph("#{name} graph", graph)
         | 
| 69 | 
            +
                    morph("#{name.sub(/page views/i,'pageviews')} graph", graph)
         | 
| 79 70 | 
             
                  end
         | 
| 80 71 | 
             
                end
         | 
| 81 72 |  | 
    
        data/lib/rugalytics.rb
    CHANGED
    
    | @@ -11,7 +11,7 @@ require 'yaml' | |
| 11 11 |  | 
| 12 12 | 
             
            # See README for usage documentation.
         | 
| 13 13 | 
             
            module Rugalytics
         | 
| 14 | 
            -
              VERSION = "0.0. | 
| 14 | 
            +
              VERSION = "0.0.7"
         | 
| 15 15 |  | 
| 16 16 | 
             
              FORMAT_PDF = '0' unless defined? FORMAT_PDF
         | 
| 17 17 | 
             
              FORMAT_XML = '1' unless defined? FORMAT_XML
         | 
| @@ -81,5 +81,6 @@ require File.dirname(__FILE__) + '/rugalytics/profile' | |
| 81 81 | 
             
            require File.dirname(__FILE__) + '/rugalytics/report'
         | 
| 82 82 | 
             
            require File.dirname(__FILE__) + '/rugalytics/item'
         | 
| 83 83 | 
             
            require File.dirname(__FILE__) + '/rugalytics/graph'
         | 
| 84 | 
            +
            require File.dirname(__FILE__) + '/rugalytics/date_extension'
         | 
| 84 85 |  | 
| 85 86 | 
             
            # Rugalytics.config_setup(RAILS_ROOT) if defined?(RAILS_ROOT) && RAILS_ROOT
         | 
    
        data/rugalytics.gemspec
    CHANGED
    
    | @@ -1,18 +1,18 @@ | |
| 1 1 |  | 
| 2 | 
            -
            # Gem::Specification for Rugalytics-0.0. | 
| 2 | 
            +
            # Gem::Specification for Rugalytics-0.0.7
         | 
| 3 3 | 
             
            # Originally generated by Echoe
         | 
| 4 4 |  | 
| 5 5 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 6 6 | 
             
            name: rugalytics
         | 
| 7 7 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 8 | 
            -
              version: 0.0. | 
| 8 | 
            +
              version: 0.0.7
         | 
| 9 9 | 
             
            platform: ruby
         | 
| 10 10 | 
             
            authors: 
         | 
| 11 11 | 
             
            - Rob McKinnon
         | 
| 12 12 | 
             
            autorequire: 
         | 
| 13 13 | 
             
            bindir: bin
         | 
| 14 14 |  | 
| 15 | 
            -
            date: 2008-08- | 
| 15 | 
            +
            date: 2008-08-05 00:00:00 +01:00
         | 
| 16 16 | 
             
            default_executable: 
         | 
| 17 17 | 
             
            dependencies: 
         | 
| 18 18 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| @@ -1,47 +1,59 @@ | |
| 1 1 | 
             
            require File.dirname(__FILE__) + '/../../spec_helper.rb'
         | 
| 2 | 
            +
            include Rugalytics
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            shared_examples_for "graph created correctly" do
         | 
| 5 | 
            +
              def graph_correct_for report_start, report_end, expected_points
         | 
| 6 | 
            +
                graph = Graph.new 'Page Views', @period, @points, report_start, report_end
         | 
| 7 | 
            +
                graph.from.should == report_start
         | 
| 8 | 
            +
                graph.to.should == report_end
         | 
| 9 | 
            +
                graph.points.should == expected_points
         | 
| 10 | 
            +
                graph
         | 
| 11 | 
            +
              end
         | 
| 2 12 |  | 
| 3 | 
            -
             | 
| 13 | 
            +
              it "should set given points on graph" do
         | 
| 14 | 
            +
                graph_correct_for Date.parse('2008-05-01'), Date.parse('2008-05-03'), @points
         | 
| 15 | 
            +
              end
         | 
| 4 16 |  | 
| 5 | 
            -
               | 
| 17 | 
            +
              it "should set appropriate point on graph when report start and end is the same date" do
         | 
| 18 | 
            +
                graph_correct_for Date.parse('2008-05-01'), Date.parse('2008-05-01'), [@points[0]]
         | 
| 19 | 
            +
              end
         | 
| 6 20 |  | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
                  @points = [5360, 3330, 4330]
         | 
| 11 | 
            -
                end
         | 
| 21 | 
            +
              it "should set appropriate points on graph when report start and end is a subset of the graph period" do
         | 
| 22 | 
            +
                graph_correct_for Date.parse('2008-05-02'), Date.parse('2008-05-03'), [@points[1],@points[2]]
         | 
| 23 | 
            +
              end
         | 
| 12 24 |  | 
| 13 | 
            -
             | 
| 14 | 
            -
             | 
| 15 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 25 | 
            +
              it 'should set points by day' do
         | 
| 26 | 
            +
                from = Date.parse('1 May 2008')
         | 
| 27 | 
            +
                to = Date.parse('3 May 2008')
         | 
| 28 | 
            +
                mid = Date.parse('2 May 2008')
         | 
| 29 | 
            +
                graph = graph_correct_for from, to, @points
         | 
| 30 | 
            +
                graph.points_by_day.should == [[from,5360],[mid,3330],[to,4330]]
         | 
| 31 | 
            +
              end
         | 
| 20 32 |  | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
                 | 
| 33 | 
            +
              it 'should return sum of points' do
         | 
| 34 | 
            +
                graph = graph_correct_for Date.parse('2008-05-01'), Date.parse('2008-05-03'), @points
         | 
| 35 | 
            +
                graph.sum_of_points.should == 5360 + 3330 + 4330
         | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
            end
         | 
| 24 38 |  | 
| 25 | 
            -
             | 
| 26 | 
            -
                  graph_correct_for Date.parse('2008-05-01'), Date.parse('2008-05-01'), [@points[0]]
         | 
| 27 | 
            -
                end
         | 
| 39 | 
            +
            describe Graph do
         | 
| 28 40 |  | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 41 | 
            +
              describe 'when creating with dates formatted Day Month Year' do
         | 
| 42 | 
            +
                before :all do
         | 
| 43 | 
            +
                  @period = '1 May 2008 - 3 May 2008'
         | 
| 44 | 
            +
                  @points = [5360, 3330, 4330]
         | 
| 31 45 | 
             
                end
         | 
| 32 46 |  | 
| 33 | 
            -
                 | 
| 34 | 
            -
             | 
| 35 | 
            -
                  to = Date.parse('3 May 2008')
         | 
| 36 | 
            -
                  mid = Date.parse('2 May 2008')
         | 
| 37 | 
            -
                  graph = graph_correct_for from, to, @points
         | 
| 38 | 
            -
                  graph.points_by_day.should == [[from,5360],[mid,3330],[to,4330]]
         | 
| 39 | 
            -
                end
         | 
| 47 | 
            +
                it_should_behave_like "graph created correctly"
         | 
| 48 | 
            +
              end
         | 
| 40 49 |  | 
| 41 | 
            -
             | 
| 42 | 
            -
             | 
| 43 | 
            -
                   | 
| 50 | 
            +
              describe 'when creating with dates formatted "Month Day, Year"' do
         | 
| 51 | 
            +
                before :all do
         | 
| 52 | 
            +
                  @period = %Q|"May 1, 2008 - May 3, 2008"|
         | 
| 53 | 
            +
                  @points = [5360, 3330, 4330]
         | 
| 44 54 | 
             
                end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                it_should_behave_like "graph created correctly"
         | 
| 45 57 | 
             
              end
         | 
| 46 58 |  | 
| 47 59 | 
             
            end
         | 
| @@ -13,8 +13,8 @@ describe Rugalytics::Item, 'when creating' do | |
| 13 13 |  | 
| 14 14 | 
             
                item.url.should == 'http://theyworkforyou.co.nz/'
         | 
| 15 15 | 
             
                item.path.should == '/'
         | 
| 16 | 
            -
                item. | 
| 17 | 
            -
                item. | 
| 16 | 
            +
                item.pageviews.should == '189'
         | 
| 17 | 
            +
                item.unique_pageviews.should == '157'
         | 
| 18 18 | 
             
                item.time_on_page.should == '54.94957983193277'
         | 
| 19 19 | 
             
                item.bounce_rate.should == '0.4862385392189026'
         | 
| 20 20 | 
             
                item.percentage_exit.should == '0.37037035822868347'
         | 
| @@ -1,18 +1,19 @@ | |
| 1 1 | 
             
            require File.dirname(__FILE__) + '/../../spec_helper.rb'
         | 
| 2 | 
            +
            include Rugalytics
         | 
| 2 3 |  | 
| 3 | 
            -
            describe  | 
| 4 | 
            +
            describe Profile do
         | 
| 4 5 |  | 
| 5 6 | 
             
              describe "being initialized" do
         | 
| 6 7 | 
             
                it "should accept :name as key" do
         | 
| 7 | 
            -
                  profile =  | 
| 8 | 
            +
                  profile = Profile.new(:name => 'test', :profile_id => '12341234')
         | 
| 8 9 | 
             
                  profile.name.should == 'test'
         | 
| 9 10 | 
             
                end
         | 
| 10 11 | 
             
                it "should accept :account_id as key" do
         | 
| 11 | 
            -
                  profile =  | 
| 12 | 
            +
                  profile = Profile.new(:account_id => '12341234', :profile_id => '12341234')
         | 
| 12 13 | 
             
                  profile.account_id.should == '12341234'
         | 
| 13 14 | 
             
                end
         | 
| 14 15 | 
             
                it "should accept :profile_id as key" do
         | 
| 15 | 
            -
                  profile =  | 
| 16 | 
            +
                  profile = Profile.new(:profile_id => '12341234')
         | 
| 16 17 | 
             
                  profile.profile_id.should == '12341234'
         | 
| 17 18 | 
             
                end
         | 
| 18 19 | 
             
              end
         | 
| @@ -24,33 +25,33 @@ describe Rugalytics::Profile do | |
| 24 25 | 
             
                  account = mock('account')
         | 
| 25 26 | 
             
                  profile = mock('profile')
         | 
| 26 27 |  | 
| 27 | 
            -
                   | 
| 28 | 
            +
                  Account.should_receive(:find).with(1254221).and_return account
         | 
| 28 29 | 
             
                  account.should_receive(:find_profile).with(profile_id).and_return profile
         | 
| 29 | 
            -
                   | 
| 30 | 
            +
                  Profile.find(account_id, profile_id).should == profile
         | 
| 30 31 | 
             
                end
         | 
| 31 32 | 
             
              end
         | 
| 32 33 |  | 
| 33 34 | 
             
              describe 'finding pageviews' do
         | 
| 34 35 | 
             
                before do
         | 
| 35 | 
            -
                  @profile =  | 
| 36 | 
            -
                  @report = mock('report',: | 
| 36 | 
            +
                  @profile = Profile.new :profile_id=>123
         | 
| 37 | 
            +
                  @report = mock('report',:pageviews_total=>100)
         | 
| 37 38 | 
             
                end
         | 
| 38 39 | 
             
                it 'should return total from loaded "Pageviews" report' do
         | 
| 39 40 | 
             
                  @profile.should_receive(:pageviews_report).with({}).and_return @report
         | 
| 40 | 
            -
                  @profile.pageviews.should == @report. | 
| 41 | 
            +
                  @profile.pageviews.should == @report.pageviews_total
         | 
| 41 42 | 
             
                end
         | 
| 42 43 | 
             
                describe 'when from and to dates are specified' do
         | 
| 43 44 | 
             
                  it 'should return total from "Pageviews" report for given dates' do
         | 
| 44 45 | 
             
                    options = {:from=>'2008-05-01', :to=>'2008-05-03'}
         | 
| 45 46 | 
             
                    @profile.should_receive(:pageviews_report).with(options).and_return @report
         | 
| 46 | 
            -
                    @profile.pageviews(options).should == @report. | 
| 47 | 
            +
                    @profile.pageviews(options).should == @report.pageviews_total
         | 
| 47 48 | 
             
                  end
         | 
| 48 49 | 
             
                end
         | 
| 49 50 | 
             
              end
         | 
| 50 51 |  | 
| 51 52 | 
             
              describe 'finding visits' do
         | 
| 52 53 | 
             
                before do
         | 
| 53 | 
            -
                  @profile =  | 
| 54 | 
            +
                  @profile = Profile.new :profile_id=>123
         | 
| 54 55 | 
             
                  @report = mock('report', :visits_total=>100)
         | 
| 55 56 | 
             
                end
         | 
| 56 57 | 
             
                it 'should return total from loaded "Visits" report' do
         | 
| @@ -68,7 +69,7 @@ describe Rugalytics::Profile do | |
| 68 69 |  | 
| 69 70 | 
             
              describe 'finding report when called with method ending in _report' do
         | 
| 70 71 | 
             
                before do
         | 
| 71 | 
            -
                  @profile =  | 
| 72 | 
            +
                  @profile = Profile.new :profile_id=>123
         | 
| 72 73 | 
             
                  @report = mock('report', :visits_total=>100)
         | 
| 73 74 | 
             
                end
         | 
| 74 75 | 
             
                it 'should find report using create_report method' do
         | 
| @@ -79,7 +80,7 @@ describe Rugalytics::Profile do | |
| 79 80 | 
             
                  csv = 'csv'
         | 
| 80 81 | 
             
                  @profile.should_receive(:get_report_csv).with({:report=>'Visits'}).and_return csv
         | 
| 81 82 | 
             
                  @report.stub!(:attribute_names).and_return ''
         | 
| 82 | 
            -
                   | 
| 83 | 
            +
                  Report.should_receive(:new).with(csv).and_return @report
         | 
| 83 84 | 
             
                  @profile.visits_report.should == @report
         | 
| 84 85 | 
             
                end
         | 
| 85 86 | 
             
                describe 'when report name is two words' do
         | 
| @@ -99,8 +100,8 @@ describe Rugalytics::Profile do | |
| 99 100 |  | 
| 100 101 | 
             
              it "should be able to find all profiles for an account" do
         | 
| 101 102 | 
             
                html = fixture('analytics_profile_find_all.html')
         | 
| 102 | 
            -
                 | 
| 103 | 
            -
                accounts =  | 
| 103 | 
            +
                Profile.should_receive(:get).and_return(html)
         | 
| 104 | 
            +
                accounts = Profile.find_all('1254221')
         | 
| 104 105 | 
             
                accounts.collect(&:name).should ==  ["blog.your_site.com"]
         | 
| 105 106 | 
             
              end
         | 
| 106 107 |  | 
| @@ -111,9 +112,9 @@ describe Rugalytics::Profile do | |
| 111 112 | 
             
                  account = mock('account')
         | 
| 112 113 | 
             
                  profile = mock('profile')
         | 
| 113 114 |  | 
| 114 | 
            -
                   | 
| 115 | 
            +
                  Account.should_receive(:find).with(account_name).and_return account
         | 
| 115 116 | 
             
                  account.should_receive(:find_profile).with(profile_name).and_return profile
         | 
| 116 | 
            -
                   | 
| 117 | 
            +
                  Profile.find(account_name, profile_name).should == profile
         | 
| 117 118 | 
             
                end
         | 
| 118 119 | 
             
              end
         | 
| 119 120 |  | 
| @@ -123,9 +124,9 @@ describe Rugalytics::Profile do | |
| 123 124 | 
             
                  account = mock('account')
         | 
| 124 125 | 
             
                  profile = mock('profile')
         | 
| 125 126 |  | 
| 126 | 
            -
                   | 
| 127 | 
            +
                  Account.should_receive(:find).with(name).and_return account
         | 
| 127 128 | 
             
                  account.should_receive(:find_profile).with(name).and_return profile
         | 
| 128 | 
            -
                   | 
| 129 | 
            +
                  Profile.find(name).should == profile
         | 
| 129 130 | 
             
                end
         | 
| 130 131 | 
             
              end
         | 
| 131 132 | 
             
            end
         | 
| @@ -1,17 +1,18 @@ | |
| 1 1 | 
             
            require File.dirname(__FILE__) + '/../../spec_helper.rb'
         | 
| 2 | 
            +
            include Rugalytics
         | 
| 2 3 |  | 
| 3 | 
            -
            describe  | 
| 4 | 
            +
            describe Report do
         | 
| 4 5 |  | 
| 5 6 | 
             
              describe "creating report from csv" do
         | 
| 6 7 |  | 
| 7 8 | 
             
                describe "when setting report attributes" do
         | 
| 8 9 | 
             
                  before :all do
         | 
| 9 | 
            -
                    csv =  | 
| 10 | 
            -
            your_site.com
         | 
| 11 | 
            -
            Top Content,
         | 
| 12 | 
            -
            26 May 2008,31 May 2008
         | 
| 13 | 
            -
            #  | 
| 14 | 
            -
                    @report =  | 
| 10 | 
            +
                    csv = ['# ----------------------------------------',
         | 
| 11 | 
            +
                            'your_site.com',
         | 
| 12 | 
            +
                            'Top Content,',
         | 
| 13 | 
            +
                            '26 May 2008,31 May 2008',
         | 
| 14 | 
            +
                            '# ----------------------------------------']
         | 
| 15 | 
            +
                    @report = Report.new(csv.join("\n"))
         | 
| 15 16 | 
             
                  end
         | 
| 16 17 |  | 
| 17 18 | 
             
                  it "should set base url from second line of text" do
         | 
| @@ -34,12 +35,12 @@ Top Content, | |
| 34 35 | 
             
                describe "when setting report dates" do
         | 
| 35 36 | 
             
                  describe "with source date format 'Month Day, Year'" do
         | 
| 36 37 | 
             
                    before :all do
         | 
| 37 | 
            -
                      csv =  | 
| 38 | 
            -
            your_site.com
         | 
| 39 | 
            -
            Top Content,
         | 
| 40 | 
            -
            "July 28, 2008","August 4, 2008"
         | 
| 41 | 
            -
            #  | 
| 42 | 
            -
                      @report =  | 
| 38 | 
            +
                      csv = ['# ----------------------------------------',
         | 
| 39 | 
            +
                            'your_site.com',
         | 
| 40 | 
            +
                            'Top Content,',
         | 
| 41 | 
            +
                            '"July 28, 2008","August 4, 2008"',
         | 
| 42 | 
            +
                            '# ----------------------------------------']
         | 
| 43 | 
            +
                      @report = Report.new(csv.join("\n"))
         | 
| 43 44 | 
             
                    end
         | 
| 44 45 | 
             
                    it "should set start date from fourth line of text" do
         | 
| 45 46 | 
             
                      @report.start_date.should == Date.parse('28 July 2008')
         | 
| @@ -50,12 +51,12 @@ Top Content, | |
| 50 51 | 
             
                  end
         | 
| 51 52 | 
             
                  describe "with dates badly formatted" do
         | 
| 52 53 | 
             
                    it 'should raise an exception' do
         | 
| 53 | 
            -
                      csv =  | 
| 54 | 
            -
            your_site.com
         | 
| 55 | 
            -
            Top Content,
         | 
| 56 | 
            -
            random something
         | 
| 57 | 
            -
            #  | 
| 58 | 
            -
                      lambda {  | 
| 54 | 
            +
                      csv = ['# ----------------------------------------',
         | 
| 55 | 
            +
                            'your_site.com',
         | 
| 56 | 
            +
                            'Top Content,',
         | 
| 57 | 
            +
                            'random something',
         | 
| 58 | 
            +
                            '# ----------------------------------------']
         | 
| 59 | 
            +
                      lambda { Report.new(csv.join("\n")) }.should raise_error(Exception, 'invalid date: random something')
         | 
| 59 60 | 
             
                    end
         | 
| 60 61 | 
             
                  end
         | 
| 61 62 | 
             
                end
         | 
| @@ -66,28 +67,27 @@ random something | |
| 66 67 | 
             
                    @attributes = %Q|URL,Page Views,Unique Page Views,Time on Page,Bounce Rate,% Exit,$ Index|
         | 
| 67 68 | 
             
                    @values1 = %Q|/,189,157,54.94957983193277,0.4862385392189026,0.37037035822868347,0.0|
         | 
| 68 69 | 
             
                    @values2 = %Q|/bills,60,38,54.17307692307692,0.0,0.13333334028720856,0.0|
         | 
| 69 | 
            -
                    @csv =  | 
| 70 | 
            -
             | 
| 71 | 
            -
            Top Content,
         | 
| 72 | 
            -
            26 May 2008,31 May 2008
         | 
| 73 | 
            -
            # ----------------------------------------
         | 
| 74 | 
            -
            # ----------------------------------------
         | 
| 75 | 
            -
            # Table
         | 
| 76 | 
            -
            # ----------------------------------------
         | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
            # --------------------------------------------------------------------------------
         | 
| 81 | 
            -
            |
         | 
| 70 | 
            +
                    @csv = ['# ----------------------------------------',
         | 
| 71 | 
            +
                            @base_url,
         | 
| 72 | 
            +
                            'Top Content,',
         | 
| 73 | 
            +
                            '26 May 2008,31 May 2008',
         | 
| 74 | 
            +
                            '# ----------------------------------------',
         | 
| 75 | 
            +
                            '# ----------------------------------------',
         | 
| 76 | 
            +
                            '# Table',
         | 
| 77 | 
            +
                            '# ----------------------------------------',
         | 
| 78 | 
            +
                            @attributes,
         | 
| 79 | 
            +
                            @values1,
         | 
| 80 | 
            +
                            @values2,
         | 
| 81 | 
            +
                            '# --------------------------------------------------------------------------------']
         | 
| 82 82 | 
             
                  end
         | 
| 83 83 |  | 
| 84 84 | 
             
                  it 'should create item for each data row in "Table"' do
         | 
| 85 85 | 
             
                    item1 = mock('item1')
         | 
| 86 86 | 
             
                    item2 = mock('item2')
         | 
| 87 | 
            -
                     | 
| 88 | 
            -
                     | 
| 87 | 
            +
                    Item.should_receive(:new).with(@attributes.split(','), @values1.split(','), @base_url).and_return item1
         | 
| 88 | 
            +
                    Item.should_receive(:new).with(@attributes.split(','), @values2.split(','), @base_url).and_return item2
         | 
| 89 89 |  | 
| 90 | 
            -
                    report =  | 
| 90 | 
            +
                    report = Report.new(@csv.join("\n"))
         | 
| 91 91 | 
             
                    report.items.should == [item1, item2]
         | 
| 92 92 | 
             
                  end
         | 
| 93 93 | 
             
                end
         | 
| @@ -99,31 +99,31 @@ Top Content, | |
| 99 99 | 
             
                    @browser_values = %Q|Firefox,1529,0.17185568809509277|
         | 
| 100 100 | 
             
                    @connection_speed_attributes = %Q|Connection Speed,Visits,% visits|
         | 
| 101 101 | 
             
                    @connection_speed_values = %Q|Unknown,3987,0.4481285810470581|
         | 
| 102 | 
            -
                    @csv =  | 
| 103 | 
            -
             | 
| 104 | 
            -
            Visitors Overview,
         | 
| 105 | 
            -
            3 May 2008,2 June 2008
         | 
| 106 | 
            -
            # ----------------------------------------
         | 
| 107 | 
            -
            # ----------------------------------------
         | 
| 108 | 
            -
            # BrowserMiniTable
         | 
| 109 | 
            -
            # ----------------------------------------
         | 
| 110 | 
            -
             | 
| 111 | 
            -
             | 
| 112 | 
            -
             | 
| 113 | 
            -
            # ----------------------------------------
         | 
| 114 | 
            -
            # ConnectionSpeedMiniTable
         | 
| 115 | 
            -
            # ----------------------------------------
         | 
| 116 | 
            -
             | 
| 117 | 
            -
             | 
| 118 | 
            -
            #  | 
| 102 | 
            +
                    @csv = ['# ----------------------------------------',
         | 
| 103 | 
            +
                            @base_url,
         | 
| 104 | 
            +
                            'Visitors Overview',
         | 
| 105 | 
            +
                            '3 May 2008,2 June 2008',
         | 
| 106 | 
            +
                            '# ----------------------------------------',
         | 
| 107 | 
            +
                            '# ----------------------------------------',
         | 
| 108 | 
            +
                            '# BrowserMiniTable',
         | 
| 109 | 
            +
                            '# ----------------------------------------',
         | 
| 110 | 
            +
                            @browser_attributes,
         | 
| 111 | 
            +
                            @browser_values,
         | 
| 112 | 
            +
                            '',
         | 
| 113 | 
            +
                            '# ----------------------------------------',
         | 
| 114 | 
            +
                            '# ConnectionSpeedMiniTable',
         | 
| 115 | 
            +
                            '# ----------------------------------------',
         | 
| 116 | 
            +
                            @connection_speed_attributes,
         | 
| 117 | 
            +
                            @connection_speed_values,
         | 
| 118 | 
            +
                            '# --------------------------------------------------------------------------------']
         | 
| 119 119 | 
             
                  end
         | 
| 120 120 | 
             
                  it 'should create item for each data row in "XxxMiniTable"' do
         | 
| 121 121 | 
             
                    browser_item = mock('browser_item')
         | 
| 122 122 | 
             
                    connection_item = mock('item')
         | 
| 123 | 
            -
                     | 
| 124 | 
            -
                     | 
| 123 | 
            +
                    Item.should_receive(:new).with(@browser_attributes.split(','), @browser_values.split(','), @base_url).and_return browser_item
         | 
| 124 | 
            +
                    Item.should_receive(:new).with(@connection_speed_attributes.split(','), @connection_speed_values.split(','), @base_url).and_return connection_item
         | 
| 125 125 |  | 
| 126 | 
            -
                    report =  | 
| 126 | 
            +
                    report = Report.new(@csv.join("\n"))
         | 
| 127 127 | 
             
                    report.browser_items.should == [browser_item]
         | 
| 128 128 | 
             
                    report.connection_speed_items.should == [connection_item]
         | 
| 129 129 | 
             
                    report.attribute_names.should == ['browser_items', 'connection_speed_items']
         | 
| @@ -131,40 +131,53 @@ Visitors Overview, | |
| 131 131 | 
             
                end
         | 
| 132 132 |  | 
| 133 133 | 
             
                describe "when creating graph points from 'Graph'" do
         | 
| 134 | 
            -
                   | 
| 135 | 
            -
                    @ | 
| 134 | 
            +
                  def graph_correct expected_start, expected_end
         | 
| 135 | 
            +
                    @start_end_dates = "#{@start},#{@end}"
         | 
| 136 136 | 
             
                    @name = %Q|Page Views|
         | 
| 137 | 
            -
                    @ | 
| 138 | 
            -
             | 
| 139 | 
            -
             | 
| 140 | 
            -
             | 
| 141 | 
            -
             | 
| 142 | 
            -
             | 
| 143 | 
            -
            # ----------------------------------------
         | 
| 144 | 
            -
             | 
| 145 | 
            -
            # ----------------------------------------
         | 
| 146 | 
            -
             | 
| 147 | 
            -
             | 
| 148 | 
            -
             | 
| 149 | 
            -
             | 
| 150 | 
            -
             | 
| 151 | 
            -
            433 | 
| 137 | 
            +
                    @csv = ['# ----------------------------------------',
         | 
| 138 | 
            +
                            'your_site.com',
         | 
| 139 | 
            +
                            'Top Content,',
         | 
| 140 | 
            +
                            @start_end_dates,
         | 
| 141 | 
            +
                            '# ----------------------------------------',
         | 
| 142 | 
            +
                            '',
         | 
| 143 | 
            +
                            '# ----------------------------------------',
         | 
| 144 | 
            +
                            '# Graph',
         | 
| 145 | 
            +
                            '# ----------------------------------------',
         | 
| 146 | 
            +
                            @period,
         | 
| 147 | 
            +
                            @name,
         | 
| 148 | 
            +
                            '"5,360"',
         | 
| 149 | 
            +
                            '433']
         | 
| 150 | 
            +
                    graph = mock('graph')
         | 
| 151 | 
            +
                    Graph.should_receive(:new).with(@name, @period, [5360, 433], expected_start, expected_end).and_return graph
         | 
| 152 | 
            +
             | 
| 153 | 
            +
                    report = Report.new(@csv.join("\n"))
         | 
| 154 | 
            +
                    report.pageviews_graph.should == graph
         | 
| 155 | 
            +
                    report.attribute_names.should == ['pageviews_graph']
         | 
| 152 156 | 
             
                  end
         | 
| 153 157 |  | 
| 154 | 
            -
                   | 
| 155 | 
            -
                    graph  | 
| 156 | 
            -
             | 
| 158 | 
            +
                  describe 'with source date format "Month Day, Year"' do
         | 
| 159 | 
            +
                    it 'should create graph with data under "Graph"' do
         | 
| 160 | 
            +
                      @start = %Q|"July 5, 2008"|
         | 
| 161 | 
            +
                      @end = %Q|"August 4, 2008"|
         | 
| 162 | 
            +
                      @period = %Q|"July 5, 2008 - August 4, 2008"|
         | 
| 163 | 
            +
                      graph_correct Date.new(2008,7,5), Date.new(2008,8,4)
         | 
| 164 | 
            +
                    end
         | 
| 165 | 
            +
                  end
         | 
| 157 166 |  | 
| 158 | 
            -
             | 
| 159 | 
            -
                     | 
| 160 | 
            -
             | 
| 167 | 
            +
                  describe "with source date format 'Day Month Year'" do
         | 
| 168 | 
            +
                    it 'should create graph with data under "Graph"' do
         | 
| 169 | 
            +
                      @start = %Q|26 May 2008|
         | 
| 170 | 
            +
                      @end = %Q|31 May 2008|
         | 
| 171 | 
            +
                      @period = %Q|1 May 2008 - 31 May 2008|
         | 
| 172 | 
            +
                      graph_correct Date.parse(@start), Date.parse(@end)
         | 
| 173 | 
            +
                    end
         | 
| 161 174 | 
             
                  end
         | 
| 162 175 | 
             
                end
         | 
| 163 176 | 
             
              end
         | 
| 164 177 |  | 
| 165 178 | 
             
              describe 'when retrieving total using method not defined on class' do
         | 
| 166 179 | 
             
                it 'should return total from graph named in method name' do
         | 
| 167 | 
            -
                  report =  | 
| 180 | 
            +
                  report = Report.new
         | 
| 168 181 | 
             
                  report.should_receive(:respond_to?).with(:page_views_graph).and_return true
         | 
| 169 182 | 
             
                  report.should_receive(:page_views_graph).and_return mock('graph', :sum_of_points=>100)
         | 
| 170 183 | 
             
                  report.method_missing(:page_views_total).should == 100
         | 
| @@ -173,7 +186,7 @@ Top Content, | |
| 173 186 |  | 
| 174 187 | 
             
              describe 'when retrieving list by day using method not defined on class' do
         | 
| 175 188 | 
             
                it 'should return by day list from graph named in method name' do
         | 
| 176 | 
            -
                  report =  | 
| 189 | 
            +
                  report = Report.new
         | 
| 177 190 | 
             
                  report.should_receive(:respond_to?).with(:page_views_graph).and_return true
         | 
| 178 191 | 
             
                  points_by_day = mock('points_by_day')
         | 
| 179 192 | 
             
                  report.should_receive(:page_views_graph).and_return mock('graph', :points_by_day=>points_by_day)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: rugalytics
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.7
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors: 
         | 
| 7 7 | 
             
            - Rob McKinnon
         | 
| @@ -9,7 +9,7 @@ autorequire: | |
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 11 |  | 
| 12 | 
            -
            date: 2008-08- | 
| 12 | 
            +
            date: 2008-08-05 00:00:00 +01:00
         | 
| 13 13 | 
             
            default_executable: 
         | 
| 14 14 | 
             
            dependencies: 
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency 
         |