go_squared 0.0.1
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/.document +5 -0
 - data/Gemfile +13 -0
 - data/Gemfile.lock +20 -0
 - data/LICENSE.txt +20 -0
 - data/README.markdown +119 -0
 - data/Rakefile +55 -0
 - data/VERSION +1 -0
 - data/lib/go_squared/core_extensions.rb +10 -0
 - data/lib/go_squared/trends.rb +92 -0
 - data/lib/go_squared.rb +21 -0
 - data/test/helper.rb +18 -0
 - data/test/test_go_squared.rb +7 -0
 - metadata +133 -0
 
    
        data/.document
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    | 
         @@ -0,0 +1,13 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            source "http://rubygems.org"
         
     | 
| 
      
 2 
     | 
    
         
            +
            # Add dependencies required to use your gem here.
         
     | 
| 
      
 3 
     | 
    
         
            +
            # Example:
         
     | 
| 
      
 4 
     | 
    
         
            +
            #   gem "activesupport", ">= 2.3.5"
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            # Add dependencies to develop your gem here.
         
     | 
| 
      
 7 
     | 
    
         
            +
            # Include everything needed to run rake, tests, features, etc.
         
     | 
| 
      
 8 
     | 
    
         
            +
            group :development do
         
     | 
| 
      
 9 
     | 
    
         
            +
              gem "shoulda", ">= 0"
         
     | 
| 
      
 10 
     | 
    
         
            +
              gem "bundler", "~> 1.0.0"
         
     | 
| 
      
 11 
     | 
    
         
            +
              gem "jeweler", "~> 1.5.2"
         
     | 
| 
      
 12 
     | 
    
         
            +
              gem "rcov", ">= 0"
         
     | 
| 
      
 13 
     | 
    
         
            +
            end
         
     | 
    
        data/Gemfile.lock
    ADDED
    
    | 
         @@ -0,0 +1,20 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            GEM
         
     | 
| 
      
 2 
     | 
    
         
            +
              remote: http://rubygems.org/
         
     | 
| 
      
 3 
     | 
    
         
            +
              specs:
         
     | 
| 
      
 4 
     | 
    
         
            +
                git (1.2.5)
         
     | 
| 
      
 5 
     | 
    
         
            +
                jeweler (1.5.2)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  bundler (~> 1.0.0)
         
     | 
| 
      
 7 
     | 
    
         
            +
                  git (>= 1.2.5)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  rake
         
     | 
| 
      
 9 
     | 
    
         
            +
                rake (0.8.7)
         
     | 
| 
      
 10 
     | 
    
         
            +
                rcov (0.9.9)
         
     | 
| 
      
 11 
     | 
    
         
            +
                shoulda (2.11.3)
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            PLATFORMS
         
     | 
| 
      
 14 
     | 
    
         
            +
              ruby
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            DEPENDENCIES
         
     | 
| 
      
 17 
     | 
    
         
            +
              bundler (~> 1.0.0)
         
     | 
| 
      
 18 
     | 
    
         
            +
              jeweler (~> 1.5.2)
         
     | 
| 
      
 19 
     | 
    
         
            +
              rcov
         
     | 
| 
      
 20 
     | 
    
         
            +
              shoulda
         
     | 
    
        data/LICENSE.txt
    ADDED
    
    | 
         @@ -0,0 +1,20 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            Copyright (c) 2011 Wout Fierens
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            Permission is hereby granted, free of charge, to any person obtaining
         
     | 
| 
      
 4 
     | 
    
         
            +
            a copy of this software and associated documentation files (the
         
     | 
| 
      
 5 
     | 
    
         
            +
            "Software"), to deal in the Software without restriction, including
         
     | 
| 
      
 6 
     | 
    
         
            +
            without limitation the rights to use, copy, modify, merge, publish,
         
     | 
| 
      
 7 
     | 
    
         
            +
            distribute, sublicense, and/or sell copies of the Software, and to
         
     | 
| 
      
 8 
     | 
    
         
            +
            permit persons to whom the Software is furnished to do so, subject to
         
     | 
| 
      
 9 
     | 
    
         
            +
            the following conditions:
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            The above copyright notice and this permission notice shall be
         
     | 
| 
      
 12 
     | 
    
         
            +
            included in all copies or substantial portions of the Software.
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
         
     | 
