data-hoover 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +21 -0
- data/README.md +108 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/data-hoover.gemspec +30 -0
- data/lib/data_hoover.rb +27 -0
- data/lib/data_hoover/bags/segment_analytics.rb +35 -0
- data/lib/data_hoover/nozzle.rb +29 -0
- data/lib/data_hoover/version.rb +3 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6796648846e392f27d8139921022fa96605fb377
|
4
|
+
data.tar.gz: 142dc60836f0f3e9c7a666fb539e9a03aa20f2b8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ff4ef64569a05bac68107ebba9f71548fcc9be90eb0f5c1b731e8defd200d7ffe041b8914409ad8211b05f908cb8b65205bbfa4e73a8ac977284f057520c433b
|
7
|
+
data.tar.gz: 19578664eee59bd57d51dfa229ec74080a413b2778bf90e6c96b56eaa5afa01e9f1b2708731da925e48128c22ec7283cbbd0c435804c2f1fd4ea3d36c42d8be1
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 JobTeaser
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# DataHoover
|
2
|
+
|
3
|
+
This gem exposes a simple API to implement event sourcing in your app.
|
4
|
+
It comes by default with a [Segment](https://segment.com/) adapter but you
|
5
|
+
could very well inject your own (be it [Kafka](https://kafka.apache.org/) or
|
6
|
+
anything you can come up with).
|
7
|
+
|
8
|
+
Please refer to `lib/data_hoover/bags/segment_analytics.rb` for an example.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'data-hoover'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install data-hoover
|
25
|
+
|
26
|
+
## Configuration
|
27
|
+
|
28
|
+
First, you have to setup the gem a little bit:
|
29
|
+
|
30
|
+
``` ruby
|
31
|
+
DataHoover.logger = Logger.new(STDOUT)
|
32
|
+
DataHoover.traits = ->(user) { ... }
|
33
|
+
```
|
34
|
+
|
35
|
+
If you want to silence the logging, just pass in `Logger.new(nil)`.
|
36
|
+
|
37
|
+
The traits lambda is used to properly qualify your users. If you do not need
|
38
|
+
this, you can skip the configuration, as a default lambda is setup by the gem
|
39
|
+
(spoiler: it does nothing!).
|
40
|
+
|
41
|
+
We also provide you with a helper method if you want to anonymize your data:
|
42
|
+
|
43
|
+
``` ruby
|
44
|
+
DataHoover.anonymize(...)
|
45
|
+
|
46
|
+
# DataHoover.anonymize(nil) => nil
|
47
|
+
# DataHoover.anonymize('foo') => Digest::SHA256.hexdigest('foo')
|
48
|
+
# DataHoover.anonymize(1) => Digest::SHA256.hexdigest(1.to_s)
|
49
|
+
```
|
50
|
+
|
51
|
+
In a Rails environment, you might want to put this snippet in an
|
52
|
+
[initializer](http://guides.rubyonrails.org/configuring.html#using-initializer-files).
|
53
|
+
|
54
|
+
If you want to be able to use the provided Segment adapter, you will need to
|
55
|
+
setup an env variable with your API key:
|
56
|
+
|
57
|
+
``` ruby
|
58
|
+
ENV['SEGMENT_KEY'] = 'YOUR_SEGMENT_KEY'
|
59
|
+
```
|
60
|
+
|
61
|
+
## Usage
|
62
|
+
|
63
|
+
To instantiate the client, run:
|
64
|
+
``` ruby
|
65
|
+
DataHoover::Nozzle.new(trackee: trackee)
|
66
|
+
```
|
67
|
+
|
68
|
+
You can additionally provide your own adapter here:
|
69
|
+
```
|
70
|
+
nozzle = DataHoover::Nozzle.new(trackee: trackee, bag: CustomKafkaAdapter)
|
71
|
+
```
|
72
|
+
|
73
|
+
And you can then start to send events:
|
74
|
+
``` ruby
|
75
|
+
event_payload = {
|
76
|
+
field_1: 'foo',
|
77
|
+
field_2: { bar: 'baz' }
|
78
|
+
}
|
79
|
+
nozzle.absorb('event_name', event_payload)
|
80
|
+
```
|
81
|
+
|
82
|
+
## Development
|
83
|
+
|
84
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run
|
85
|
+
`rake spec` to run the tests. You can also run `bin/console` for an interactive
|
86
|
+
prompt that will allow you to experiment.
|
87
|
+
|
88
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To
|
89
|
+
release a new version, update the version number in `version.rb`, and then run
|
90
|
+
`bundle exec rake release`, which will create a git tag for the version, push
|
91
|
+
git commits and tags, and push the `.gem` file to
|
92
|
+
[rubygems.org](https://rubygems.org).
|
93
|
+
|
94
|
+
## Contributing
|
95
|
+
|
96
|
+
Bug reports and pull requests are welcome on GitHub at
|
97
|
+
https://github.com/jobteaser/data-hoover.
|
98
|
+
|
99
|
+
|
100
|
+
## License
|
101
|
+
|
102
|
+
The gem is available as open source under the terms of the
|
103
|
+
[MIT License](http://opensource.org/licenses/MIT).
|
104
|
+
|
105
|
+
## TODO
|
106
|
+
|
107
|
+
- [ ] Expose a mean to choose the anonymization implementation (and use it
|
108
|
+
internally as well)
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/data-hoover.gemspec
ADDED
@@ -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 'data_hoover/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'data-hoover'
|
8
|
+
spec.version = DataHoover::VERSION
|
9
|
+
spec.authors = ['Thomas Larrieu', 'Bryan Frimin']
|
10
|
+
spec.email = %w(thomas.larrieu@gmail.com friminb@gmail.com)
|
11
|
+
|
12
|
+
spec.summary = 'Event sourcing for human beings'
|
13
|
+
spec.description = 'This gem exposes a simple API to implement event' \
|
14
|
+
'sourcing in your app.'
|
15
|
+
spec.homepage = 'https://github.com/jobteaser/data-hoover'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
spec.bindir = 'exe'
|
22
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
+
spec.require_paths = %w(lib)
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
26
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
28
|
+
# TODO: this should be an optional dependency (segment)
|
29
|
+
spec.add_dependency 'analytics-ruby'
|
30
|
+
end
|
data/lib/data_hoover.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'data_hoover/version'
|
2
|
+
|
3
|
+
require 'digest'
|
4
|
+
require 'logger'
|
5
|
+
|
6
|
+
require 'segment/analytics'
|
7
|
+
|
8
|
+
require 'data_hoover/nozzle'
|
9
|
+
require 'data_hoover/bags/segment_analytics'
|
10
|
+
|
11
|
+
module DataHoover
|
12
|
+
class << self
|
13
|
+
|
14
|
+
attr_accessor :logger, :traits
|
15
|
+
|
16
|
+
def anonymize(entry)
|
17
|
+
return if entry.nil?
|
18
|
+
Digest::SHA256.hexdigest(entry.to_s)
|
19
|
+
end
|
20
|
+
|
21
|
+
alias anon anonymize
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
self.logger = Logger.new(STDOUT)
|
26
|
+
self.traits = ->(_) { {} }
|
27
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module DataHoover
|
2
|
+
module Bags
|
3
|
+
class SegmentAnalytics
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def tag(trackee_id:, traits:)
|
8
|
+
client.identify(
|
9
|
+
user_id: trackee_id,
|
10
|
+
traits: traits
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
def wrap(trackee_id:, event:, properties:)
|
15
|
+
client.track(
|
16
|
+
user_id: trackee_id,
|
17
|
+
event: event,
|
18
|
+
properties: properties
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def client
|
25
|
+
Segment::Analytics.new(
|
26
|
+
write_key: ENV.fetch('SEGMENT_KEY'),
|
27
|
+
on_error: ->(_status, msg) { DataHoover.logger.error(msg) }
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module DataHoover
|
2
|
+
class Nozzle
|
3
|
+
|
4
|
+
def initialize(trackee:, bag: DataHoover::Bags::SegmentAnalytics)
|
5
|
+
@trackee = trackee
|
6
|
+
@bag = bag
|
7
|
+
end
|
8
|
+
|
9
|
+
def absorb(event, props={})
|
10
|
+
@bag.tag(
|
11
|
+
trackee_id: DataHoover.anon(@trackee.id),
|
12
|
+
traits: traits
|
13
|
+
)
|
14
|
+
@bag.wrap(
|
15
|
+
trackee_id: DataHoover.anon(@trackee.id),
|
16
|
+
event: event,
|
17
|
+
properties: props
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def traits
|
24
|
+
trackee_traits = DataHoover.traits.call(@trackee)
|
25
|
+
Hash(trackee_traits).reject { |_key, value| value.nil? }
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: data-hoover
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Thomas Larrieu
|
8
|
+
- Bryan Frimin
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2017-05-03 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '1.14'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '1.14'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rake
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - "~>"
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '10.0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: rspec
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '3.5'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '3.5'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: analytics-ruby
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
description: This gem exposes a simple API to implement eventsourcing in your app.
|
71
|
+
email:
|
72
|
+
- thomas.larrieu@gmail.com
|
73
|
+
- friminb@gmail.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".travis.yml"
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/console
|
86
|
+
- bin/setup
|
87
|
+
- data-hoover.gemspec
|
88
|
+
- lib/data_hoover.rb
|
89
|
+
- lib/data_hoover/bags/segment_analytics.rb
|
90
|
+
- lib/data_hoover/nozzle.rb
|
91
|
+
- lib/data_hoover/version.rb
|
92
|
+
homepage: https://github.com/jobteaser/data-hoover
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.4.5.1
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Event sourcing for human beings
|
116
|
+
test_files: []
|