rangefinder-sst 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d2b4c5d33bedad8ec844bd51febbb5e2c87dd6d
4
- data.tar.gz: f7b77be8d09faa1e49cf1158add16685cfccedc0
3
+ metadata.gz: 4156abf190f6a06596e6ac45e053c78b5ab852c6
4
+ data.tar.gz: b04560ac65e006f6ce0504c825780b7e98dea171
5
5
  SHA512:
6
- metadata.gz: 5232414d64f9d3d4b970629dcc250a7bba531341ee42b25cbea0011821e45768f9fa3ce831a27fcfd50333d6f17ff74123fc127cb8eaa106e2b1213aa884436b
7
- data.tar.gz: 9d7d58355ea39aa72956038d122510217d106ffd085bec398fb2be9e8392b24af315f200976acbbf5b0445843e2ed5a9968aab8a9054939af12ba0b5137f64b5
6
+ metadata.gz: 1d79e175fd4e44ad7c9c8ab8c50fce56ab2f29384898a0f2e200662a50ef366210f0e047c37f7b4db6c4933201143a728b85321c0539e34a48d0b370bf6c07d2
7
+ data.tar.gz: bbecffbe860c351463184d7b0626f6cb622061ebd48649044b2c0cf1588d47f7bc1fa35ce6e4f4a80168f2fa36a2e5a180eb62f814d3314a01edd62ea4a814e7
data/example/rack.ru ADDED
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'sinatra'
3
+ require 'rangefinder/sst'
4
+ require 'rangefinder/sst/rack'
5
+
6
+ class MyApp < Sinatra::Base
7
+ get '/' do
8
+ '<html><body>Hello world!</body></html>'
9
+ end
10
+ end
11
+
12
+ use Rangefinder::SST::Rack, :site_id => 4
13
+ run MyApp
@@ -0,0 +1,48 @@
1
+ module Rangefinder
2
+ class SST
3
+ class Rack
4
+ def initialize(app, config = {})
5
+ @app = app
6
+ @autoinject = config[:autoinject].nil? ? true : config[:autoinject]
7
+ # Pass config on to the SST instance.
8
+ @sst = Rangefinder::SST.new config
9
+ end
10
+
11
+ def code
12
+ @sst.code
13
+ end
14
+
15
+ def call(env)
16
+ env['rangefinder'] = self
17
+ @sst.track(
18
+ :page => env['REQUEST_URI'],
19
+ :referrer => env['HTTP_REFERER'],
20
+ :user_agent => env['HTTP_USER_AGENT'],
21
+ :ipv4 => env['REMOTE_ADDR']
22
+ )
23
+ unless @autoinject
24
+ # Don't do all the work if you don't need to.
25
+ return @app.call(env)
26
+ else
27
+ status, headers, body = @app.call(env)
28
+ # If there's a content-type and it doesn't have "text/html" in it then just return
29
+ if !headers['Content-Type'].nil? && headers['Content-Type'].index('text/html') == false
30
+ return [status, headers, body]
31
+ end
32
+ # Build a new response
33
+ response = ::Rack::Response.new([], status, headers)
34
+ body.each do |b|
35
+ # Rebuild the response body part by part
36
+ body_close = b.rindex(/<\/body[^>]*>/i)
37
+ unless body_close.nil?
38
+ # Insert the code before the closing body tag
39
+ b.insert body_close, "\n"+@sst.code
40
+ end
41
+ response.write b
42
+ end
43
+ response.finish
44
+ end
45
+ end#call(env)
46
+ end#Rack
47
+ end#SST
48
+ end#Rangefinder
@@ -1,5 +1,5 @@
1
1
  module Rangefinder
2
2
  class SST
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rangefinder-sst
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dirk Gadsden
@@ -92,7 +92,9 @@ files:
92
92
  - LICENSE
93
93
  - README.md
94
94
  - Rakefile
95
+ - example/rack.ru
95
96
  - lib/rangefinder/sst.rb
97
+ - lib/rangefinder/sst/rack.rb
96
98
  - lib/rangefinder/sst/version.rb
97
99
  - rangefinder-sst.gemspec
98
100
  homepage: http://rangefinderapp.com