| 
      
 15 
     | 
    
         
            +
            EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
         
     | 
| 
      
 16 
     | 
    
         
            +
            MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
         
     | 
| 
      
 17 
     | 
    
         
            +
            NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
         
     | 
| 
      
 18 
     | 
    
         
            +
            LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
         
     | 
| 
      
 19 
     | 
    
         
            +
            OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
         
     | 
| 
      
 20 
     | 
    
         
            +
            WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         
     | 
    
        data/README.markdown
    ADDED
    
    | 
         @@ -0,0 +1,119 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # go_squared gem
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            ## What is it?
         
     | 
| 
      
 4 
     | 
    
         
            +
            A Ruby gem wrapping the gosquared.com API.
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            ## Who should use it?
         
     | 
| 
      
 7 
     | 
    
         
            +
            Any Ruby on Rails developer who wants/needs to load trends from GoSquared Statistics.
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            ## Usage
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
            ### Installation
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                gem install go_squared
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
            ### Initialization
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            Initialize the connection for a given site:
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                @gs = GoSquared.new('Your API Key', 'GSN-123456-A')
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
            ### Metrics
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
            To fetch the pageviews metric simply do:
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                @pageviews = @gs.trends.pageviews
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
            All available metrics are:
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            - pageviews _(Total number of pageviews and uniques per unit time)_
         
     | 
| 
      
 32 
     | 
    
         
            +
            - topcontent _(Top performing content)_
         
     | 
| 
      
 33 
     | 
    
         
            +
            - ppv _(Pages per view per unit time)_
         
     | 
| 
      
 34 
     | 
    
         
            +
            - browsers _(Browsers)_
         
     | 
| 
      
 35 
     | 
    
         
            +
            - platforms _(Platforms)_
         
     | 
| 
      
 36 
     | 
    
         
            +
            - referrers _(Referrers)_
         
     | 
| 
      
 37 
     | 
    
         
            +
            - locations _(Locations)_
         
     | 
| 
      
 38 
     | 
    
         
            +
            - languages _(Languages)_
         
     | 
| 
      
 39 
     | 
    
         
            +
            - screens _(Screen sizes)_
         
     | 
| 
      
 40 
     | 
    
         
            +
            - capabilities _(Flash & Java availability)_
         
     | 
| 
      
 41 
     | 
    
         
            +
            - queries _(Search queries)_
         
     | 
| 
      
 42 
     | 
    
         
            +
            - keywords _(Search keywords)_
         
     | 
| 
      
 43 
     | 
    
         
            +
            - nvr _(New vs Returning visitors per unit time)_
         
     | 
| 
      
 44 
     | 
    
         
            +
            - sources _(Organic - search engine - sources)_
         
     | 
| 
      
 45 
     | 
    
         
            +
            - toplanding _(Top landing pages)_
         
     | 
| 
      
 46 
     | 
    
         
            +
            - topexit _(Top exit pages)_
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            ### Method chain
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
            By default trends form one month ago until now are fetched.
         
     | 
| 
      
 52 
     | 
    
         
            +
            To get a custom timeframe:
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                @pageviews = @gs.trends.pageviews.from(14.days.ago).to(7.days.ago)
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
            All chainable methods are:
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
            - from _(defaults to 1.month.ago)_
         
     | 
| 
      
 59 
     | 
    
         
            +
            - to _(defaults to Time.now)_
         
     | 
| 
      
 60 
     | 
    
         
            +
            - period _(last specified period of time - overrides from/to - options are 'day', 'week', 'month' and 'year' - defaults to 'week')_
         
     | 
| 
      
 61 
     | 
    
         
            +
            - timezone _(defaults to 'UTC')_
         
     | 
| 
      
 62 
     | 
    
         
            +
            - group_by _(options are 'day', 'week', 'month' and 'year' - defaults to 'day')_
         
     | 
| 
      
 63 
     | 
    
         
            +
            - limit _(must be an integer - defaults to 30)_
         
     | 
| 
      
 64 
     | 
    
         
            +
             
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
            ### Fetch data
         
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
            Up till now no data has been fetched.
         
     | 
| 
      
 69 
     | 
    
         
            +
            To get the raw XML:
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                @xml = @pageviews.xml
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
            To get an array of ruby Hashes with symbolized keys:
         
     | 
