Skip to content

Commit

Permalink
Added use of Net::HTTP::Persistent for requests.
Browse files Browse the repository at this point in the history
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
justindossey committed Feb 8, 2012
1 parent bab2d56 commit 50eff83
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 3 additions & 1 deletion Gemfile
Expand Up @@ -4,4 +4,6 @@ source "http://rubygems.org"
gemspec

gem 'minitest'
gem 'webmock'
gem 'webmock'

gem 'net-http-persistent'
2 changes: 2 additions & 0 deletions gabba.gemspec
Expand Up @@ -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
16 changes: 9 additions & 7 deletions 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'

Expand Down Expand Up @@ -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|

This comment has been minimized.

Copy link
@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
Expand All @@ -173,4 +175,4 @@ def random_id

end # Gabba Class

end
end
2 changes: 1 addition & 1 deletion lib/gabba/version.rb
@@ -1,5 +1,5 @@
module Gabba
unless const_defined?('VERSION')
VERSION = "0.1.1"

This comment has been minimized.

Copy link
@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.