Class: Trafficlogger::Analytic

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/trafficlogger/analytic.rb

Class Method Summary collapse

Class Method Details

.logger(req = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/trafficlogger/analytic.rb', line 11

def logger(req=nil)
	return if req.nil? || req.env.nil?
	data = req.env
	log_data = {}
	log_data["server_name"] = data["SERVER_NAME"]
	log_data["server_port"] = data["SERVER_PORT"]
	log_data["server_software"] = data["SERVER_SOFTWARE"]
	log_data["gateway_interface"] = data["GATEWAY_INTERFACE"]
	log_data["path_info"] = data["PATH_INFO"]
	log_data["request_uri"] = data["REQUEST_URI"]
	log_data["query_string"] = data["QUERY_STRING"]
	log_data["remote_host"] = data["REMOTE_HOST"]
	log_data["http_accept_encoding"] = data["HTTP_ACCEPT_ENCODING"]
	log_data["http_user_agent"] = data["HTTP_USER_AGENT"]
	log_data["server_protocol"] = data["SERVER_PROTOCOL"]
	log_data["http_accept_language"] = data["HTTP_ACCEPT_LANGUAGE"]
	log_data["http_host"] = data["HTTP_HOST"]
	log_data["remote_addr"] = data["REMOTE_ADDR"]
	log_data["http_referer"] = data["HTTP_REFERER"]
	log_data["http_cookie"] = data["HTTP_COOKIE"]
	log_data["http_accept"] = data["HTTP_ACCEPT"]
	log_data["request_method"] = data["REQUEST_METHOD"]
	log_data["http_connection"] = data["HTTP_CONNECTION"]
	log_data["http_version"] = data["HTTP_VERSION"]
	log_data["original_full_path"] = data["ORIGINAL_FULLPATH"]
	# Extract Relevant Information from User Agent
	operating_system,device,platform = ::Trafficlogger::UAParse.extract data["HTTP_USER_AGENT"].to_s
	log_data["operating_system"] = operating_system
	log_data["device"] = device
	log_data["platform"] = platform

	Analytic.create(log_data)
end

.search(searchterm, searchtype) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/models/trafficlogger/analytic.rb', line 45

def search(searchterm,searchtype)
  if !searchterm.blank? and !searchtype.blank?
    case searchtype
    when "path_info"
      where("path_info = ?",searchterm).order("created_at desc")
    when "request_uri"
      where("request_uri = ?",searchterm).order("created_at desc")
    when "request_method"
      where("request_method = ?",searchterm).order("created_at desc")
    when "operating_system"
      where("operating_system = ?",searchterm).order("created_at desc")
    when "device"
      where("device = ?",searchterm).order("created_at desc")
    when "platform"
      where("platform = ?",searchterm).order("created_at desc")
    else
      order("created_at desc").scoped
    end
  else
    order("created_at desc").scoped
  end
end