| 
      
 74 
     | 
    
         
            +
             
     | 
| 
      
 75 
     | 
    
         
            +
                @stats = @pageviews.from_xml
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
            The latter will return something like:
         
     | 
| 
      
 78 
     | 
    
         
            +
                
         
     | 
| 
      
 79 
     | 
    
         
            +
                {:hits=>"41", :uniques=>"28", :stat_start=>"1298736000", :time_grouping=>"2011057", :display_time=>"Sat, 26 Feb 11"}
         
     | 
| 
      
 80 
     | 
    
         
            +
                {:hits=>"126", :uniques=>"77", :stat_start=>"1298764800", :time_grouping=>"2011058", :display_time=>"Sun, 27 Feb 11"}
         
     | 
| 
      
 81 
     | 
    
         
            +
                {:hits=>"105", :uniques=>"56", :stat_start=>"1298851200", :time_grouping=>"2011059", :display_time=>"Mon, 28 Feb 11"}
         
     | 
| 
      
 82 
     | 
    
         
            +
                ...
         
     | 
| 
      
 83 
     | 
    
         
            +
             
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
            ## Important
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
      
 87 
     | 
    
         
            +
            This gem is written for Rails 3.
         
     | 
| 
      
 88 
     | 
    
         
            +
            Rails 2 might work but it's not tested.
         
     | 
| 
      
 89 
     | 
    
         
            +
             
     | 
| 
      
 90 
     | 
    
         
            +
            Note that this gem is still under development.
         
     | 
| 
      
 91 
     | 
    
         
            +
            It only covers the trends section of the gosquared.com API.
         
     | 
| 
      
 92 
     | 
    
         
            +
             
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
            ## Contributing to go_squared
         
     | 
| 
      
 95 
     | 
    
         
            +
             
         
     | 
| 
      
 96 
     | 
    
         
            +
            * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
         
     | 
| 
      
 97 
     | 
    
         
            +
            * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
         
     | 
| 
      
 98 
     | 
    
         
            +
            * Fork the project
         
     | 
| 
      
 99 
     | 
    
         
            +
            * Start a feature/bugfix branch
         
     | 
| 
      
 100 
     | 
    
         
            +
            * Commit and push until you are happy with your contribution
         
     | 
| 
      
 101 
     | 
    
         
            +
            * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
         
     | 
| 
      
 102 
     | 
    
         
            +
            * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
            ## Copyright
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
            Copyright (c) 2011 Wout Fierens. See LICENSE.txt for
         
     | 
| 
      
 107 
     | 
    
         
            +
            further details.
         
     | 
| 
      
 108 
     | 
    
         
            +
             
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
             
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
             
     | 
| 
      
 117 
     | 
    
         
            +
             
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
             
     | 
    
        data/Rakefile
    ADDED
    
    | 
         @@ -0,0 +1,55 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'rubygems'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'bundler'
         
     | 
| 
      
 3 
     | 
    
         
            +
            begin
         
     | 
| 
      
 4 
     | 
    
         
            +
              Bundler.setup(:default, :development)
         
     | 
| 
      
 5 
     | 
    
         
            +
            rescue Bundler::BundlerError => e
         
     | 
| 
      
 6 
     | 
    
         
            +
              $stderr.puts e.message
         
     | 
| 
      
 7 
     | 
    
         
            +
              $stderr.puts "Run `bundle install` to install missing gems"
         
     | 
| 
      
 8 
     | 
    
         
            +
              exit e.status_code
         
     | 
| 
      
 9 
     | 
    
         
            +
            end
         
     | 
| 
      
 10 
     | 
    
         
            +
            require 'rake'
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            require 'jeweler'
         
     | 
| 
      
 13 
     | 
    
         
            +
            Jeweler::Tasks.new do |gem|
         
     | 
| 
      
 14 
     | 
    
         
            +
              # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
         
     | 
| 
      
 15 
     | 
    
         
            +
              gem.name = "go_squared"
         
     | 
| 
      
 16 
     | 
    
         
            +
              gem.homepage = "http://github.com/wout/go_squared"
         
     | 
| 
      
 17 
     | 
    
         
            +
              gem.license = "MIT"
         
     | 
