tophold_rack 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ .rvmrc
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
data/Gemfile CHANGED
@@ -6,4 +6,8 @@ gem 'rack'
6
6
 
7
7
  gem 'devise'
8
8
 
9
+ gem 'redis'
10
+
11
+ gem 'redis-namespace'
12
+
9
13
  gemspec
@@ -43,8 +43,12 @@ Rails.configuration.tophold_rack_devise_scope = "user"
43
43
  #customize this to meet your requirments.
44
44
  Rails.configuration.tophold_rack_request_black_list << "admin"
45
45
 
46
- #3rd party tracking url
47
- Rails.configuration.tophold_rack_tracking_url = "http://localhost:8888/tracking/"
46
+ #track redis settings
47
+ redis = Redis.new host: "127.0.0.1", port: 6379
48
+ space = Redis::Namespace.new 'st', redis: redis
49
+ Rails.configuration.tophold_statistics_redis = space
50
+
51
+ Rails.configuration.tophold_statistics_queue = "static"
48
52
 
49
53
  #if Rails.env.development?
50
54
  # Rails.configuration.tophold_rack_disabled = true
@@ -6,9 +6,15 @@ module TopholdRack
6
6
 
7
7
  config.tophold_rack_request_black_list = ["uploads", "assets"]
8
8
 
9
- config.tophold_rack_tracking_url = "http://localhost:8888/tracking/"
10
-
11
9
  config.tophold_rack_disabled = false
10
+
11
+ redis = Redis.new host: "127.0.0.1", port: 6379
12
+
13
+ nspace = Redis::Namespace.new 'st', redis: redis
14
+
15
+ config.tophold_statistics_redis = nspace
16
+
17
+ config.tophold_statistics_queue = "static"
12
18
 
13
19
  initializer "tophold_rack.load_app_instance_data" do |app|
14
20
  TopholdRack.setup do |config|
@@ -7,6 +7,7 @@ module TopholdRack
7
7
 
8
8
  def initialize app
9
9
  @app = app
10
+ @redis = Rails.configuration.tophold_statistics_redis
10
11
  end
11
12
 
12
13
  def request_black_list
@@ -18,12 +19,18 @@ module TopholdRack
18
19
  request = Rack::Request.new env
19
20
  if request.get?
20
21
  path, query = request.path, request.query_string
21
- scope = env["rack.session"]["warden.user.#{Rails.configuration.tophold_rack_devise_scope}.key"]
22
- user_id = scope ? scope[1][0] : nil
23
- unless path =~ request_black_list
24
- str = "#{path.blank? ? '/' : path}?query=#{query}&user_id=#{user_id}"
25
- url = Rails.configuration.tophold_rack_tracking_url+"?request_url=#{CGI.escape str}"
26
- open url
22
+ if scope = env["rack.session"]["warden.user.#{Rails.configuration.tophold_rack_devise_scope}.key"]
23
+ user_id = scope[1][0].to_s =~ /\d+/ ? scope[1][0] : scope[0][0]
24
+ else
25
+ user_id = nil
26
+ end
27
+ unless path =~ request_black_list
28
+ begin
29
+ @redis.lpush(Rails.configuration.tophold_statistics_queue,{user_id: user_id, url: path, visited_date: Date.today}.to_json)
30
+ rescue Exception => e
31
+ raise e
32
+ Rails.logger.fatal 'RedisDispatcher can not work!'
33
+ end
27
34
  end
28
35
  end
29
36
  end
@@ -1,3 +1,3 @@
1
1
  module TopholdRack
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/tophold_rack.rb CHANGED
@@ -1,4 +1,6 @@
1
1
  require "tophold_rack/version"
2
+ require "redis"
3
+ require "redis-namespace"
2
4
 
3
5
  module TopholdRack
4
6
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tophold_rack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-30 00:00:00.000000000 Z
12
+ date: 2013-08-19 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A rack based middleware to redispatch requested uri path to 3rd party
15
15
  tracking server
@@ -20,7 +20,6 @@ extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
22
  - .gitignore
23
- - .rvmrc
24
23
  - Gemfile
25
24
  - LICENSE.txt
26
25
  - README.md
@@ -52,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
51
  version: '0'
53
52
  requirements: []
54
53
  rubyforge_project:
55
- rubygems_version: 1.8.24
54
+ rubygems_version: 1.8.25
56
55
  signing_key:
57
56
  specification_version: 3
58
57
  summary: A rack based middleware to redispatch requested uri path to 3rd party tracking
data/.rvmrc DELETED
@@ -1 +0,0 @@
1
- rvm use ruby-1.9.3-p362@tophold_rack