urchin_tracking_module 1.0.3 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e178ebe92fe8c07ebdfc73fb9ba15afc86135918
4
- data.tar.gz: 40b77d0dfb8b7a1884f5bf85364ba9d2a4b69c42
3
+ metadata.gz: e0519945a69d20b0cd3656f07d058af6f585fe69
4
+ data.tar.gz: 12141b46ff967702d6ee3c28263f9ed7e0b4fbf8
5
5
  SHA512:
6
- metadata.gz: dc52e6adb9f505e45e4a8e525a88afc202c0f60372bc284f982b8b052d759846eff8fad054382c2d1fcf1a9efa77f7ebbcbf62cb6f60b11ed076415a50c4fd8d
7
- data.tar.gz: 570a955bc823b507df562e4e871d45a0855995dda2132967a335719d2aa4987ed7782e2b35ee57cb61fe64b4cc37a4f8ac165a3846bc340345a0a17f146a191b
6
+ metadata.gz: eb58cfbc6ba80c07e9cdd240803a602f0e166df474d2b6023b35ad1d9890bb2e8fb4ade3dcbb78328fea95f23bc3bb8795313c8b90b21da28d8c599020cd4fe4
7
+ data.tar.gz: ffd0afe1f63486884a110de6cf5d2a155c682ad68d4edb3675d1b3161730dd244f467530269275e989615a75b6df80a18e2cfa135d01214063a99f39b54e0250
data/.gitignore CHANGED
@@ -1,2 +1,5 @@
1
1
  pkg/
2
- tmp/
2
+ tmp/
3
+ /.bundle
4
+ /vendor/bundle
5
+ .idea
data/Gemfile CHANGED
@@ -1,7 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'active_support'
4
-
5
3
  group :test do
6
4
  gem 'rspec'
7
5
  gem 'guard-rspec'
data/Gemfile.lock CHANGED
@@ -1,14 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- urchin_tracking_module (1.0.1)
4
+ urchin_tracking_module (1.0.4)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- active_support (3.0.0)
10
- activesupport (= 3.0.0)
11
- activesupport (3.0.0)
12
9
  coderay (1.0.9)
13
10
  diff-lcs (1.2.4)
14
11
  ffi (1.9.0)
@@ -56,7 +53,6 @@ PLATFORMS
56
53
  ruby
57
54
 
58
55
  DEPENDENCIES
59
- active_support
60
56
  bundler (~> 1.3)
61
57
  guard-bundler
62
58
  guard-rspec
data/README.md CHANGED
@@ -40,18 +40,15 @@ Your thought's/improvements are welcome :)
40
40
 
41
41
  ## TODOs
42
42
 
43
- * remove dependency to Rails
44
43
  * remove bonusbox specific `src` param or make this kind of
45
44
  additions configurable.
46
- * `UrchinTrackingModule.configure {|c| c[:utm_source] => nil }` would generate
47
- invalid params. It should pick up defaults instead.
48
45
  * `UrchinTrackingModule.configure {|c| c[:utm_source] => 'my_app' }` could have a
49
46
  configuration object instead of a hash, to become
50
47
  `UrchinTrackingModule.configure {|c| c.utm_source = 'my_app' }`
51
48
 
52
49
  ## Code status
53
50
 
