Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 50eff8380ba62c5484fc430d5fc0603aff6988d6 1 parent bab2d56
@justindossey authored
View
4 Gemfile
@@ -4,4 +4,6 @@ source "http://rubygems.org"
gemspec
gem 'minitest'
-gem 'webmock'
+gem 'webmock'
+
+gem 'net-http-persistent'
View
2  gabba.gemspec
@@ -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
16 lib/gabba/gabba.rb
@@ -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|

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ 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
2  lib/gabba/version.rb
@@ -1,5 +1,5 @@
module Gabba
unless const_defined?('VERSION')
- VERSION = "0.1.1"

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ VERSION = "0.1.2"
end
end
@deadprogram

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

@deadprogram

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.

Please sign in to comment.
Something went wrong with that request. Please try again.