rack-referrals 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -25,14 +25,38 @@ Example Usage (Rails 3 App)
25
25
 
26
26
  Just add it to your middleware stack:
27
27
 
28
+ # Rails 3 App - in config/application.rb
28
29
  class Application < Rails::Application
29
30
  ...
30
31
  config.middleware.use Rack::Referrals
31
32
  ...
32
33
  end
34
+
35
+ # Rails 2 App - in config/environment.rb
36
+ Rails::Initializer.run do |config|
37
+ ...
38
+ config.middleware.use "Rack::Referrals"
39
+ ...
40
+ end
33
41
 
42
+ Now you can check any request to see what search engine referred it, and if any did, then what search terms were used.
43
+
44
+ class ExampleController < ApplicationController
45
+
46
+ def index
47
+ str = if request.env['referring.search_engine']
48
+ "You're from #{request.env['referring.search_engine']}, " \
49
+ "where you searched: #{request.env['referring.search_terms']}"
50
+ else
51
+ "You're from somewhere boring."
52
+ end
53
+
54
+ render :text => str
55
+ end
56
+
57
+ end
34
58
 
35
- Getting Fancy
59
+ Gettin' Fancy
36
60
  -------------
37
61
 
38
62
  This knows about a number of search engines by default (Google, Yahoo, Bing, some big Russian ones... check the <code>DEFAULT_ENGINES</code> constant in <code>lib/rack-referrals.rb</code> for the current list).
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## 0.0.2 October 7, 2011
4
+ * API CHANGE: replacing *search_phrase* with *search_terms*, since phrase implies it was searched "like so"
5
+
6
+ ## 0.0.1 October 7, 2011
7
+ * Initial functioning version
8
+
@@ -5,7 +5,7 @@ module Rack
5
5
  #
6
6
  # Rack Middleware for extracting information from the HTTP-REFERER header.
7
7
  # Specifically, it populates +env['referring.search_engine']+ and
8
- # +env['referring.search_phrase']+ if it detects a request came from a known
8
+ # +env['referring.search_terms']+ if it detects a request came from a known
9
9
  # search engine.
10
10
  #
11
11
  class Referrals
@@ -54,7 +54,7 @@ module Rack
54
54
  rescue URI::InvalidURIError; nil
55
55
  end
56
56
 
57
- env["referring.search_phrase"] = query_string && Rack::Utils.parse_query(query_string)[param_name]
57
+ env["referring.search_terms"] = query_string && Rack::Utils.parse_query(query_string)[param_name]
58
58
  end
59
59
  end
60
60
 
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Referrals
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -18,21 +18,21 @@ class ReferralTest < MiniTest::Unit::TestCase
18
18
  get '/', nil, 'HTTP_REFERER' => "http://www.google.com/search?q=ruby+on+rails&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a"
19
19
 
20
20
  assert_equal "google", last_request.env['referring.search_engine']
21
- assert_equal "ruby on rails", last_request.env['referring.search_phrase']
21
+ assert_equal "ruby on rails", last_request.env['referring.search_terms']
22
22
  end
23
23
 
24
24
  def test_handles_missing_params
25
25
  get '/', nil, 'HTTP_REFERER' => "http://www.google.com/search?ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a"
26
26
 
27
27
  assert_equal "google", last_request.env['referring.search_engine']
28
- assert_equal nil, last_request.env['referring.search_phrase']
28
+ assert_equal nil, last_request.env['referring.search_terms']
29
29
  end
30
30
 
31
31
  def test_handles_no_referer
32
32
  get '/'
33
33
 
34
34
  assert_equal nil, last_request.env['referring.search_engine']
35
- assert_equal nil, last_request.env['referring.search_phrase']
35
+ assert_equal nil, last_request.env['referring.search_terms']
36
36
  end
37
37
 
38
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-referrals
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-10-07 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
16
- requirement: &70197710584540 !ruby/object:Gem::Requirement
16
+ requirement: &70145645641620 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70197710584540
24
+ version_requirements: *70145645641620
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rack-test
27
- requirement: &70197710583960 !ruby/object:Gem::Requirement
27
+ requirement: &70145645641180 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70197710583960
35
+ version_requirements: *70145645641180
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &70197710583240 !ruby/object:Gem::Requirement
38
+ requirement: &70145645640760 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70197710583240
46
+ version_requirements: *70145645640760
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rack
49
- requirement: &70197710582340 !ruby/object:Gem::Requirement
49
+ requirement: &70145645630860 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *70197710582340
57
+ version_requirements: *70145645630860
58
58
  description: If the user clicked through from a search engine, this middleware will
59
59
  detect the engine used and the terms searched.
60
60
  email:
@@ -67,6 +67,7 @@ files:
67
67
  - Gemfile
68
68
  - README.md
69
69
  - Rakefile
70
+ - history.md
70
71
  - lib/rack-referrals.rb
71
72
  - lib/rack-referrals/version.rb
72
73
  - rack-referrals.gemspec