| 
      
 18 
     | 
    
         
            +
              gem.summary = %Q{A ruby wrapper for the GoSquared API }
         
     | 
| 
      
 19 
     | 
    
         
            +
              gem.description = %Q{Currently only the trends part is covered}
         
     | 
| 
      
 20 
     | 
    
         
            +
              gem.email = "wout@boysabroad.com"
         
     | 
| 
      
 21 
     | 
    
         
            +
              gem.authors = ["Wout Fierens"]
         
     | 
| 
      
 22 
     | 
    
         
            +
              # Include your dependencies below. Runtime dependencies are required when using your gem,
         
     | 
| 
      
 23 
     | 
    
         
            +
              # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
         
     | 
| 
      
 24 
     | 
    
         
            +
              #  gem.add_runtime_dependency 'jabber4r', '> 0.1'
         
     | 
| 
      
 25 
     | 
    
         
            +
              #  gem.add_development_dependency 'rspec', '> 1.2.3'
         
     | 
| 
      
 26 
     | 
    
         
            +
              
         
     | 
| 
      
 27 
     | 
    
         
            +
              #gem.add_dependency 'active_support', '>= 2.0.0'
         
     | 
| 
      
 28 
     | 
    
         
            +
            end
         
     | 
| 
      
 29 
     | 
    
         
            +
            Jeweler::RubygemsDotOrgTasks.new
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            require 'rake/testtask'
         
     | 
| 
      
 32 
     | 
    
         
            +
            Rake::TestTask.new(:test) do |test|
         
     | 
| 
      
 33 
     | 
    
         
            +
              test.libs << 'lib' << 'test'
         
     | 
| 
      
 34 
     | 
    
         
            +
              test.pattern = 'test/**/test_*.rb'
         
     | 
| 
      
 35 
     | 
    
         
            +
              test.verbose = true
         
     | 
| 
      
 36 
     | 
    
         
            +
            end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            require 'rcov/rcovtask'
         
     | 
| 
      
 39 
     | 
    
         
            +
            Rcov::RcovTask.new do |test|
         
     | 
| 
      
 40 
     | 
    
         
            +
              test.libs << 'test'
         
     | 
| 
      
 41 
     | 
    
         
            +
              test.pattern = 'test/**/test_*.rb'
         
     | 
| 
      
 42 
     | 
    
         
            +
              test.verbose = true
         
     | 
| 
      
 43 
     | 
    
         
            +
            end
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
            task :default => :test
         
     | 
| 
      
 46 
     | 
    
         
            +
             
     | 
| 
      
 47 
     | 
    
         
            +
            require 'rake/rdoctask'
         
     | 
| 
      
 48 
     | 
    
         
            +
            Rake::RDocTask.new do |rdoc|
         
     | 
| 
      
 49 
     | 
    
         
            +
              version = File.exist?('VERSION') ? File.read('VERSION') : ""
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
              rdoc.rdoc_dir = 'rdoc'
         
     | 
| 
      
 52 
     | 
    
         
            +
              rdoc.title = "go_squared #{version}"
         
     | 
| 
      
 53 
     | 
    
         
            +
              rdoc.rdoc_files.include('README*')
         
     | 
| 
      
 54 
     | 
    
         
            +
              rdoc.rdoc_files.include('lib/**/*.rb')
         
     | 
| 
      
 55 
     | 
    
         
            +
            end
         
     | 
    
        data/VERSION
    ADDED
    
    | 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            0.0.1
         
     | 
| 
         @@ -0,0 +1,10 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class Hash
         
     | 
| 
      
 2 
     | 
    
         
            +
              def recursive_symbolize_keys!
         
     | 
| 
      
 3 
     | 
    
         
            +
                symbolize_keys!
         
     | 
| 
      
 4 
     | 
    
         
            +
                # symbolize each hash in .values
         
     | 
| 
      
 5 
     | 
    
         
            +
                values.each{|h| h.recursive_symbolize_keys! if h.is_a?(Hash) }
         
     | 
| 
      
 6 
     | 
    
         
            +
                # symbolize each hash inside an array in .values
         
     | 
| 
      
 7 
     | 
    
         
            +
                values.select{|v| v.is_a?(Array) }.flatten.each{|h| h.recursive_symbolize_keys! if h.is_a?(Hash) }
         
     | 
