trackme 0.0.4

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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MzNmYzIzOTQ1NzU1NzRhN2UwOTU3MmU5ZDA0NWQ1ZWUwNmMzNmU3ZQ==
5
+ data.tar.gz: !binary |-
6
+ NTNjNTE4MjhiYzZjNmE4ZmY3NDBiZTY4ZmY1YzZjY2Q5ZGJhYTkyNA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZWI4OWE0ZWNmZjQ4NDRmN2U3MWU3YThiY2I0OWIzNDBkOGEzZjA2NThmNGI1
10
+ NTYyOTczZjlkYjdkMDNkYjJiMjU1ZTkyMDg5MWU0ZjZlZDhjYTc0OTA1MTdl
11
+ ZDVlOGYwZWQ0NDBiYzE2NDY4NTRiZmRkMDJkYmEyMGI3MmNmODQ=
12
+ data.tar.gz: !binary |-
13
+ NjA5NjA1OTVmZTcxZGUyZTYzZjQ4ODY5ZDI0N2JlMDIyYWE0ZjQzYmIzMWQ2
14
+ MDUxNTc0YWEzY2E5YjkyZjBiMTQ5Zjc5NDJkYmRhMTNmOWZkYTMwNmEzNzQ1
15
+ ODI5NWUyMTQ2MjUwZmU5ZjIyMDFjOGI5OWQ3MWQ0MWRiYmE4ZjA=
data/.gitignore ADDED
@@ -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,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in trackme.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Michael Dijkstra
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,101 @@
1
+ # TrackMe
2
+
3
+ Simple user activity tracking for Ruby and Rails developers
4
+
5
+ ## Usage
6
+
7
+ TrackMe is based on the idea that an actor performs an event.
8
+
9
+ To setup your event class add the following:
10
+ `include TrackMe::Event`
11
+
12
+ To setup your actor class add the following:
13
+ `include TrackMe::Actor`
14
+
15
+ By default, TrackMe looks for an event class called 'Event'. If you would like
16
+ to change this then set the following:
17
+ `self.event_klass = CLASS`
18
+
19
+ Once setup, you can track a users activity in the following way:
20
+ `current_user.track_me(category: 'View')`
21
+
22
+ ## Details
23
+
24
+ TrackMe events have the following options:
25
+ + `:actor` (required) - The object that did the event
26
+ + `:category` (required)- The event category, such as 'Message'
27
+ + `:label` (optional)- The label of the event category, such as 'New'
28
+ + `:value` (optional)- The value of the event category label, such as 'Hello Bob!'
29
+ + `:created_at` (optional)- The date the event occurred, such as '2013-09-29
30
+ 12:00:00'
31
+
32
+ TrackMe needs the following fields to save events:
33
+ + `actor_id` - Integer
34
+ + `category` - String
35
+ + `label` - String
36
+ + `value` - String
37
+ + `created_at` - Date/Time
38
+
39
+ ## Rails Example
40
+
41
+ First, add the TrackMe gem to your Gemfile:
42
+
43
+ `gem 'trackme'`
44
+
45
+ Next, you need to setup a model to be the actor, this is most likely going to
46
+ be your `User` model.
47
+
48
+ ```ruby
49
+ class User
50
+ include TrackMe::Actor
51
+
52
+ # … existing model code
53
+ end
54
+ ```
55
+
56
+ Then you need to setup a model to save the events, in most cases you will need
57
+ to create a new model with the fields `actor`, `category`, `label`, `value`.
58
+
59
+ In a Rails app backed by Postgress you would set this up with by running the
60
+ following on the command line:
61
+
62
+ `rails g model event actor_id:integer category:text label:text value:text -t nil`
63
+
64
+ `rake db:migrate`
65
+
66
+ And add the following to your `Event` model:
67
+
68
+ ```ruby
69
+ class Event
70
+ include TrackMe::Event
71
+
72
+ # … existing model code
73
+ end
74
+ ```
75
+
76
+ Let's say you have a `Messages` controller and you want to track when a user
77
+ sends a message, you would add the following code to your `create` action:
78
+
79
+ ```ruby
80
+ class MessagesController
81
+ # … existing controller code
82
+
83
+ def create
84
+ # … existing code
85
+ @sender = User.find(params[:sender_id])
86
+ @sender.track_me(category: 'Message', label: 'New', value: @message.body)
87
+ end
88
+
89
+ # … more controller code
90
+ end
91
+ ```
92
+
93
+ That's it! Now you are able to track users activity.
94
+
95
+ ## Contributing
96
+
97
+ 1. Fork it
98
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
99
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
100
+ 4. Push to the branch (`git push origin my-new-feature`)
101
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/trackme.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'trackme/version'
2
+ require 'trackme/actor.rb'
3
+ require 'trackme/errors.rb'
4
+ require 'trackme/event.rb'
@@ -0,0 +1,23 @@
1
+ module TrackMe
2
+
3
+ module Actor
4
+
5
+ attr_accessor :event_klass
6
+
7
+ def track_me(options={})
8
+ validate_track_me(options) or raise StandardError
9
+ event_class.publish(self, options)
10
+ end
11
+
12
+ def validate_track_me(options)
13
+ options[:category].empty? == false && options[:label].empty? == false
14
+ rescue
15
+ raise Errors::InvalidData
16
+ end
17
+
18
+ def event_class
19
+ @event_klass ||= event_klass ? event_klass.classify.constantize : ::Event
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,17 @@
1
+ module TrackMe
2
+
3
+ module Errors
4
+
5
+ class InvalidData < StandardError
6
+
7
+ attr_reader :message
8
+
9
+ def initialize(message)
10
+ @message = "Invalid Data: #{message}"
11
+ end
12
+
13
+ end
14
+
15
+ end
16
+
17
+ end
@@ -0,0 +1,19 @@
1
+ module TrackMe
2
+ module Event
3
+ attr_reader :actor, :category, :label, :value, :created_at
4
+ attr_writer :actor, :category, :label, :value, :created_at
5
+
6
+ def self.included(base)
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods
11
+ def publish(actor, data={})
12
+ (actor && data[:category]) or raise Errors::InvalidData
13
+ event = new({ actor_id: actor.id }.merge(data))
14
+ event.save
15
+ event
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module TrackMe
2
+ VERSION = "0.0.4"
3
+ end
@@ -0,0 +1,14 @@
1
+ class Event
2
+ include TrackMe::Event
3
+
4
+ def initialize(data={})
5
+ @actor = data[:actor]
6
+ @category = data[:category]
7
+ @label = data[:label]
8
+ @value = data[:value]
9
+ @created_at = data[:created_at]
10
+ end
11
+
12
+ def save
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ class User
2
+ include TrackMe::Actor
3
+
4
+ def self.existing_instance_method
5
+ true
6
+ end
7
+
8
+ def id
9
+ '1'
10
+ end
11
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ describe TrackMe do
3
+ describe "Actor" do
4
+ describe ".track_me" do
5
+ it "must have a category" do
6
+ expect{ user.track_me(category: '', label: 'Homepage') }.to raise_error
7
+ end
8
+
9
+ it "must have a label" do
10
+ expect{ user.track_me(category: 'View', label: '') }.to raise_error
11
+ end
12
+
13
+ it "is valid with category and label" do
14
+ expect{ user.track_me(data) }.not_to raise_error
15
+ end
16
+
17
+ it "still uses existing methods" do
18
+ User.existing_instance_method.should eq(true)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+ describe TrackMe do
3
+ describe "Event" do
4
+ describe ".publish" do
5
+ it "must have an actor" do
6
+ expect{ Event.publish(nil, data) }.to raise_error
7
+ end
8
+
9
+ it "must have a category" do
10
+ expect{ Event.publish(user, { category: nil }) }.to raise_error
11
+ end
12
+
13
+ it "returns an event" do
14
+ event = Event.publish(user, data)
15
+ event.class.should eq(Event)
16
+ end
17
+
18
+ it "can override the create date" do
19
+ event = Event.publish(user, { created_at: Time.new(2013) }.merge(data))
20
+ event.created_at.should eq(Time.new(2013))
21
+ end
22
+ end
23
+
24
+ describe ".create" do
25
+ it "has an actor" do
26
+ event.actor.should eq(user)
27
+ end
28
+
29
+ it "has a category" do
30
+ event.category.should eq('View')
31
+ end
32
+
33
+ it "has a label" do
34
+ event.label.should eq('Homepage')
35
+ end
36
+
37
+ it "has a value" do
38
+ event.value.should eq('1')
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,27 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+ #
6
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ #
8
+
9
+ require 'trackme'
10
+
11
+ require 'app/models/user.rb'
12
+ require 'app/models/event.rb'
13
+ require 'support/trackme_helper.rb'
14
+
15
+ RSpec.configure do |config|
16
+ config.treat_symbols_as_metadata_keys_with_true_values = true
17
+ config.run_all_when_everything_filtered = true
18
+ config.filter_run :focus
19
+
20
+ # Run specs in random order to surface order dependencies. If you find an
21
+ # order dependency and want to debug it, you can fix the order by providing
22
+ # the seed, which is printed after each run.
23
+ # --seed 1234
24
+ config.order = 'random'
25
+
26
+ config.include TrackMeHelper
27
+ end
@@ -0,0 +1,13 @@
1
+ module TrackMeHelper
2
+ def user
3
+ @user ||= User.new
4
+ end
5
+
6
+ def event
7
+ @event ||= Event.new({ actor: user }.merge(data))
8
+ end
9
+
10
+ def data
11
+ { category: 'View', label: 'Homepage', value: '1' }
12
+ end
13
+ end
data/trackme.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'trackme/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "trackme"
8
+ spec.version = TrackMe::VERSION
9
+ spec.authors = ["Michael Dijkstra"]
10
+ spec.email = ["micdijkstra@gmail.com"]
11
+ spec.description = %q{Simple user activity tracking}
12
+ spec.summary = %q{Provides an easy way for Ruby and Rails developers to track user activity.}
13
+ spec.homepage = "https://github.com/micdijkstra/trackme"
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 "rspec"
24
+ end
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trackme
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Michael Dijkstra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Simple user activity tracking
56
+ email:
57
+ - micdijkstra@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .rspec
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/trackme.rb
69
+ - lib/trackme/actor.rb
70
+ - lib/trackme/errors.rb
71
+ - lib/trackme/event.rb
72
+ - lib/trackme/version.rb
73
+ - spec/app/models/event.rb
74
+ - spec/app/models/user.rb
75
+ - spec/lib/actor_spec.rb
76
+ - spec/lib/event_spec.rb
77
+ - spec/spec_helper.rb
78
+ - spec/support/trackme_helper.rb
79
+ - trackme.gemspec
80
+ homepage: https://github.com/micdijkstra/trackme
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ! '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.0.3
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: Provides an easy way for Ruby and Rails developers to track user activity.
104
+ test_files:
105
+ - spec/app/models/event.rb
106
+ - spec/app/models/user.rb
107
+ - spec/lib/actor_spec.rb
108
+ - spec/lib/event_spec.rb
109
+ - spec/spec_helper.rb
110
+ - spec/support/trackme_helper.rb