Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updating to 0.0.6

  • Loading branch information...
commit 10199e210780a464a2c4505b44e63ff4bc74f518 1 parent e38b19a
Simon Reed authored
View
6 lib/pathways/parser.rb
@@ -26,7 +26,8 @@ def run(most_recent_session_updated_at)
next unless timestamp = line.match( /^PathwaysTracker\:(.*)/)
visit_hash = JSON.parse(timestamp[1].to_s)
- session = Pathways::Session.find_or_create_by_ip_and_state(visit_hash["ip"], :active)
+ session = Pathways::Session.find_or_create_by_client_id_and_state(visit_hash["client_id"], :active)
+ session.update_attributes(:user_id => visit_hash["user_id"], :iteration => visit_hash["iteration"])
updated_at = Time.parse(visit_hash["created_at"]).to_i
next if most_recent_session_updated_at and updated_at < most_recent_session_updated_at
@@ -41,7 +42,8 @@ def run(most_recent_session_updated_at)
if time_since_last_visit > 600
session.state = :closed
session.save
- session = Pathways::Session.find_or_create_by_ip_and_state(visit_hash["ip"], :active)
+ session = Pathways::Session.find_or_create_by_client_id_and_state(visit_hash["client_id"], :active)
+ session.update_attributes(:user_id => visit_hash["user_id"], :iteration => visit_hash["iteration"])
session.created_at = updated_at
end
last_visit.time_active = (time_since_last_visit > 60) ? 60 : time_since_last_visit
View
17 lib/pathways/session.rb
@@ -2,6 +2,8 @@ module Pathways
class Session
include MongoMapper::Document
+ key :client_id, String
+ key :iteration, String
key :ip, String
key :state, String
key :user_id, Integer
@@ -68,6 +70,21 @@ def self.finder_build(opts={})
end
end
+ def self.find_by_path(path,opts={})
+ opts.merge!({
+ :out => {:inline => true},
+ :raw => true
+ })
+ results = self.finder_build(opts).find()
+ sessions = []
+ results.to_a.first.last.each do | result |
+ id = result["_id"]
+ next unless id == path
+ sessions = Pathways::Session.find_all_by_id(result["value"]["sessions"].try(:uniq))
+ end
+ return sessions
+ end
+
def self.popular_pages(opts={})
opts.merge!({
:out => {:inline => true},
View
14 lib/pathways/tracker.rb
@@ -1,6 +1,18 @@
module Pathways
module Tracker
+
+ mattr_accessor :iteration
+
def log_visit
+
+ unless client_id = cookies[:pathways_token]
+ client_id = Digest::MD5.hexdigest("#{request.ip}:#{Time.now}")
+ cookies[:pathways_token] = {
+ :value => client_id,
+ :expires => 20.years.from_now.utc
+ }
+ end
+
Rails.logger.info "PathwaysTracker:" << { :url => request.url,
:request_method => request.method,
:path => request.request_uri,
@@ -8,7 +20,9 @@ def log_visit
:action => action_name,
:params => params,
:ip => request.ip,
+ :client_id => client_id,
:created_at => Time.now,
+ :iteration => Pathways::Tracker.iteration,
:user_id => (current_user) ? current_user.id : nil}.to_json
end
end
View
2  lib/pathways/version.rb
@@ -1,3 +1,3 @@
module Pathways
- VERSION = "0.0.3"
+ VERSION = "0.0.6"
end
View
4 pathways.gemspec
@@ -9,13 +9,13 @@ Gem::Specification.new do |s|
s.email = ["hello@mintdigital.com","min.sucks@gmail.com"]
s.homepage = "http://rubygems.org/gems/pathways"
s.summary = "Helps your track the pathways in your Rails app."
- s.description = "Helps your track the pathways in your app so that you can pave the cowpaths."
+ 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."
s.required_rubygems_version = ">= 1.3.6"
s.rubyforge_project = "pathways"
s.add_development_dependency "bundler", ">= 1.0.0"
- s.add_dependency "mongo_mapper", "~> 0.9.1"
+ s.add_dependency "mongo_mapper", "0.8.6"
s.add_dependency "vegas", "~> 0.1.2"
s.add_dependency "sinatra", ">= 0.9.2"
s.add_dependency "bson_ext"
Please sign in to comment.
Something went wrong with that request. Please try again.