utm-builder 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.screenrc_extra +8 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +44 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +94 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/lib/utm.rb +58 -0
- data/lib/utm/configuration.rb +34 -0
- data/test/helper.rb +21 -0
- data/test/test_utm.rb +180 -0
- data/utm-builder.gemspec +79 -0
- metadata +173 -0
data/.document
ADDED
data/.screenrc_extra
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "addressable", ">= 0"
|
10
|
+
gem "minitest", ">= 0"
|
11
|
+
gem "bundler", "~> 1.0.0"
|
12
|
+
gem "jeweler", "~> 1.6.4"
|
13
|
+
gem "simplecov", ">= 0"
|
14
|
+
gem "reek", "~> 1.2.8"
|
15
|
+
gem "rake", "0.9.2.2"
|
16
|
+
gem "rdoc", "~> 3.12"
|
17
|
+
gem "awesome_print", ">= 1.0.2"
|
18
|
+
gem "bundler", "~> 1.0.0"
|
19
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.2.7)
|
5
|
+
awesome_print (1.0.2)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.6.4)
|
8
|
+
bundler (~> 1.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
json (1.6.5)
|
12
|
+
minitest (2.11.3)
|
13
|
+
multi_json (1.1.0)
|
14
|
+
rake (0.9.2.2)
|
15
|
+
rdoc (3.12)
|
16
|
+
json (~> 1.4)
|
17
|
+
reek (1.2.8)
|
18
|
+
ruby2ruby (~> 1.2)
|
19
|
+
ruby_parser (~> 2.0)
|
20
|
+
sexp_processor (~> 3.0)
|
21
|
+
ruby2ruby (1.3.1)
|
22
|
+
ruby_parser (~> 2.0)
|
23
|
+
sexp_processor (~> 3.0)
|
24
|
+
ruby_parser (2.3.1)
|
25
|
+
sexp_processor (~> 3.0)
|
26
|
+
sexp_processor (3.1.0)
|
27
|
+
simplecov (0.6.1)
|
28
|
+
multi_json (~> 1.0)
|
29
|
+
simplecov-html (~> 0.5.3)
|
30
|
+
simplecov-html (0.5.3)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
addressable
|
37
|
+
awesome_print (>= 1.0.2)
|
38
|
+
bundler (~> 1.0.0)
|
39
|
+
jeweler (~> 1.6.4)
|
40
|
+
minitest
|
41
|
+
rake (= 0.9.2.2)
|
42
|
+
rdoc (~> 3.12)
|
43
|
+
reek (~> 1.2.8)
|
44
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Joel Larsson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
= UTM
|
2
|
+
|
3
|
+
Used to dry up UTM link generation.
|
4
|
+
|
5
|
+
= DEPENDENCIES
|
6
|
+
|
7
|
+
ruby-1.9.2, bundler, addressable, minitest, jeweler, reek, rake, reek, rdoc
|
8
|
+
|
9
|
+
= INSTALL
|
10
|
+
|
11
|
+
gem install bundler
|
12
|
+
bundle install
|
13
|
+
|
14
|
+
= USAGE
|
15
|
+
|
16
|
+
== RAKE TASKS
|
17
|
+
|
18
|
+
Mostly used rake tasks
|
19
|
+
|
20
|
+
rake rdoc # Build RDoc HTML files
|
21
|
+
rake reek # Check for code smells
|
22
|
+
rake test # Run tests
|
23
|
+
|
24
|
+
Not so used rake tasks
|
25
|
+
|
26
|
+
rake install # Build and install gem using `gem install`
|
27
|
+
rake build # Build gem into pkg/
|
28
|
+
rake clobber_rdoc # Remove RDoc HTML files
|
29
|
+
rake console[script] # Start IRB with all runtime dependencies loaded
|
30
|
+
rake gemcutter:release # Release gem to Gemcutter
|
31
|
+
rake gemspec # Generate and validate gemspec
|
32
|
+
rake gemspec:debug # Display the gemspec for debugging purposes, as jeweler knows it (not from the filesystem)
|
33
|
+
rake gemspec:generate # Regenerate the gemspec on the filesystem
|
34
|
+
rake gemspec:release # Regenerate and validate gemspec, and then commits and pushes to git
|
35
|
+
rake gemspec:validate # Validates the gemspec on the filesystem
|
36
|
+
rake git:release # Tag and push release to git.
|
37
|
+
rake release # Release gem
|
38
|
+
rake rerdoc # Rebuild RDoc HTML files
|
39
|
+
rake version # Displays the current version
|
40
|
+
rake version:bump:major # Bump the major version by 1
|
41
|
+
rake version:bump:minor # Bump the a minor version by 1
|
42
|
+
rake version:bump:patch # Bump the patch version by 1
|
43
|
+
rake version:write # Writes out an explicit version.
|
44
|
+
|
45
|
+
== EXAMPLE USAGE
|
46
|
+
# == Campaign Source (utm_source)
|
47
|
+
# Required. Use utm_source to identify a search engine, newsletter
|
48
|
+
# name, or other source.
|
49
|
+
# * Example: utm_source=google
|
50
|
+
#
|
51
|
+
# == Campaign Medium (utm_medium)
|
52
|
+
# Required. Use utm_medium to identify a medium such as email or
|
53
|
+
# cost-per- click.
|
54
|
+
# * Example: utm_medium=cpc
|
55
|
+
#
|
56
|
+
# Campaign Term (utm_term)
|
57
|
+
# Used for paid search. Use utm_term to note the keywords for this ad.
|
58
|
+
# * Example: utm_term=running+shoes
|
59
|
+
|
60
|
+
# Campaign Content (utm_content)
|
61
|
+
# Used for A/B testing and content-targeted ads. Use utm_content to
|
62
|
+
# differentiate ads or links that point to the same URL.
|
63
|
+
# * Examples: utm_content=logolink or utm_content=textlink
|
64
|
+
|
65
|
+
# Campaign Name (utm_campaign)
|
66
|
+
# Used for keyword analysis. Use utm_campaign to identify a specific
|
67
|
+
# product promotion or strategic campaign.
|
68
|
+
# * Example: utm_campaign=spring_sale
|
69
|
+
|
70
|
+
UTM.configure do |conf|
|
71
|
+
conf.utm_source = "google"
|
72
|
+
conf.utm_medium = "cpc"
|
73
|
+
conf.utm_content = "variation_1"
|
74
|
+
conf.utm_campaign = "autofire"
|
75
|
+
end
|
76
|
+
|
77
|
+
params = UTM.build_params({utm_term: "fixies"})
|
78
|
+
params = UTM.build_params({utm_term: "ponies"})
|
79
|
+
|
80
|
+
== HELP OUT
|
81
|
+
|
82
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
83
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
84
|
+
* Fork the project
|
85
|
+
* Start a feature/bugfix branch
|
86
|
+
* Commit and push until you are happy with your contribution
|
87
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
88
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
89
|
+
|
90
|
+
== Copyright
|
91
|
+
|
92
|
+
Copyright (c) 2012 Joel Larsson. See LICENSE.txt for
|
93
|
+
further details.
|
94
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "utm-builder"
|
18
|
+
gem.homepage = "http://github.com/tilljoel/utm-builder"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Simple gem for building UTM-links}
|
21
|
+
gem.description = %Q{Builds UTM links}
|
22
|
+
gem.email = "tilljoel@gmail.com"
|
23
|
+
gem.authors = ["Joel Larsson"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
require 'reek/rake/task'
|
36
|
+
Reek::Rake::Task.new do |t|
|
37
|
+
t.fail_on_error = true
|
38
|
+
t.verbose = false
|
39
|
+
t.source_files = 'lib/**/*.rb'
|
40
|
+
end
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rdoc/task'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "utm-builder #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/utm.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'utm', 'configuration')
|
2
|
+
require 'cgi'
|
3
|
+
require 'addressable/uri'
|
4
|
+
# Generic UTM Exception Class, raised on missing mandatory settings
|
5
|
+
class UTMError < StandardError; end
|
6
|
+
|
7
|
+
module UTM
|
8
|
+
#FIXME rename to UTMHelper
|
9
|
+
|
10
|
+
MANDATORY_FIELDS = [:utm_source, :utm_medium, :utm_campaign]
|
11
|
+
POSSIBLE_FIELDS = [:utm_source, :utm_term, :utm_medium, :utm_content, :utm_campaign]
|
12
|
+
|
13
|
+
# == Campaign Source (utm_source)
|
14
|
+
# Required. Use utm_source to identify a search engine, newsletter
|
15
|
+
# name, or other source.
|
16
|
+
# * Example: utm_source=google
|
17
|
+
#
|
18
|
+
# == Campaign Medium (utm_medium)
|
19
|
+
# Required. Use utm_medium to identify a medium such as email or
|
20
|
+
# cost-per- click.
|
21
|
+
# * Example: utm_medium=cpc
|
22
|
+
#
|
23
|
+
# Campaign Term (utm_term)
|
24
|
+
# Used for paid search. Use utm_term to note the keywords for this ad.
|
25
|
+
# * Example: utm_term=running+shoes
|
26
|
+
|
27
|
+
# Campaign Content (utm_content)
|
28
|
+
# Used for A/B testing and content-targeted ads. Use utm_content to
|
29
|
+
# differentiate ads or links that point to the same URL.
|
30
|
+
# * Examples: utm_content=logolink or utm_content=textlink
|
31
|
+
|
32
|
+
# Campaign Name (utm_campaign)
|
33
|
+
# Used for keyword analysis. Use utm_campaign to identify a specific
|
34
|
+
# product promotion or strategic campaign.
|
35
|
+
# * Example: utm_campaign=spring_sale
|
36
|
+
|
37
|
+
def self.build_params(utm = {})
|
38
|
+
new = {}
|
39
|
+
new[:utm_source] = utm[:utm_source] || conf.utm_source
|
40
|
+
new[:utm_term] = utm[:utm_term] || conf.utm_term
|
41
|
+
new[:utm_medium] = utm[:utm_medium] || conf.utm_medium
|
42
|
+
new[:utm_content] = utm[:utm_content] || conf.utm_content
|
43
|
+
new[:utm_campaign] = utm[:utm_campaign] || conf.utm_campaign
|
44
|
+
new.select! {|field, content| content != nil}
|
45
|
+
|
46
|
+
raise UTMError, "Missing mandatory fields" if new.values_at(*MANDATORY_FIELDS).include?(nil)
|
47
|
+
|
48
|
+
parameters = new.map { |field, content| "#{field}=#{CGI.escape(content.to_s)}" unless content.nil? }
|
49
|
+
parameters.sort.join("&")
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.parse(url)
|
54
|
+
params = Addressable::URI.parse(url).query_values
|
55
|
+
params.select {|key,val| POSSIBLE_FIELDS.map(&:to_s).include?(key)}
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
module UTM
|
3
|
+
# == Configuration Class
|
4
|
+
#
|
5
|
+
# Class used for configuration. Use a block with
|
6
|
+
#
|
7
|
+
# UTM.configure do |config|
|
8
|
+
# config.utm_source = "twitter"
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
class Configuration
|
12
|
+
attr_accessor :utm_source
|
13
|
+
attr_accessor :utm_term
|
14
|
+
attr_accessor :utm_medium
|
15
|
+
attr_accessor :utm_content
|
16
|
+
attr_accessor :utm_campaign
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.reset_config!
|
21
|
+
@conf = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.configure
|
25
|
+
@conf = nil
|
26
|
+
yield conf
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.conf
|
30
|
+
@conf ||= Configuration.new
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
data/test/helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
require 'minitest/spec'
|
4
|
+
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'minitest/unit'
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
16
|
+
require 'utm'
|
17
|
+
|
18
|
+
class MiniTest::Unit::TestCase
|
19
|
+
end
|
20
|
+
|
21
|
+
MiniTest::Unit.autorun
|
data/test/test_utm.rb
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestUtmBuilder < MiniTest::Unit::TestCase
|
4
|
+
|
5
|
+
VALID_UTM_SOURCE = "google"
|
6
|
+
VALID_UTM_MEDIUM = "cpc"
|
7
|
+
VALID_UTM_TERM = "running shoes"
|
8
|
+
VALID_UTM_CONTENT = "logolink"
|
9
|
+
VALID_UTM_CAMPAIGN = "spring_sale"
|
10
|
+
VALID_UTM_CAMPAIGN_VARIANT = "big_joel_sale"
|
11
|
+
VALID_RESULT_PARAMS = "utm_campaign=spring_sale&utm_content=logolink&utm_medium=cpc&utm_source=google&utm_term=running+shoes"
|
12
|
+
VALID_RESULT_PARAMS_KEYS = ["utm_campaign", "utm_content", "utm_medium", "utm_source", "utm_term"]
|
13
|
+
|
14
|
+
|
15
|
+
#### TEST only parameteter input
|
16
|
+
def start_test(meth)
|
17
|
+
puts "\n*** start test #{meth} ***"
|
18
|
+
end
|
19
|
+
|
20
|
+
def end_test(meth)
|
21
|
+
puts "\n*** end test #{meth} ***"
|
22
|
+
end
|
23
|
+
|
24
|
+
def setup()
|
25
|
+
UTM.reset_config!
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_params_that_it_will_not_fail_with_missing_optional
|
29
|
+
start_test __method__
|
30
|
+
utm = {}
|
31
|
+
utm[:utm_source] = VALID_UTM_SOURCE
|
32
|
+
utm[:utm_medium] = VALID_UTM_MEDIUM
|
33
|
+
utm[:utm_content] = VALID_UTM_CONTENT
|
34
|
+
utm[:utm_campaign] = VALID_UTM_CAMPAIGN
|
35
|
+
params = UTM.build_params(utm)
|
36
|
+
assert params.include?("utm_source=#{VALID_UTM_SOURCE}")
|
37
|
+
assert params.include?("utm_medium=#{VALID_UTM_MEDIUM}")
|
38
|
+
assert params.include?("utm_content=#{VALID_UTM_CONTENT}")
|
39
|
+
assert params.include?("utm_campaign=#{VALID_UTM_CAMPAIGN}")
|
40
|
+
refute params.include?("utm_term=#{VALID_UTM_TERM}")
|
41
|
+
end_test __method__
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_params_that_it_will_fail_with_missing_mandatory
|
45
|
+
# Campaign Source, Campaign Medium and Campaign Name should always be used.
|
46
|
+
start_test __method__
|
47
|
+
utm = {}
|
48
|
+
utm[:utm_medium] = VALID_UTM_MEDIUM
|
49
|
+
utm[:utm_content] = VALID_UTM_CONTENT
|
50
|
+
utm[:utm_campaign] = VALID_UTM_CAMPAIGN
|
51
|
+
assert_raises (UTMError) do
|
52
|
+
params = UTM.build_params(utm)
|
53
|
+
end
|
54
|
+
end_test __method__
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_params_that_it_works_with_all_settings_ok
|
58
|
+
start_test __method__
|
59
|
+
utm = {}
|
60
|
+
utm[:utm_source] = VALID_UTM_SOURCE
|
61
|
+
utm[:utm_term] = VALID_UTM_TERM
|
62
|
+
utm[:utm_medium] = VALID_UTM_MEDIUM
|
63
|
+
utm[:utm_content] = VALID_UTM_CONTENT
|
64
|
+
utm[:utm_campaign] = VALID_UTM_CAMPAIGN
|
65
|
+
params = UTM.build_params(utm)
|
66
|
+
assert_equal VALID_RESULT_PARAMS, params
|
67
|
+
end_test __method__
|
68
|
+
end
|
69
|
+
|
70
|
+
#### TEST only block input
|
71
|
+
|
72
|
+
def test_block_that_it_will_fail_with_missing_mandatory
|
73
|
+
# Campaign Source, Campaign Medium and Campaign Name should always be used.
|
74
|
+
start_test __method__
|
75
|
+
UTM.configure do |conf|
|
76
|
+
conf.utm_medium = VALID_UTM_MEDIUM
|
77
|
+
conf.utm_content = VALID_UTM_CONTENT
|
78
|
+
conf.utm_campaign = VALID_UTM_CAMPAIGN
|
79
|
+
end
|
80
|
+
assert_raises (UTMError) do
|
81
|
+
url = UTM.build_params()
|
82
|
+
end
|
83
|
+
end_test __method__
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_block_that_it_will_not_fail_with_missing_optional
|
87
|
+
start_test __method__
|
88
|
+
UTM.configure do |conf|
|
89
|
+
conf.utm_source = VALID_UTM_SOURCE
|
90
|
+
conf.utm_medium = VALID_UTM_MEDIUM
|
91
|
+
conf.utm_content = VALID_UTM_CONTENT
|
92
|
+
conf.utm_campaign = VALID_UTM_CAMPAIGN
|
93
|
+
end
|
94
|
+
url = UTM.build_params()
|
95
|
+
assert url.include?("utm_source=#{VALID_UTM_SOURCE}")
|
96
|
+
assert url.include?("utm_medium=#{VALID_UTM_MEDIUM}")
|
97
|
+
assert url.include?("utm_content=#{VALID_UTM_CONTENT}")
|
98
|
+
assert url.include?("utm_campaign=#{VALID_UTM_CAMPAIGN}")
|
99
|
+
refute url.include?("utm_term=#{VALID_UTM_TERM}")
|
100
|
+
end_test __method__
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_block_that_it_works_with_all_settings_ok
|
104
|
+
start_test __method__
|
105
|
+
UTM.configure do |conf|
|
106
|
+
conf.utm_source = VALID_UTM_SOURCE
|
107
|
+
conf.utm_term = VALID_UTM_TERM
|
108
|
+
conf.utm_medium = VALID_UTM_MEDIUM
|
109
|
+
conf.utm_content = VALID_UTM_CONTENT
|
110
|
+
conf.utm_campaign = VALID_UTM_CAMPAIGN
|
111
|
+
end
|
112
|
+
params = UTM.build_params()
|
113
|
+
assert_equal VALID_RESULT_PARAMS, params
|
114
|
+
end_test __method__
|
115
|
+
end
|
116
|
+
|
117
|
+
#### TEST block and param inpust
|
118
|
+
def test_block_that_it_works_with_all_settings_and_override_from_params
|
119
|
+
start_test __method__
|
120
|
+
UTM.configure do |conf|
|
121
|
+
conf.utm_source = VALID_UTM_SOURCE
|
122
|
+
conf.utm_term = VALID_UTM_TERM
|
123
|
+
conf.utm_medium = VALID_UTM_MEDIUM
|
124
|
+
conf.utm_content = VALID_UTM_CONTENT
|
125
|
+
conf.utm_campaign = VALID_UTM_CAMPAIGN_VARIANT
|
126
|
+
end
|
127
|
+
params = UTM.build_params({utm_campaign: VALID_UTM_CAMPAIGN})
|
128
|
+
assert_equal VALID_RESULT_PARAMS, params
|
129
|
+
end_test __method__
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_block_that_it_works_with_all_settings_and_override_from_params
|
133
|
+
# Campaign Source, Campaign Medium and Campaign Name should always be used.
|
134
|
+
start_test __method__
|
135
|
+
UTM.configure do |conf|
|
136
|
+
conf.utm_source = VALID_UTM_SOURCE
|
137
|
+
conf.utm_medium = VALID_UTM_MEDIUM
|
138
|
+
end
|
139
|
+
params = UTM.build_params({utm_campaign: VALID_UTM_CAMPAIGN})
|
140
|
+
|
141
|
+
assert params.include?("utm_source=#{VALID_UTM_SOURCE}")
|
142
|
+
assert params.include?("utm_medium=#{VALID_UTM_MEDIUM}")
|
143
|
+
assert params.include?("utm_campaign=#{VALID_UTM_CAMPAIGN}")
|
144
|
+
|
145
|
+
refute params.include?("utm_content=#{VALID_UTM_CONTENT}")
|
146
|
+
refute params.include?("utm_term=#{VALID_UTM_TERM}")
|
147
|
+
|
148
|
+
end_test __method__
|
149
|
+
end
|
150
|
+
|
151
|
+
#### TEST reset_config
|
152
|
+
|
153
|
+
def test_block_reset_config
|
154
|
+
start_test __method__
|
155
|
+
UTM.configure do |conf|
|
156
|
+
conf.utm_source = VALID_UTM_SOURCE
|
157
|
+
conf.utm_term = VALID_UTM_TERM
|
158
|
+
conf.utm_medium = VALID_UTM_MEDIUM
|
159
|
+
conf.utm_content = VALID_UTM_CONTENT
|
160
|
+
conf.utm_campaign = VALID_UTM_CAMPAIGN
|
161
|
+
end
|
162
|
+
conf_ok = UTM.conf
|
163
|
+
UTM.reset_config!
|
164
|
+
conf_empty = UTM.conf
|
165
|
+
refute_equal conf_ok, conf_empty
|
166
|
+
|
167
|
+
end_test __method__
|
168
|
+
end
|
169
|
+
|
170
|
+
def test_parse_uri_good_uri
|
171
|
+
params = UTM.parse("?" + VALID_RESULT_PARAMS)
|
172
|
+
assert_equal 0, (params.keys - VALID_RESULT_PARAMS_KEYS).size
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_parse_uri_good_uri_with_extrastuff
|
176
|
+
params = UTM.parse("?" + VALID_RESULT_PARAMS + "&extramstuff=20&morestuff=10")
|
177
|
+
assert_equal 0, (params.keys - VALID_RESULT_PARAMS_KEYS).size
|
178
|
+
end
|
179
|
+
|
180
|
+
end
|
data/utm-builder.gemspec
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{utm-builder}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = [%q{Joel Larsson}]
|
12
|
+
s.date = %q{2012-04-22}
|
13
|
+
s.description = %q{Builds UTM links}
|
14
|
+
s.email = %q{tilljoel@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".screenrc_extra",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/utm.rb",
|
29
|
+
"lib/utm/configuration.rb",
|
30
|
+
"test/helper.rb",
|
31
|
+
"test/test_utm.rb",
|
32
|
+
"utm-builder.gemspec"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/tilljoel/utm-builder}
|
35
|
+
s.licenses = [%q{MIT}]
|
36
|
+
s.require_paths = [%q{lib}]
|
37
|
+
s.rubygems_version = %q{1.8.6}
|
38
|
+
s.summary = %q{Simple gem for building UTM-links}
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_development_dependency(%q<addressable>, [">= 0"])
|
45
|
+
s.add_development_dependency(%q<minitest>, [">= 0"])
|
46
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
47
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
48
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<reek>, ["~> 1.2.8"])
|
50
|
+
s.add_development_dependency(%q<rake>, ["= 0.9.2.2"])
|
51
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
52
|
+
s.add_development_dependency(%q<awesome_print>, [">= 1.0.2"])
|
53
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<addressable>, [">= 0"])
|
56
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
57
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
58
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
59
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
60
|
+
s.add_dependency(%q<reek>, ["~> 1.2.8"])
|
61
|
+
s.add_dependency(%q<rake>, ["= 0.9.2.2"])
|
62
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
63
|
+
s.add_dependency(%q<awesome_print>, [">= 1.0.2"])
|
64
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
+
end
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<addressable>, [">= 0"])
|
68
|
+
s.add_dependency(%q<minitest>, [">= 0"])
|
69
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
70
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
71
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
72
|
+
s.add_dependency(%q<reek>, ["~> 1.2.8"])
|
73
|
+
s.add_dependency(%q<rake>, ["= 0.9.2.2"])
|
74
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
75
|
+
s.add_dependency(%q<awesome_print>, [">= 1.0.2"])
|
76
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
metadata
ADDED
@@ -0,0 +1,173 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: utm-builder
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Joel Larsson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-22 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: addressable
|
16
|
+
requirement: &70322272374820 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70322272374820
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: minitest
|
27
|
+
requirement: &70322272372620 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70322272372620
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: bundler
|
38
|
+
requirement: &70322272371440 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.0.0
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70322272371440
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: jeweler
|
49
|
+
requirement: &70322272369160 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.6.4
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70322272369160
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: simplecov
|
60
|
+
requirement: &70322272367360 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70322272367360
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: reek
|
71
|
+
requirement: &70322272366200 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ~>
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.2.8
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *70322272366200
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rake
|
82
|
+
requirement: &70322272363600 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - =
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 0.9.2.2
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *70322272363600
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: rdoc
|
93
|
+
requirement: &70322272361060 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ~>
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '3.12'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *70322272361060
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: awesome_print
|
104
|
+
requirement: &70322272355940 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 1.0.2
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: *70322272355940
|
113
|
+
- !ruby/object:Gem::Dependency
|
114
|
+
name: bundler
|
115
|
+
requirement: &70322272351740 !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ~>
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 1.0.0
|
121
|
+
type: :development
|
122
|
+
prerelease: false
|
123
|
+
version_requirements: *70322272351740
|
124
|
+
description: Builds UTM links
|
125
|
+
email: tilljoel@gmail.com
|
126
|
+
executables: []
|
127
|
+
extensions: []
|
128
|
+
extra_rdoc_files:
|
129
|
+
- LICENSE.txt
|
130
|
+
- README.rdoc
|
131
|
+
files:
|
132
|
+
- .document
|
133
|
+
- .screenrc_extra
|
134
|
+
- Gemfile
|
135
|
+
- Gemfile.lock
|
136
|
+
- LICENSE.txt
|
137
|
+
- README.rdoc
|
138
|
+
- Rakefile
|
139
|
+
- VERSION
|
140
|
+
- lib/utm.rb
|
141
|
+
- lib/utm/configuration.rb
|
142
|
+
- test/helper.rb
|
143
|
+
- test/test_utm.rb
|
144
|
+
- utm-builder.gemspec
|
145
|
+
homepage: http://github.com/tilljoel/utm-builder
|
146
|
+
licenses:
|
147
|
+
- MIT
|
148
|
+
post_install_message:
|
149
|
+
rdoc_options: []
|
150
|
+
require_paths:
|
151
|
+
- lib
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ! '>='
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
segments:
|
159
|
+
- 0
|
160
|
+
hash: 345112546316964816
|
161
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
|
+
none: false
|
163
|
+
requirements:
|
164
|
+
- - ! '>='
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
requirements: []
|
168
|
+
rubyforge_project:
|
169
|
+
rubygems_version: 1.8.6
|
170
|
+
signing_key:
|
171
|
+
specification_version: 3
|
172
|
+
summary: Simple gem for building UTM-links
|
173
|
+
test_files: []
|