Permalink
Browse files

patron

  • Loading branch information...
1 parent ae066fe commit e3987b2a2eb4f1baf56bac970c7dc9a7ce85ee59 @jkraemer committed Jun 14, 2011
Showing with 7 additions and 6 deletions.
  1. +1 −0 Gemfile.lock
  2. +4 −4 lib/piwik_tracker/piwik.rb
  3. +2 −2 test/piwik_tracker/piwik_test.rb
View
@@ -2,6 +2,7 @@ PATH
remote: .
specs:
piwik-tracker (0.1.0)
+ patron
GEM
remote: http://rubygems.org/
@@ -19,14 +19,14 @@ class Piwik
attr_accessor :debug
attr_writer :logger
-
+
# base_uri - the location of your Piwik installation, i.e. 'http://yoursite.com/piwik'.
# site_id - Id of the site to be tracked
def initialize(base_uri, site_id)
@base_uri = base_uri
@site_id = site_id
end
-
+
# sends a tracking request
def track(params)
send_request params.merge( 'idsite' => @site_id,
@@ -48,7 +48,7 @@ def send_request(params)
logger.debug "Piwik request:\n#{url}\n#{headers.inspect}"
http.get url, headers
end
-
+
def http
@http ||= connect
end
@@ -59,7 +59,7 @@ def hash_to_querystring(hash)
query_string << "#{URI.encode(key.to_s)}=#{URI.encode(hash[key].to_s)}"
end
end
-
+
def connect
Patron::Session.new.tap do |session|
session.timeout = HTTP_TIMEOUT
@@ -14,7 +14,7 @@ def setup
@piwik.debug = true
@request = @piwik.request(ENV['auth'])
end
-
+
test "should track pageview" do
assert resp = @request.url('http://test.com/track_pageview').track_pageview( 'somwhere' )
pp resp
@@ -31,4 +31,4 @@ def setup
end
end
-end
+end

0 comments on commit e3987b2

Please sign in to comment.