rack-piwik-0.3.0/0000755000004100000410000000000012352206703013603 5ustar www-datawww-datarack-piwik-0.3.0/lib/0000755000004100000410000000000012352206703014351 5ustar www-datawww-datarack-piwik-0.3.0/lib/rack/0000755000004100000410000000000012352206703015271 5ustar www-datawww-datarack-piwik-0.3.0/lib/rack/piwik.rb0000644000004100000410000000206012352206703016737 0ustar www-datawww-datarequire 'rack' require 'erb' module Rack class Piwik DEFAULT = { :disable_cookies => false } def initialize(app, options = {}) raise ArgumentError, "piwik_url must be present" unless options[:piwik_url] and !options[:piwik_url].empty? raise ArgumentError, "piwik_id must be present" unless options[:piwik_id] and !options[:piwik_id].to_s.empty? @app, @options = app, DEFAULT.merge(options) end def call(env); dup._call(env); end def _call(env) @status, @headers, @response = @app.call(env) return [@status, @headers, @response] unless html? response = Rack::Response.new([], @status, @headers) @response.each { |fragment| response.write inject(fragment) } response.finish end private def html?; @headers['Content-Type'] =~ /html/; end def inject(response) file = 'async' @template ||= ::ERB.new ::File.read ::File.expand_path("../templates/#{file}.erb",__FILE__) response.gsub(%r{}, @template.result(binding) + "") end end end rack-piwik-0.3.0/lib/rack/templates/0000755000004100000410000000000012352206703017267 5ustar www-datawww-datarack-piwik-0.3.0/lib/rack/templates/async.erb0000644000004100000410000000254712352206703021106 0ustar www-datawww-data rack-piwik-0.3.0/lib/rack/templates/sync.erb0000644000004100000410000000236012352206703020736 0ustar www-datawww-data rack-piwik-0.3.0/metadata.yml0000644000004100000410000000233412352206703016110 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: rack-piwik version: !ruby/object:Gem::Version version: 0.3.0 platform: ruby authors: - Maxwell Salzberg autorequire: bindir: bin cert_chain: [] date: 2014-06-01 00:00:00.000000000 Z dependencies: [] description: Simple Rack middleware for implementing Piwik Analytics tracking in your Ruby-Rack based project. email: - maxwell@joindiaspora.com executables: [] extensions: [] extra_rdoc_files: [] files: - LICENSE - README.md - lib/rack/piwik.rb - lib/rack/templates/async.erb - lib/rack/templates/sync.erb - test/helper.rb - test/test_rack_piwik.rb homepage: https://github.com/maxwell/rack-piwik licenses: [] metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.2.2 signing_key: specification_version: 4 summary: Rack middleware to inject the Piwik tracking code into outgoing responses. Adapted from rack-google-analytics test_files: [] has_rdoc: rack-piwik-0.3.0/test/0000755000004100000410000000000012352206703014562 5ustar www-datawww-datarack-piwik-0.3.0/test/helper.rb0000644000004100000410000000151312352206703016366 0ustar www-datawww-datarequire 'rubygems' require 'test/unit' require 'shoulda' require 'rack' require 'rack/test' require File.expand_path('../../lib/rack/piwik',__FILE__) class Test::Unit::TestCase include Rack::Test::Methods def app; Rack::Lint.new(@app); end def mock_app(options) main_app = lambda { |env| request = Rack::Request.new(env) case request.path when '/head_only' then [200,{ 'Content-Type' => 'application/html' },['head only']] when '/arbitrary.xml' then [200,{'Content-Type' => 'application/xml'}, ['xml only']] when '/body_only' then [200,{'Content-Type' => 'application/html'} ,['body only']] else [404,'Nothing here'] end } builder = Rack::Builder.new builder.use Rack::Piwik, options builder.run main_app @app = builder.to_app end end rack-piwik-0.3.0/test/test_rack_piwik.rb0000755000004100000410000000544612352206703020305 0ustar www-datawww-datarequire File.expand_path('../helper',__FILE__) class TestRackPiwik < Test::Unit::TestCase context "Asynchronous" do context "default" do setup { mock_app :async => true, :tracker => 'somebody', :piwik_url => 'piwik.example.org', :piwik_id => '123' } should "add tracker if body element is present" do get "/body_only" assert_match 'http://piwik.example.org/', last_response.body assert_match '_paq.push(["setSiteId", "123"]);', last_response.body assert_match %r{\n}, last_response.body assert_equal 792, last_response.headers['Content-Length'].to_i end should "omit 404 tracking for other responses with other status" do get "/body_only" assert_no_match %r{.setDocumentTitle\('404/URL}, last_response.body end should "omit addition of tracking code for non-html content" do get "/arbitrary.xml" assert_no_match %r{Piwik}, last_response.body assert_match %r{xml only}, last_response.body end should "omit addition of tracking code if tag is missing" do get "/head_only" assert_no_match %r{Piwik}, last_response.body assert_match %r{head only}, last_response.body end should "not disable piwik cookies" do get "/body_only" assert_no_match %r{disableCookies}, last_response.body end end context "disable cookies is true" do setup { mock_app :async => true, :tracker => 'somebody', :piwik_url => 'piwik.example.org', :piwik_id => '123', :disable_cookies => true } should "disable piwik cookies" do get "/body_only" assert_match %r{\_paq\.push\(\[\'disableCookies\'\]\)\;}, last_response.body end end context "with a number as piwik id" do setup { mock_app :async => true, :tracker => 'somebody', :piwik_url => 'piwik.example.org', :piwik_id => 123 } should "not raise an exception" do assert_nothing_raised do get "/body_only" end end end end =begin context "Synchronous" do setup { mock_app :async => false, :tracker => 'somebody', :piwik_url => 'piwik.example.org', :piwik_id => '123' } should "add tracker if body element is present" do get "/body_only" assert_match %r{https://piwik.example.org/}, last_response.body assert_match %r{123\);}, last_response.body assert_match %r{\n}, last_response.body assert_equal "650", last_response.headers['Content-Length'] end should "show non-asynchronous tracker" do get "/bob" assert_match %r{.getTracker}, last_response.body assert_match %r{}, last_response.body assert_match %r{\"whatthe\"}, last_response.body end end =end end rack-piwik-0.3.0/LICENSE0000644000004100000410000000203712352206703014612 0ustar www-datawww-dataCopyright (c) 2009 Lee Hambley Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. rack-piwik-0.3.0/checksums.yaml.gz0000444000004100000410000000041512352206703017071 0ustar www-datawww-data/Se)[ADN յu 3 j525pL3|<_??y_]BW^0)iJx J]/.{i EN5&g_ʰ=HK.0$8Oq B ;,ל*Ĭn2ҏZq6xm=HRҎjUO1ָj9YQ* ye{VLo^fWq9■u$hi.NvH>1rack-piwik-0.3.0/README.md0000644000004100000410000000354212352206703015066 0ustar www-datawww-data# Rack Piwik Adapted from Rack::Piwik Simple Rack middleware to help injecting the Piwik tracking code into the footer of your websites. ## Usage #### Gemfile: gem 'rack-piwik', :require => 'rack/piwik' #### Sinatra ## app.rb use Rack::Piwik, :piwik_url => '', :piwik_id => '', :disable_cookies => true/false #### Padrino ## app/app.rb use Rack::Piwik, :piwik_url => '', :piwik_id => '', :disable_cookies => true/false #### Rails ## application.rb: config.gem 'rack-piwik', :lib => 'rack/piwik' config.middleware.use Rack::Piwik, :piwik_url => '', :piwik_id => '', :disable_cookies => true/false ## Thread Safety This middleware *should* be thread safe. Although my experience in such areas is limited, having taken the advice of those with more experience; I defer the call to a shallow copy of the environment, if this is of consequence to you please review the implementation. ## Change Log * 0.2.0 Use asynchronous JS tracking code by default * 0.1.0 Initial Release ## Note on Patches/Pull Requests * Fork the project. * Make your feature addition or bug fix. * Add tests for it. This is important so I don't break it in a future version unintentionally. * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull) * Send me a pull request. Bonus points for topic branches. ## Copyright Copyright (c) 2009-2011 Lee Hambley. See LICENSE for details. With thanks to Ralph von der Heyden http://github.com/ralph/ and Simon `cimm` Schoeters http://github.com/cimm/ - And the biggest hand to Arthur `achiu` Chiu for the huge work that went into the massive 0.9 re-factor.