rangefinder-sst 0.1.0 → 0.1.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.
- checksums.yaml +4 -4
- data/example/rack.ru +13 -0
- data/lib/rangefinder/sst/rack.rb +48 -0
- data/lib/rangefinder/sst/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4156abf190f6a06596e6ac45e053c78b5ab852c6
|
4
|
+
data.tar.gz: b04560ac65e006f6ce0504c825780b7e98dea171
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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.
|
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
|