| 
      
 8 
     | 
    
         
            +
                self
         
     | 
| 
      
 9 
     | 
    
         
            +
              end
         
     | 
| 
      
 10 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,92 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            class GoSquared
         
     | 
| 
      
 2 
     | 
    
         
            +
              class Trends
         
     | 
| 
      
 3 
     | 
    
         
            +
                METRICS = %w(pageviews topcontent ppv browsers platforms referrers locations languages screens capabilities queries keywords nvr sources toplanding topexit)
         
     | 
| 
      
 4 
     | 
    
         
            +
                
         
     | 
| 
      
 5 
     | 
    
         
            +
                def initialize api_key, site_id
         
     | 
| 
      
 6 
     | 
    
         
            +
                  @api_key  = api_key
         
     | 
| 
      
 7 
     | 
    
         
            +
                  @site_id  = site_id
         
     | 
| 
      
 8 
     | 
    
         
            +
                  
         
     | 
| 
      
 9 
     | 
    
         
            +
                  @start    = 1.month.ago.to_i
         
     | 
| 
      
 10 
     | 
    
         
            +
                  @end      = Time.now.to_i
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @metric   = :pageviews
         
     | 
| 
      
 12 
     | 
    
         
            +
                  @group    = :day
         
     | 
| 
      
 13 
     | 
    
         
            +
                end
         
     | 
| 
      
 14 
     | 
    
         
            +
                
         
     | 
| 
      
 15 
     | 
    
         
            +
                METRICS.each do |metric|
         
     | 
| 
      
 16 
     | 
    
         
            +
                  define_method metric do
         
     | 
| 
      
 17 
     | 
    
         
            +
                    self.on(metric)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
                
         
     | 
| 
      
 21 
     | 
    
         
            +
                def on metric
         
     | 
| 
      
 22 
     | 
    
         
            +
                  @metric = metric.to_sym
         
     | 
| 
      
 23 
     | 
    
         
            +
                  self
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
                
         
     | 
| 
      
 26 
     | 
    
         
            +
                def from time
         
     | 
| 
      
 27 
     | 
    
         
            +
                  @start = time.to_i
         
     | 
| 
      
 28 
     | 
    
         
            +
                  self
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
                
         
     | 
| 
      
 31 
     | 
    
         
            +
                def to time
         
     | 
| 
      
 32 
     | 
    
         
            +
                  @end = time.to_i
         
     | 
| 
      
 33 
     | 
    
         
            +
                  self
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
                
         
     | 
| 
      
 36 
     | 
    
         
            +
                def timezone value
         
     | 
| 
      
 37 
     | 
    
         
            +
                  @timezone = value
         
     | 
| 
      
 38 
     | 
    
         
            +
                  self
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
                
         
     | 
| 
      
 41 
     | 
    
         
            +
                def group_by group
         
     | 
| 
      
 42 
     | 
    
         
            +
                  @group = group.to_sym
         
     | 
| 
      
 43 
     | 
    
         
            +
                  self
         
     | 
| 
      
 44 
     | 
    
         
            +
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
                
         
     | 
| 
      
 46 
     | 
    
         
            +
                def limit value
         
     | 
| 
      
 47 
     | 
    
         
            +
                  @limit = value
         
     | 
| 
      
 48 
     | 
    
         
            +
                  self
         
     | 
| 
      
 49 
     | 
    
         
            +
                end
         
     | 
| 
      
 50 
     | 
    
         
            +
                
         
     | 
| 
      
 51 
     | 
    
         
            +
                def period value
         
     | 
| 
      
 52 
     | 
    
         
            +
                  @period = value
         
     | 
| 
      
 53 
     | 
    
         
            +
                  self
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
                
         
     | 
| 
      
 56 
     | 
    
         
            +
                def xml
         
     | 
| 
      
 57 
     | 
    
         
            +
                  fetch
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
                
         
     | 
| 
      
 60 
     | 
    
         
            +
                def from_xml
         
     | 
| 
      
 61 
     | 
    
         
            +
                  hash = Hash.from_xml(xml)
         
     | 
| 
      
 62 
     | 
    
         
            +
                  
         
     | 
| 
      
 63 
     | 
    
         
            +
                  hash.recursive_symbolize_keys!
         
     | 
