pathways 0.0.4 → 0.0.5

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.
@@ -26,7 +26,8 @@ module Pathways
26
26
  next unless timestamp = line.match( /^PathwaysTracker\:(.*)/)
27
27
  visit_hash = JSON.parse(timestamp[1].to_s)
28
28
 
29
- session = Pathways::Session.find_or_create_by_ip_and_state(visit_hash["ip"], :active)
29
+ session = Pathways::Session.find_or_create_by_client_id_and_state(visit_hash["client_id"], :active)
30
+ session.update_attributes(:user_id => visit_hash["user_id"], :iteration => visit_hash["iteration"])
30
31
 
31
32
  updated_at = Time.parse(visit_hash["created_at"]).to_i
32
33
  next if most_recent_session_updated_at and updated_at < most_recent_session_updated_at
@@ -41,7 +42,8 @@ module Pathways
41
42
  if time_since_last_visit > 600
42
43
  session.state = :closed
43
44
  session.save
44
- session = Pathways::Session.find_or_create_by_ip_and_state(visit_hash["ip"], :active)
45
+ session = Pathways::Session.find_or_create_by_client_id_and_state(visit_hash["client_id"], :active)
46
+ session.update_attributes(:user_id => visit_hash["user_id"], :iteration => visit_hash["iteration"])
45
47
  session.created_at = updated_at
46
48
  end
47
49
  last_visit.time_active = (time_since_last_visit > 60) ? 60 : time_since_last_visit
@@ -2,6 +2,8 @@ module Pathways
2
2
  class Session
3
3
  include MongoMapper::Document
4
4
 
5
+ key :client_id, String
6
+ key :iteration, String
5
7
  key :ip, String
6
8
  key :state, String
7
9
  key :user_id, Integer
@@ -68,6 +70,21 @@ module Pathways
68
70
  end
69
71
  end
70
72
 
73
+ def self.find_by_path(path,opts={})
74
+ opts.merge!({
75
+ :out => {:inline => true},
76
+ :raw => true
77
+ })
78
+ results = self.finder_build(opts).find()
79
+ sessions = []
80
+ results.to_a.first.last.each do | result |
81
+ id = result["_id"]
82
+ next unless id == path
83
+ sessions = Pathways::Session.find_all_by_id(result["value"]["sessions"].try(:uniq))
84
+ end
85
+ return sessions
86
+ end
87
+
71
88
  def self.popular_pages(opts={})
72
89
  opts.merge!({
73
90
  :out => {:inline => true},
@@ -1,6 +1,18 @@
1
1
  module Pathways
2
2
  module Tracker
3
+
4
+ mattr_accessor :iteration
5
+
3
6
  def log_visit
7
+
8
+ unless client_id = cookies[:pathways_token]
9
+ client_id = Digest::MD5.hexdigest("#{request.ip}:#{Time.now}")
10
+ cookies[:pathways_token] = {
11
+ :value => client_id,
12
+ :expires => 20.years.from_now.utc
13
+ }
14
+ end
15
+
4
16
  Rails.logger.info "PathwaysTracker:" << { :url => request.url,
5
17
  :request_method => request.method,
6
18
  :path => request.request_uri,
@@ -8,7 +20,9 @@ module Pathways
8
20
  :action => action_name,
9
21
  :params => params,
10
22
  :ip => request.ip,
23
+ :client_id => client_id,
11
24
  :created_at => Time.now,
25
+ :iteration => Pathways::Tracker.iteration,
12
26
  :user_id => (current_user) ? current_user.id : nil}.to_json
13
27
  end
14
28
  end
@@ -1,3 +1,3 @@
1
1
  module Pathways
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/pathways.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.email = ["hello@mintdigital.com","min.sucks@gmail.com"]
10
10
  s.homepage = "http://rubygems.org/gems/pathways"
11
11
  s.summary = "Helps your track the pathways in your Rails app."
12
- s.description = "Helps your track the pathways in your app so that you can pave the cowpaths."
12
+ s.description = "Helps your track the pathways in your app so that you can pave the cowpaths. Uses MongoDB to traverse the paths looking for little nuggets."
13
13
 
14
14
  s.required_rubygems_version = ">= 1.3.6"
15
15
  s.rubyforge_project = "pathways"
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pathways
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mint Digital
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-08-31 00:00:00 +01:00
19
+ date: 2011-09-02 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -97,7 +97,7 @@ dependencies:
97
97
  version: "0"
98
98
  type: :runtime
99
99
  version_requirements: *id005
100
- description: Helps your track the pathways in your app so that you can pave the cowpaths.
100
+ description: Helps your track the pathways in your app so that you can pave the cowpaths. Uses MongoDB to traverse the paths looking for little nuggets.
101
101
  email:
102
102
  - hello@mintdigital.com
103
103
  - min.sucks@gmail.com