webtrends-rails 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 30aafe7308b243a4b8a9ba6a0cf75dd92c6a64e9
4
+ data.tar.gz: e863191af8ce72c3e77beebb9677ff15b88a29dd
5
+ SHA512:
6
+ metadata.gz: ed16e48d1a6d69d09ff3b9c1e49ba2c3abeac3c3c4b531a7455b7e1f31802fc8e89f470c9d0d3d0cbfced86ac39e7ede0394adb203bd2d3a1b9ac02b8f5daeb6
7
+ data.tar.gz: 2df8785c367bd1ef694a708792ca5425014a8340e014a977201d0d3c19dd2e0e0ad6db85429a940932c745cc27553cfd20814749c664aeade9d980ab3a148392
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ --color
2
+ --require spec_helper
3
+ --require rspec/instafail
4
+ --require rspec/rails
5
+ --format documentation
data/.simplecov ADDED
@@ -0,0 +1,5 @@
1
+ SimpleCov.start do
2
+ SimpleCov.minimum_coverage 100.0
3
+ add_filter "/vendor"
4
+ add_filter "/spec"
5
+ end
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in webtrends-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ruben Estevez
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # Webtrends::Rails
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/webtrends-rails.png)](http://badge.fury.io/rb/webtrends-rails)
4
+ [![Code Climate](https://codeclimate.com/github/amaabca/webtrends-rails.png)](https://codeclimate.com/github/amaabca/webtrends-rails)
5
+ [![Build Status](https://travis-ci.org/amaabca/webtrends-rails.png?branch=master)](https://travis-ci.org/amaabca/webtrends-rails)
6
+ [![Coverage Status](https://coveralls.io/repos/amaabca/webtrends-rails/badge.png)](https://coveralls.io/r/amaabca/webtrends-rails)
7
+ [![Dependency Status](https://gemnasium.com/amaabca/webtrends-rails.png)](https://gemnasium.com/amaabca/webtrends-rails)
8
+
9
+ Make use of Webtrends gem to allow server-side tracking in a Rails application.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'webtrends-rails'
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install webtrends-rails
24
+
25
+ ## Usage
26
+
27
+ ### Controller configuration
28
+
29
+ Track hook
30
+
31
+ track :object_to_track, options, optional_block
32
+
33
+ NOTE: Any options that can be passed to before_action can be used as options.
34
+
35
+ By default the track hook will use the following tags:
36
+
37
+ - dcsuri: request path (ex. /path/to/service)
38
+ - dcsdat: milliseconds since epoch
39
+ - dcssip: hostname
40
+ - WT.es: hostname + dcsuri
41
+ - WT.co_f: webtrends visitor id
42
+
43
+ NOTE: dcsuri is the only mandatory tag for event tracking. If dcsuri is not passed you will get
44
+ a 400 Bad Request response
45
+
46
+ #### Tracking with custom tags
47
+
48
+ track :object_to_track, only: :create do |tags|
49
+ tags.store('your_custom_tag', 'custom_tag_value')
50
+ end
51
+
52
+ #### Tracking with default tags
53
+
54
+ track :object_to_track, only: [:create, :update]
55
+
56
+
57
+ ### Model configuration
58
+
59
+ #### ActiveRecord
60
+
61
+ Make use of an after_save hook to call track_event
62
+
63
+ after_save :track_event
64
+
65
+ #### ActiveModel
66
+
67
+ Make use of an after_validation hook to call track_event
68
+
69
+ after_validation :track_event, if: 'errors.blank?'
70
+
71
+
72
+ ## Contributing
73
+
74
+ 1. Fork it
75
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
76
+ 3. Create tests for your feature
77
+ 4. Make sure coverage meets minimum requirements
78
+ 5. Commit your changes (`git commit -am 'Add some feature'`)
79
+ 6. Push to the branch (`git push origin my-new-feature`)
80
+ 7. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ desc "Run all tests"
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
@@ -0,0 +1,34 @@
1
+ module Webtrends
2
+ module Rails
3
+ module Controller
4
+ def self.included(base)
5
+ base.send(:extend, ClassMethods)
6
+ end
7
+
8
+ private
9
+
10
+ def analytics_visitor_id
11
+ visitor_id = ''
12
+ /id=([\w\-]*)/.match(cookies['WT_FPC']).tap do |match|
13
+ visitor_id = match.captures.first if match
14
+ end
15
+ visitor_id
16
+ end
17
+
18
+ def analytics_tags
19
+ { dcsuri: request.path, dcsdat: (Time.now.to_f * 1000).to_i, dcssip: request.domain,
20
+ 'WT.es' => "#{request.domain}#{request.path}", 'WT.co_f' => analytics_visitor_id }
21
+ end
22
+
23
+ module ClassMethods
24
+ def track(object_to_track, options)
25
+ before_action(options) do |controller|
26
+ tags = analytics_tags
27
+ yield(tags) if block_given?
28
+ controller.public_send(object_to_track).webtrends_tags = tags
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,11 @@
1
+ module Webtrends
2
+ module Rails
3
+ module Model
4
+ attr_accessor :webtrends_tags
5
+
6
+ def track_event
7
+ Webtrends::Event.new(tags: webtrends_tags).track
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Webtrends
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,11 @@
1
+ require "webtrends"
2
+ require "webtrends/rails/version"
3
+ require "webtrends/rails/model"
4
+ require "webtrends/rails/controller"
5
+
6
+ module Webtrends
7
+ module Rails
8
+ ActiveRecord::Callbacks.send(:include, Webtrends::Rails::Model) if defined? ActiveRecord
9
+ ActionController::Base.send(:include, Webtrends::Rails::Controller) if defined? ActionController
10
+ end
11
+ end
@@ -0,0 +1,36 @@
1
+ describe TestsController do
2
+ before(:each) do
3
+ Webtrends::Event.stub(:track)
4
+ end
5
+
6
+ context 'successfull load' do
7
+ context '#analytics visitor id' do
8
+ it 'should respond to method' do
9
+ expect(subject).to receive(:analytics_visitor_id)
10
+ get :index
11
+ end
12
+
13
+ context 'cookie is present' do
14
+ it 'should return the id' do
15
+ request.cookies['WT_FPC'] = 'id=some_id-9ew8r09t7:vlkhrpe-ryg8u4387'
16
+ get :index
17
+ expect(subject.model.webtrends_tags['WT.co_f']).to eq('some_id-9ew8r09t7')
18
+ end
19
+ end
20
+
21
+ context 'cookies is not present' do
22
+ it 'should return empty string' do
23
+ get :index
24
+ expect(subject.model.webtrends_tags['WT.co_f']).to eq('')
25
+ end
26
+ end
27
+ end
28
+
29
+ context '#analytics_tags' do
30
+ it 'should return tags' do
31
+ get :index
32
+ expect(subject.model.webtrends_tags).to_not be_empty
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,21 @@
1
+ require 'active_support/all'
2
+ require 'action_controller'
3
+ require 'action_dispatch'
4
+
5
+ module Rails
6
+ class App
7
+ def env_config; {} end
8
+ def routes
9
+ return @routes if defined?(@routes)
10
+ @routes = ActionDispatch::Routing::RouteSet.new
11
+ @routes.draw do
12
+ resources :tests # Replace with your own needs
13
+ end
14
+ @routes
15
+ end
16
+ end
17
+
18
+ def self.application
19
+ @app ||= App.new
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ class TestsController < ActionController::Base
2
+ include Rails.application.routes.url_helpers
3
+ include Webtrends::Rails::Controller
4
+
5
+ def render(*attributes); end
6
+
7
+ expose(:model)
8
+
9
+ track :model, only: :index
10
+
11
+ def index
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ class Model
2
+ include ActiveModel::Validations
3
+ include ActiveModel::Conversion
4
+ include ActiveRecord::Callbacks
5
+ extend ActiveModel::Naming
6
+ include Webtrends::Rails::Model
7
+
8
+ attr_accessor :some_attribute
9
+
10
+ validates :some_attribute, presence: true
11
+
12
+ after_validation :track_event, if: 'errors.blank?'
13
+
14
+ def attributes=(attributes = {})
15
+ attributes.each do |name, value|
16
+ send("#{name}=", value)
17
+ end
18
+ end
19
+
20
+ def save
21
+ errors.add(:base, 'Error') unless valid?
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ describe Model do
2
+ context 'successfull load' do
3
+ context 'after validation' do
4
+ it 'should respond to track event' do
5
+ subject.some_attribute = 'cupcake'
6
+ expect_any_instance_of(Webtrends::Event).to receive(:track)
7
+ subject.save
8
+ end
9
+ end
10
+ end
11
+
12
+ context 'usuccessfull load' do
13
+ context 'after validation' do
14
+ it 'should not respond to track event' do
15
+ expect_any_instance_of(Webtrends::Event).to_not receive(:track)
16
+ subject.save
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,15 @@
1
+ require 'simplecov'
2
+ require 'rails/all'
3
+ require 'rspec/rails'
4
+ require 'webtrends/rails'
5
+ require 'coveralls'
6
+ require 'decent_exposure'
7
+ require 'factories/application'
8
+ require 'factories/controller'
9
+ require 'factories/model'
10
+ Coveralls.wear!
11
+
12
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
13
+ SimpleCov::Formatter::HTMLFormatter,
14
+ Coveralls::SimpleCov::Formatter
15
+ ]
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'webtrends/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "webtrends-rails"
8
+ spec.version = Webtrends::Rails::VERSION
9
+ spec.authors = ["Michael van den Beuken", "Ruben Estevez", "Jordan Babe", "Mathieu Gilbert", "Ryan Jones", "Darko Dosenovic"]
10
+ spec.email = ["michael.beuken@gmail.com", "ruben.a.estevez@gmail.com", "jorbabe@gmail.com", "mathieu.gilbert@ama.ab.ca", "ryan.michael.jones@gmail.com", "darko.dosenovic@ama.ab.ca"]
11
+ spec.description = "Make use of Webtrends gem to allow server-side tracking in a Rails application."
12
+ spec.summary = "Make use of Webtrends gem to allow server-side tracking in a Rails application."
13
+ spec.homepage = "https://github.com/amaabca/webtrends-rails"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "pry"
24
+ spec.add_development_dependency "rspec-rails"
25
+ spec.add_development_dependency "rspec-instafail"
26
+ spec.add_development_dependency "simplecov"
27
+ spec.add_development_dependency "coveralls"
28
+ spec.add_development_dependency "decent_exposure"
29
+ spec.add_dependency "rails", ">= 3.1"
30
+ spec.add_dependency "webtrends"
31
+ end
metadata ADDED
@@ -0,0 +1,219 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webtrends-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Michael van den Beuken
8
+ - Ruben Estevez
9
+ - Jordan Babe
10
+ - Mathieu Gilbert
11
+ - Ryan Jones
12
+ - Darko Dosenovic
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+ date: 2014-02-20 00:00:00.000000000 Z
17
+ dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: bundler
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: '1.3'
25
+ type: :development
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ~>
30
+ - !ruby/object:Gem::Version
31
+ version: '1.3'
32
+ - !ruby/object:Gem::Dependency
33
+ name: rake
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :development
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: pry
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ type: :development
54
+ prerelease: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ - !ruby/object:Gem::Dependency
61
+ name: rspec-rails
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ - !ruby/object:Gem::Dependency
75
+ name: rspec-instafail
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ type: :development
82
+ prerelease: false
83
+ version_requirements: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ - !ruby/object:Gem::Dependency
89
+ name: simplecov
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ type: :development
96
+ prerelease: false
97
+ version_requirements: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ - !ruby/object:Gem::Dependency
103
+ name: coveralls
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ type: :development
110
+ prerelease: false
111
+ version_requirements: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - '>='
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ - !ruby/object:Gem::Dependency
117
+ name: decent_exposure
118
+ requirement: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ - !ruby/object:Gem::Dependency
131
+ name: rails
132
+ requirement: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - '>='
135
+ - !ruby/object:Gem::Version
136
+ version: '3.1'
137
+ type: :runtime
138
+ prerelease: false
139
+ version_requirements: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '3.1'
144
+ - !ruby/object:Gem::Dependency
145
+ name: webtrends
146
+ requirement: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ type: :runtime
152
+ prerelease: false
153
+ version_requirements: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ description: Make use of Webtrends gem to allow server-side tracking in a Rails application.
159
+ email:
160
+ - michael.beuken@gmail.com
161
+ - ruben.a.estevez@gmail.com
162
+ - jorbabe@gmail.com
163
+ - mathieu.gilbert@ama.ab.ca
164
+ - ryan.michael.jones@gmail.com
165
+ - darko.dosenovic@ama.ab.ca
166
+ executables: []
167
+ extensions: []
168
+ extra_rdoc_files: []
169
+ files:
170
+ - .gitignore
171
+ - .rspec
172
+ - .simplecov
173
+ - .travis.yml
174
+ - Gemfile
175
+ - LICENSE.txt
176
+ - README.md
177
+ - Rakefile
178
+ - lib/webtrends/rails.rb
179
+ - lib/webtrends/rails/controller.rb
180
+ - lib/webtrends/rails/model.rb
181
+ - lib/webtrends/rails/version.rb
182
+ - spec/controllers/controller_spec.rb
183
+ - spec/factories/application.rb
184
+ - spec/factories/controller.rb
185
+ - spec/factories/model.rb
186
+ - spec/models/model_spec.rb
187
+ - spec/spec_helper.rb
188
+ - webtrends-rails.gemspec
189
+ homepage: https://github.com/amaabca/webtrends-rails
190
+ licenses:
191
+ - MIT
192
+ metadata: {}
193
+ post_install_message:
194
+ rdoc_options: []
195
+ require_paths:
196
+ - lib
197
+ required_ruby_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ required_rubygems_version: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - '>='
205
+ - !ruby/object:Gem::Version
206
+ version: '0'
207
+ requirements: []
208
+ rubyforge_project:
209
+ rubygems_version: 2.0.0
210
+ signing_key:
211
+ specification_version: 4
212
+ summary: Make use of Webtrends gem to allow server-side tracking in a Rails application.
213
+ test_files:
214
+ - spec/controllers/controller_spec.rb
215
+ - spec/factories/application.rb
216
+ - spec/factories/controller.rb
217
+ - spec/factories/model.rb
218
+ - spec/models/model_spec.rb
219
+ - spec/spec_helper.rb