| 
      
 64 
     | 
    
         
            +
                  
         
     | 
| 
      
 65 
     | 
    
         
            +
                  hash[:data][@group].blank? ? hash[:data] : hash[:data][@group]
         
     | 
| 
      
 66 
     | 
    
         
            +
                end
         
     | 
| 
      
 67 
     | 
    
         
            +
                
         
     | 
| 
      
 68 
     | 
    
         
            +
                private
         
     | 
| 
      
 69 
     | 
    
         
            +
                  
         
     | 
| 
      
 70 
     | 
    
         
            +
                  def fetch
         
     | 
| 
      
 71 
     | 
    
         
            +
                    res = Net::HTTP.start('api.gosquared.com') do |http|
         
     | 
| 
      
 72 
     | 
    
         
            +
                      params = []
         
     | 
| 
      
 73 
     | 
    
         
            +
                      params << "api_key=#{ @api_key }"
         
     | 
| 
      
 74 
     | 
    
         
            +
                      params << "sid=#{ @site_id }"
         
     | 
| 
      
 75 
     | 
    
         
            +
                      params << "metric=#{ @metric }"
         
     | 
| 
      
 76 
     | 
    
         
            +
                      params << "start=#{ @start }"
         
     | 
| 
      
 77 
     | 
    
         
            +
                      params << "end=#{ @end }"
         
     | 
| 
      
 78 
     | 
    
         
            +
                      params << "grouping=#{ @group }"    if @group
         
     | 
| 
      
 79 
     | 
    
         
            +
                      params << "limit=#{ @limit }"       if @limit
         
     | 
| 
      
 80 
     | 
    
         
            +
                      params << "period=#{ @period }"     if @period
         
     | 
| 
      
 81 
     | 
    
         
            +
                      params << "timezone=#{ @timezone }" if @timezone
         
     | 
| 
      
 82 
     | 
    
         
            +
                      
         
     | 
| 
      
 83 
     | 
    
         
            +
                      http.get("/trends.xml?#{ params.join('&') }")
         
     | 
| 
      
 84 
     | 
    
         
            +
                    end
         
     | 
| 
      
 85 
     | 
    
         
            +
                    
         
     | 
| 
      
 86 
     | 
    
         
            +
                    res.body
         
     | 
| 
      
 87 
     | 
    
         
            +
                  rescue e
         
     | 
| 
      
 88 
     | 
    
         
            +
                    "<data><error>#{ e }</error></data>"
         
     | 
| 
      
 89 
     | 
    
         
            +
                  end
         
     | 
| 
      
 90 
     | 
    
         
            +
                
         
     | 
| 
      
 91 
     | 
    
         
            +
              end
         
     | 
| 
      
 92 
     | 
    
         
            +
            end
         
     | 
    
        data/lib/go_squared.rb
    ADDED
    
    | 
         @@ -0,0 +1,21 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'net/http'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'active_support/core_ext/hash/conversions'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            require 'go_squared/core_extensions'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require 'go_squared/trends'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            $:.unshift(File.dirname(__FILE__)) unless
         
     | 
| 
      
 8 
     | 
    
         
            +
              $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            class GoSquared
         
     | 
| 
      
 11 
     | 
    
         
            +
              
         
     | 
| 
      
 12 
     | 
    
         
            +
              def initialize api_key, site_id
         
     | 
| 
      
 13 
     | 
    
         
            +
                @api_key = api_key
         
     | 
| 
      
 14 
     | 
    
         
            +
                @site_id = site_id
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
              
         
     | 
| 
      
 17 
     | 
    
         
            +
              def trends
         
     | 
| 
      
 18 
     | 
    
         
            +
                GoSquared::Trends.new(@api_key, @site_id)
         
     | 
| 
      
 19 
     | 
    
         
            +
              end
         
     | 
| 
      
 20 
     | 
    
         
            +
              
         
     | 
| 
      
 21 
     | 
    
         
            +
            end
         
     | 
    
        data/test/helper.rb
    ADDED
    
    | 
         @@ -0,0 +1,18 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'rubygems'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'bundler'
         
     | 
| 
      
 3 
     | 
    
         
            +
            begin
         
     | 
| 
      
 4 
     | 
    
         
            +
              Bundler.setup(:default, :development)
         
     | 
| 
      
 5 
     | 
    
         
            +
            rescue Bundler::BundlerError => e
         
     | 
| 
      
 6 
     | 
    
         
            +
              $stderr.puts e.message
         
     | 
| 
      
 7 
     | 
    
         
            +
              $stderr.puts "Run `bundle install` to install missing gems"
         
     | 
| 
      
 8 
     | 
    
         
            +
              exit e.status_code
         
     | 
| 
      
 9 
     | 
    
         
            +
            end
         
     | 
| 
      
 10 
     | 
    
         
            +
            require 'test/unit'
         
     | 
| 
      
 11 
     | 
    
         
            +
            require 'shoulda'
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
         
     | 
| 
      
 14 
     | 
    
         
            +
            $LOAD_PATH.unshift(File.dirname(__FILE__))
         
     | 
| 
      
 15 
     | 
    
         
            +
            require 'go_squared'
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            class Test::Unit::TestCase
         
     | 
| 
      
 18 
     | 
    
         
            +
            end
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,133 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification 
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: go_squared
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version 
         
     | 
| 
      
 4 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 5 
     | 
    
         
            +
              segments: 
         
     | 
| 
      
 6 
     | 
    
         
            +
              - 0
         
     | 
| 
      
 7 
     | 
    
         
            +
              - 0
         
     | 
| 
      
 8 
     | 
    
         
            +
              - 1
         
     | 
| 
      
 9 
     | 
    
         
            +
              version: 0.0.1
         
     | 
| 
      
 10 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 11 
     | 
    
         
            +
            authors: 
         
     | 
| 
      
 12 
     | 
    
         
            +
            - Wout Fierens
         
     | 
| 
      
 13 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 14 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 15 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
            date: 2011-03-13 00:00:00 +00:00
         
     | 
| 
      
 18 
     | 
    
         
            +
            default_executable: 
         
     | 
| 
      
 19 
     | 
    
         
            +
            dependencies: 
         
     | 
| 
      
 20 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 21 
     | 
    
         
            +
              name: shoulda
         
     | 
| 
      
 22 
     | 
    
         
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         
     | 
| 
      
 23 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 24 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 25 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 26 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 27 
     | 
    
         
            +
                    segments: 
         
     | 
| 
      
 28 
     | 
    
         
            +
                    - 0
         
     | 
| 
      
 29 
     | 
    
         
            +
                    version: "0"
         
     | 
| 
      
 30 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 31 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 32 
     | 
    
         
            +
              version_requirements: *id001
         
     | 
| 
      
 33 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 34 
     | 
    
         
            +
              name: bundler
         
     | 
| 
      
 35 
     | 
    
         
            +
              requirement: &id002 !ruby/object:Gem::Requirement 
         
     | 
| 
      
 36 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 37 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 38 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 39 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 40 
     | 
    
         
            +
                    segments: 
         
     | 
| 
      
 41 
     | 
    
         
            +
                    - 1
         
     | 
| 
      
 42 
     | 
    
         
            +
                    - 0
         
     | 
| 
      
 43 
     | 
    
         
            +
                    - 0
         
     | 
| 
      
 44 
     | 
    
         
            +
                    version: 1.0.0
         
     | 
| 
      
 45 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 46 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 47 
     | 
    
         
            +
              version_requirements: *id002
         
     | 
| 
      
 48 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 49 
     | 
    
         
            +
              name: jeweler
         
     | 
| 
      
 50 
     | 
    
         
            +
              requirement: &id003 !ruby/object:Gem::Requirement 
         
     | 
| 
      
 51 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 52 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 53 
     | 
    
         
            +
                - - ~>
         
     | 
| 
      
 54 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 55 
     | 
    
         
            +
                    segments: 
         
     | 
| 
      
 56 
     | 
    
         
            +
                    - 1
         
     | 
| 
      
 57 
     | 
    
         
            +
                    - 5
         
     | 
| 
      
 58 
     | 
    
         
            +
                    - 2
         
     | 
| 
      
 59 
     | 
    
         
            +
                    version: 1.5.2
         
     | 
| 
      
 60 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 61 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 62 
     | 
    
         
            +
              version_requirements: *id003
         
     | 
| 
      
 63 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 64 
     | 
    
         
            +
              name: rcov
         
     | 