54
- * [![Build Status](https://api.travis-ci.org/bonusboxme/urchin_tracking_module.png)](https://travis-ci.org/bonusboxme/urchin_tracking_module)
51
+ [![Build Status](https://travis-ci.org/bonusboxme/urchin_tracking_module.png?branch=master)](https://travis-ci.org/bonusboxme/urchin_tracking_module)
55
52
 
56
53
  ## License
57
54
 
@@ -1,3 +1,3 @@
1
1
  class UrchinTrackingModule
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.5"
3
3
  end
@@ -1,6 +1,5 @@
1
1
  require 'urchin_tracking_module/version'
2
2
  require 'singleton'
3
- require 'active_support/core_ext/hash/slice'
4
3
 
5
4
  def UTM(url, params={})
6
5
  UrchinTrackingModule.new(url).tracking(params)
@@ -8,6 +7,11 @@ end
8
7
 
9
8
  class UrchinTrackingModule
10
9
  TRACKING_PARAMETERS = %i(utm_source utm_medium utm_term utm_content utm_campaign)
10
+ module Slicable
11
+ def slice(*keys)
12
+ keys.inject(Hash.new) {|h,k| h.merge(k => self[k]) }
13
+ end
14
+ end
11
15
 
12
16
  def initialize(url)
13
17
  @url = url
@@ -15,8 +19,10 @@ class UrchinTrackingModule
15
19
 
16
20
  def tracking(params=defaults)
17
21
  filtered_params(params).inject(@url) do |url,(name,value)|
18
- url = add_param(url, "#{name}", value)
19
- url = add_param(url, "src", value) if name == :utm_source
22
+ unless value.nil?
23
+ url = add_param(url, "#{name}", value)
24
+ url = add_param(url, "src", value) if name == :utm_source
25
+ end
20
26
  url
21
27
  end
22
28
  end
@@ -27,10 +33,12 @@ class UrchinTrackingModule
27
33
  private :defaults
28
34
 
29
35
  def filtered_params(params)
36
+ params.extend Slicable unless params.respond_to?(:slice)
30
37
  defaults.merge(params.slice(*TRACKING_PARAMETERS))
31
38
  end
32
39
  private :filtered_params
33
40
 
41
+
34
42
  def add_param(url, param_name, param_value)
35
43
  uri = URI(url)
36
44
  params = url_params(uri).merge(param_name => param_value)
@@ -79,7 +87,11 @@ class UrchinTrackingModule
79
87
  end
80
88
 
81
89
  def default_source
82
- Rails.application.class.parent_name
90
+ if defined?(Rails)
91
+ Rails.application.class.parent_name
92
+ else
93
+ 'urchin_tracking_module'
94
+ end
83
95
  end
84
96
  private :default_source
85
97
 
data/spec/spec_helper.rb CHANGED
@@ -1,14 +1,5 @@
1
1
  Dir["./support/**/*.rb"].each { |f| require f }
2
2
 
3
- unless defined?(Rails)
4
- module Rails
5
- class Application
6
- def self.parent_name; "urchin_tracking_module" end
7
- end
8
- def self.application; Application.new end
9
- end
10
- end
11
-
12
3
  RSpec.configure do |config|
13
4
  config.order = "random"
14
5
  end
@@ -24,6 +24,15 @@ describe UrchinTrackingModule do
24
24
  end
25
25
  end
26
26
 
27
+ context 'nil parameter values' do
28
+ let(:params) {{ utm_content: nil }}
29
+
30
+ it 'is not tracked' do
31
+ uri = subject.tracking(params)
32
+ expect(uri).not_to match(/utm_content=/)
33
+ end
34
+ end
35
+
27
36
  describe '.configure' do
28
37
  EXAMPLE_CONFIG = {
29
38
  utm_source: 'b2b_application',
@@ -61,6 +70,10 @@ describe UrchinTrackingModule do
61
70
  expect(UrchinTrackingModule.medium).to eq EXAMPLE_CONFIG[:utm_medium]
62
71
  end
63
72
 
73
+ it 'ignores non utm params' do
74
+ expect(UTM(url, foo: 'bar')).not_to match(/foo=bar/)
75
+ end
76
+
64
77
  describe 'UTM helper' do
65
78
  let(:utm) { double }
66
79
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: urchin_tracking_module
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Riethmayer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-17 00:00:00.000000000 Z
11
+ date: 2013-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,4 +86,3 @@ summary: utm params for your URL.
86
86
  test_files:
87
87
  - spec/spec_helper.rb
88
88
  - spec/urchin_tracking_module_spec.rb
89
- has_rdoc: