Permalink
Browse files

Added use of Net::HTTP::Persistent for requests.

Example use:
ga = Gabba::Gabba.new('UA-12345', 'www.example.com')
events.each {|category, action, label, value| ga.event(category, action, label, value)}
  • Loading branch information...
1 parent bab2d56 commit 50eff8380ba62c5484fc430d5fc0603aff6988d6 @justindossey committed Feb 8, 2012
Showing with 15 additions and 9 deletions.
  1. +3 −1 Gemfile
  2. +2 −0 gabba.gemspec
  3. +9 −7 lib/gabba/gabba.rb
  4. +1 −1 lib/gabba/version.rb
View
@@ -4,4 +4,6 @@ source "http://rubygems.org"
gemspec
gem 'minitest'
-gem 'webmock'
+gem 'webmock'
+
+gem 'net-http-persistent'
View
@@ -18,4 +18,6 @@ Gem::Specification.new do |s|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
+
+ s.add_dependency 'net-http-persistent', '>=2.5'
end
View
@@ -1,6 +1,7 @@
# yo, easy server-side tracking for Google Analytics... hey!
require "uri"
require "net/http"
+require 'net/http/persistent'
require 'cgi'
require File.dirname(__FILE__) + '/version'
@@ -156,12 +157,13 @@ def check_account_params
# makes the tracking call to Google Analytics
def hey(params)
query = params.map {|k,v| "#{k}=#{URI.escape(v.to_s, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))}" }.join('&')
- response = Net::HTTP.start(GOOGLE_HOST) do |http|
- request = Net::HTTP::Get.new("#{BEACON_PATH}?#{query}")
- request["User-Agent"] = URI.escape(user_agent)
- request["Accept"] = "*/*"
- http.request(request)
- end
+ @@http ||= Net::HTTP::Persistent.new 'Gabba'
+ #response = Net::HTTP.start(GOOGLE_HOST) do |http|
deadprogram
deadprogram Mar 23, 2012

You should not comment out lines of code. Better to instead remove them entirely, and let version control do its job.

+ request = Net::HTTP::Get.new("#{BEACON_PATH}?#{query}")
+ request["User-Agent"] = URI.escape(user_agent)
+ request["Accept"] = "*/*"
+ uri = URI "http://#{GOOGLE_HOST}/#{BEACON_PATH}"
+ response = @@http.request(uri, request)
raise GoogleAnalyticsNetworkError unless response.code == "200"
response
@@ -173,4 +175,4 @@ def random_id
end # Gabba Class
-end
+end
View
@@ -1,5 +1,5 @@
module Gabba
unless const_defined?('VERSION')
- VERSION = "0.1.1"
deadprogram
deadprogram Mar 23, 2012

You should not change the version number of a gem with submitting a pull request. Instead, let the gem author decide on what to include in any particular release, since there may be multiple pull requests going into it.

+ VERSION = "0.1.2"
end
end

0 comments on commit 50eff83

Please sign in to comment.