| 
      
 65 
     | 
    
         
            +
              requirement: &id004 !ruby/object:Gem::Requirement 
         
     | 
| 
      
 66 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 67 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 68 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 69 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 70 
     | 
    
         
            +
                    segments: 
         
     | 
| 
      
 71 
     | 
    
         
            +
                    - 0
         
     | 
| 
      
 72 
     | 
    
         
            +
                    version: "0"
         
     | 
| 
      
 73 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 74 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 75 
     | 
    
         
            +
              version_requirements: *id004
         
     | 
| 
      
 76 
     | 
    
         
            +
            description: Currently only the trends part is covered
         
     | 
| 
      
 77 
     | 
    
         
            +
            email: wout@boysabroad.com
         
     | 
| 
      
 78 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
            extra_rdoc_files: 
         
     | 
| 
      
 83 
     | 
    
         
            +
            - LICENSE.txt
         
     | 
| 
      
 84 
     | 
    
         
            +
            - README.markdown
         
     | 
| 
      
 85 
     | 
    
         
            +
            files: 
         
     | 
| 
      
 86 
     | 
    
         
            +
            - .document
         
     | 
| 
      
 87 
     | 
    
         
            +
            - Gemfile
         
     | 
| 
      
 88 
     | 
    
         
            +
            - Gemfile.lock
         
     | 
| 
      
 89 
     | 
    
         
            +
            - LICENSE.txt
         
     | 
| 
      
 90 
     | 
    
         
            +
            - README.markdown
         
     | 
| 
      
 91 
     | 
    
         
            +
            - Rakefile
         
     | 
| 
      
 92 
     | 
    
         
            +
            - VERSION
         
     | 
| 
      
 93 
     | 
    
         
            +
            - lib/go_squared.rb
         
     | 
| 
      
 94 
     | 
    
         
            +
            - lib/go_squared/core_extensions.rb
         
     | 
| 
      
 95 
     | 
    
         
            +
            - lib/go_squared/trends.rb
         
     | 
| 
      
 96 
     | 
    
         
            +
            - test/helper.rb
         
     | 
| 
      
 97 
     | 
    
         
            +
            - test/test_go_squared.rb
         
     | 
| 
      
 98 
     | 
    
         
            +
            has_rdoc: true
         
     | 
| 
      
 99 
     | 
    
         
            +
            homepage: http://github.com/wout/go_squared
         
     | 
| 
      
 100 
     | 
    
         
            +
            licenses: 
         
     | 
| 
      
 101 
     | 
    
         
            +
            - MIT
         
     | 
| 
      
 102 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 103 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
            require_paths: 
         
     | 
| 
      
 106 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 107 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 108 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 109 
     | 
    
         
            +
              requirements: 
         
     | 
| 
      
 110 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 111 
     | 
    
         
            +
                - !ruby/object:Gem::Version 
         
     | 
| 
      
 112 
     | 
    
         
            +
                  hash: -3715000075723790159
         
     | 
| 
      
 113 
     | 
    
         
            +
                  segments: 
         
     | 
| 
      
 114 
     | 
    
         
            +
                  - 0
         
     | 
| 
      
 115 
     | 
    
         
            +
                  version: "0"
         
     | 
| 
      
 116 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 117 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 118 
     | 
    
         
            +
              requirements: 
         
     | 
| 
      
 119 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 120 
     | 
    
         
            +
                - !ruby/object:Gem::Version 
         
     | 
| 
      
 121 
     | 
    
         
            +
                  segments: 
         
     | 
| 
      
 122 
     | 
    
         
            +
                  - 0
         
     | 
| 
      
 123 
     | 
    
         
            +
                  version: "0"
         
     | 
| 
      
 124 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 127 
     | 
    
         
            +
            rubygems_version: 1.3.7
         
     | 
| 
      
 128 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 129 
     | 
    
         
            +
            specification_version: 3
         
     | 
| 
      
 130 
     | 
    
         
            +
            summary: A ruby wrapper for the GoSquared API
         
     | 
| 
      
 131 
     | 
    
         
            +
            test_files: 
         
     | 
| 
      
 132 
     | 
    
         
            +
            - test/helper.rb
         
     | 
| 
      
 133 
     | 
    
         
            +
            - test/test_go_squared.rb
         
     |