webtrends 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 88af47c8840f1c9a5152ad58bdddbb2348829270
4
+ data.tar.gz: 9d990d0d6a755bab23ba73f8389cd80b3797d521
5
+ SHA512:
6
+ metadata.gz: 10c05f208024257f0bd6e4d7ef7bd2afe1fd244132afb03c5e02536c0bd7748c1c4a7516c3b0c62128451c89e9e9803fc9d7331c3292bfab677dd592ef39cdfe
7
+ data.tar.gz: 2d6d60b1e49d77cc7a54b4e75330e889c7cca86802251b4a0c78c802b6e6c3b122d6b4251cee582f2e4e01c67821bf6974ef539d810dea86a2243ebd5a46b22c
@@ -0,0 +1,17 @@
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
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --color
2
+ --require spec_helper
3
+ --require rspec/instafail
4
+ --format documentation
@@ -0,0 +1,5 @@
1
+ SimpleCov.start do
2
+ SimpleCov.minimum_coverage 100.0
3
+ add_filter "/vendor"
4
+ add_filter "/spec"
5
+ end
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in webtrends.gemspec
4
+ gemspec
@@ -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.
@@ -0,0 +1,58 @@
1
+ # Webtrends
2
+ [![Gem Version](https://badge.fury.io/rb/webtrends.png)](http://badge.fury.io/rb/webtrends)
3
+ [![Code Climate](https://codeclimate.com/github/amaabca/webtrends.png)](https://codeclimate.com/github/amaabca/webtrends)
4
+ [![Build Status](https://travis-ci.org/amaabca/webtrends.png?branch=master)](https://travis-ci.org/amaabca/webtrends)
5
+ [![Coverage Status](https://coveralls.io/repos/amaabca/webtrends/badge.png)](https://coveralls.io/r/amaabca/webtrends)
6
+ [![Dependency Status](https://gemnasium.com/amaabca/webtrends.png)](https://gemnasium.com/amaabca/webtrends)
7
+
8
+ Make use of the Webtrends api to post event data for analytics purposes.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'webtrends'
15
+
16
+ And then execute:
17
+
18
+ $ bundle install
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install webtrends
23
+
24
+ ## Usage
25
+
26
+ Create config/initializers/webtrends.rb
27
+
28
+ Add the following configuration block
29
+
30
+ Webtrends.configure do |c|
31
+ c.protocol = 'https'
32
+ c.domain = 'dc.webtrends.com'
33
+ c.version = 'v1'
34
+ c.customer_id = YOUR_CUSTOMER_ID
35
+ c.verbose = true (setting verbose false is recommended in production)
36
+ c.format = 'xml' (plain or xml)
37
+ end
38
+
39
+ Additional documentation can be found on: http://help.webtrends.com/en/dcapi/
40
+
41
+ Example:
42
+
43
+ wt = Webtrends::Event.new(tags: { dcsuri: '/your_path_to_track', 'WT.ti' => 'a_tag'} )
44
+ response = wt.track
45
+
46
+ Note: You will either get a RestClient::Response back or an exception will be raised.
47
+
48
+ Note: dcsuri is required for the constructor.
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Create tests for your feature
55
+ 4. Make sure coverage meets minimum requirements
56
+ 5. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 6. Push to the branch (`git push origin my-new-feature`)
58
+ 7. Create new Pull Request
@@ -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,6 @@
1
+ require "rest_client"
2
+
3
+ require "webtrends/version"
4
+ require "webtrends/service"
5
+ require "webtrends/event"
6
+ require "webtrends/configuration"
@@ -0,0 +1,25 @@
1
+ module Webtrends
2
+
3
+ attr_accessor :configuration
4
+
5
+ def self.configuration
6
+ @configuration ||= Configuration.new
7
+ end
8
+
9
+ def self.configure
10
+ yield(configuration)
11
+ end
12
+
13
+ class Configuration
14
+ attr_accessor :verbose, :format, :protocol, :domain, :version, :customer_id, :event_service
15
+
16
+ def initialize
17
+ self.verbose = false
18
+ self.format = 'xml'
19
+ self.protocol = 'https'
20
+ self.domain = 'dc.webtrends.com'
21
+ self.version = 'v1'
22
+ self.event_service = 'events.svc'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ module Webtrends
2
+ class Event < Service
3
+
4
+ attr_accessor :tags
5
+
6
+ def initialize(args = {})
7
+ super
8
+ self.tags = args.fetch(:tags, {})
9
+ self.service = args.fetch(:service, Webtrends.configuration.event_service)
10
+ end
11
+
12
+ def track
13
+ if !tags.empty?
14
+ RestClient.post endpoint, options.merge(tags)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,24 @@
1
+ module Webtrends
2
+ class Service
3
+
4
+ attr_accessor :verbose, :format, :protocol, :domain, :version, :customer_id, :service
5
+
6
+ def initialize(args = {})
7
+ self.verbose = args.fetch(:verbose, Webtrends.configuration.verbose)
8
+ self.format = args.fetch(:format, Webtrends.configuration.format)
9
+ self.protocol = args.fetch(:protocol, Webtrends.configuration.protocol)
10
+ self.domain = args.fetch(:protocol, Webtrends.configuration.domain)
11
+ self.version = args.fetch(:version, Webtrends.configuration.version)
12
+ self.customer_id = args.fetch(:customer_id, Webtrends.configuration.customer_id)
13
+ end
14
+
15
+ private
16
+ def options
17
+ {dcsverbose: verbose, dcsformat: format}
18
+ end
19
+
20
+ def endpoint
21
+ "#{protocol}://#{domain}/#{version}/#{customer_id}/#{service}"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module Webtrends
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,80 @@
1
+ describe Webtrends::Event do
2
+
3
+ let(:successful_response) do
4
+ OpenStruct.new({response: File.read(File.join('spec', 'fixtures', 'success.xml')), code: 200})
5
+ end
6
+ let(:default_configuration) do
7
+ OpenStruct.new(
8
+ customer_id: 'whereevermd',
9
+ verbose: false,
10
+ format: 'xml')
11
+ end
12
+
13
+ before(:each) do
14
+ Webtrends.configure do |c|
15
+ c.customer_id = default_configuration.customer_id
16
+ end
17
+ end
18
+
19
+ describe '#track' do
20
+ context 'successful response' do
21
+ it 'returns success code' do
22
+ RestClient.stub(:post).and_return(successful_response)
23
+ subject.tags = {'dcsuri' => '/waffles'}
24
+ response = subject.track
25
+ expect(response.code).to eq(200)
26
+ end
27
+
28
+ it 'should merge tags and options' do
29
+ RestClient.stub(:post).and_return(successful_response)
30
+ subject.tags = {'dcsuri' => '/waffles'}
31
+ expect(RestClient).to receive(:post).with(subject.send(:endpoint), subject.tags.merge(subject.send(:options)))
32
+ response = subject.track
33
+ end
34
+ end
35
+
36
+ context 'unsuccessful response' do
37
+ it 'should trigger an exception' do
38
+ RestClient.stub(:post).and_raise(RestClient::BadRequest.new '400 Bad Request')
39
+ subject.tags = {'WT.ti' => 'waffles'}
40
+ begin
41
+ response = subject.track
42
+ rescue Exception => e
43
+ expect(e).to be_kind_of(RestClient::BadRequest)
44
+ end
45
+ expect(response).to be_nil
46
+ end
47
+
48
+ it 'should not call webtrends if tags is empty' do
49
+ expect(RestClient).to_not receive(:post)
50
+ response = subject.track
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '#initialize' do
56
+ context 'not passing default configuraiton' do
57
+ it 'uses default config attributes' do
58
+ expect(subject.customer_id).to eq(default_configuration.customer_id)
59
+ expect(subject.verbose).to eq(default_configuration.verbose)
60
+ expect(subject.format).to eq(default_configuration.format)
61
+ end
62
+ end
63
+
64
+ context 'passing default configuraiton' do
65
+ let(:custom_configuration) do
66
+ OpenStruct.new(
67
+ customer_id: 'somedifferent',
68
+ verbose: true,
69
+ format: 'plain')
70
+ end
71
+
72
+ let(:subject) { Webtrends::Event.new(custom_configuration.to_h) }
73
+ it 'does not uses default config attributes' do
74
+ expect(subject.customer_id).to_not eq(default_configuration.customer_id)
75
+ expect(subject.verbose).to_not eq(default_configuration.verbose)
76
+ expect(subject.format).to_not eq(default_configuration.format)
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <fields>
3
+ <date>2014-02-12</date>
4
+ <time>20:25:52</time>
5
+ <c-ip>96.53.112.182</c-ip>
6
+ <cs-useame>-</cs-useame>
7
+ <cs-host>-</cs-host>
8
+ <cs-method>POST</cs-method>
9
+ <cs-uri-stem>/dsgffhn</cs-uri-stem>
10
+ <cs-uri-query>WT.ti=ACCR</cs-uri-query>
11
+ <sc-status>200</sc-status>
12
+ <sc-bytes>-</sc-bytes>
13
+ <cs-version>-</cs-version>
14
+ <cs-user-agent>Ruby</cs-user-agent>
15
+ <cs-cookie>-</cs-cookie>
16
+ <cs-referer>-</cs-referer>
17
+ <dcs-id>dcsc1928yuz5bdaag0hu1lr25_6d2y</dcs-id>
18
+ </fields>
@@ -0,0 +1,11 @@
1
+ require 'simplecov'
2
+ require 'rspec'
3
+ require 'webtrends'
4
+ require 'coveralls'
5
+ require 'ostruct'
6
+ Coveralls.wear!
7
+
8
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
9
+ SimpleCov::Formatter::HTMLFormatter,
10
+ Coveralls::SimpleCov::Formatter
11
+ ]
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'webtrends/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "webtrends"
8
+ spec.version = Webtrends::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 = %q{Make use of the Webtrends api to post event data for analytics purposes.}
12
+ spec.summary = %q{Make use of the Webtrends api to post event data for analytics purposes.}
13
+ spec.homepage = "https://github.com/amaabca/webtrends"
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"
25
+ spec.add_development_dependency "rspec-instafail"
26
+ spec.add_development_dependency "simplecov"
27
+ spec.add_development_dependency "coveralls"
28
+ spec.add_dependency "rest-client"
29
+
30
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webtrends
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-19 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
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: rest-client
118
+ requirement: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ type: :runtime
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ description: Make use of the Webtrends api to post event data for analytics purposes.
131
+ email:
132
+ - michael.beuken@gmail.com
133
+ - ruben.a.estevez@gmail.com
134
+ - jorbabe@gmail.com
135
+ - mathieu.gilbert@ama.ab.ca
136
+ - ryan.michael.jones@gmail.com
137
+ - darko.dosenovic@ama.ab.ca
138
+ executables: []
139
+ extensions: []
140
+ extra_rdoc_files: []
141
+ files:
142
+ - .gitignore
143
+ - .rspec
144
+ - .simplecov
145
+ - .travis.yml
146
+ - Gemfile
147
+ - LICENSE.txt
148
+ - README.md
149
+ - Rakefile
150
+ - lib/webtrends.rb
151
+ - lib/webtrends/configuration.rb
152
+ - lib/webtrends/event.rb
153
+ - lib/webtrends/service.rb
154
+ - lib/webtrends/version.rb
155
+ - spec/event_spec.rb
156
+ - spec/fixtures/success.xml
157
+ - spec/spec_helper.rb
158
+ - webtrends.gemspec
159
+ homepage: https://github.com/amaabca/webtrends
160
+ licenses:
161
+ - MIT
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - '>='
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - '>='
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.0.0
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: Make use of the Webtrends api to post event data for analytics purposes.
183
+ test_files:
184
+ - spec/event_spec.rb
185
+ - spec/fixtures/success.xml
186
+ - spec/spec_helper.rb