Module: Snowfinch::Collector

Defined in:
lib/snowfinch/collector.rb,
lib/snowfinch/collector/click.rb,
lib/snowfinch/collector/version.rb

Defined Under Namespace

Classes: Click

Constant Summary collapse

EMPTY_GIF =
"R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw=="
RESPONSE =
[Base64.decode64(EMPTY_GIF)]
HEADERS =
{ "Content-Type" => "image/gif" }
OK =
[200, HEADERS, RESPONSE]
BAD_REQUEST =
[400, {}, []]
VERSION =
"0.5.0"

Class Method Summary collapse

Class Method Details

.call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/snowfinch/collector.rb', line 20

def self.call(env)
  params = Rack::Request.new(env).params

  click = Click.new :token => params["token"],
                    :uri => params["uri"],
                    :uuid => params["uuid"],
                    :referrer => params["referrer"]
  
  if click.save
    OK
  else
    BAD_REQUEST
  end
#rescue
  #BAD_REQUEST
end

.dbObject



37
38
39
# File 'lib/snowfinch/collector.rb', line 37

def self.db
  @db ||= Mongo::Connection.new.db("snowfinch")
end

.db=(database) ⇒ Object



41
42
43
# File 'lib/snowfinch/collector.rb', line 41

def self.db=(database)
  @db = database
end

.hash_uri(uri) ⇒ Object



54
55
56
# File 'lib/snowfinch/collector.rb', line 54

def self.hash_uri(uri)
  Digest::SHA1.hexdigest(uri).to_i(16).encode62
end

.sanitize_uri(uri) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/snowfinch/collector.rb', line 45

def self.sanitize_uri(uri)
  uri = uri.sub(/^https?:\/\/(www\.)?/, "http://")
  uri = URI.parse(uri)
  uri.path = uri.path.sub(/(.)\/$/, '\1')
  uri.query = nil
  uri.fragment = nil
  uri = uri.to_s
end