preplaysports 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0016f3a2381cf76cd9a0b27e60f284901eba7373
4
+ data.tar.gz: 298726da866bb450ecbb955fe11c7a2c334cddf6
5
+ SHA512:
6
+ metadata.gz: ebcad496dfa3bc0c28d8d8ee0033fe84073aae84dbf10226149ffd5b96ad726c83b8a91622fc5e5a3dffdc68dfc4925d3b163c29b0456fb4e8079668532d6908
7
+ data.tar.gz: 7e77181ae1789e93784935fdd787b76bf444a854533635332b3cd72496ed07ca251d6b1fcb2f4a386de34456a0063a137c833e1696930e1f86a5a58f03f20933
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 pre_play_sports.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jérémy Van de Wyngaert
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/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ require "pre_play_sports/version"
2
+ require "pre_play_sports/event"
3
+
4
+ module PrePlaySports
5
+ end
@@ -0,0 +1,78 @@
1
+ module PrePlaySports
2
+
3
+ class Event
4
+ attr_accessor :event_type, :data, :context
5
+
6
+ def initialize(event_type, data, context)
7
+ @event_type = event_type
8
+ @data = filter(data)
9
+ @context = context
10
+ end
11
+
12
+ def to_scrolls_hash
13
+ event = {
14
+ d: { type: event_type }.merge!(data),
15
+ c: context,
16
+ m: {
17
+ dyno: $dyno_name,
18
+ created_at: Time.now.to_s
19
+ }
20
+ }
21
+ flatten_keys(event).merge!(preplay_event: true)
22
+ end
23
+
24
+ private
25
+
26
+ #this "flatten" a hash in order to use it on a Scrolls.log line
27
+ # {
28
+ # data: {
29
+ # foo: 'bar',
30
+ # baz: 42
31
+ # }
32
+ # }
33
+ # become :
34
+ # {
35
+ # :'data.foo' => 'bar',
36
+ # :'data.baz' => 42
37
+ # }
38
+ def flatten_keys(hash, namespace = nil)
39
+ namespace = namespace.nil? ? '' : "#{namespace}."
40
+ hash.inject(Hash.new) do |result, key, value|
41
+
42
+ hash.each do |k, v|
43
+ if v.is_a? Hash
44
+ # recursive call with the new namespace
45
+ result.merge! flatten_keys(v, namespace + k.to_s)
46
+ else
47
+ # direct set in the hash of the v
48
+ result["#{namespace}#{k}".to_sym] = v
49
+ end
50
+ end
51
+ result
52
+ end
53
+ end
54
+
55
+ #will filter the hash that was given to keep only the data that we want to display on the logs dependending on the data type
56
+ FIELD_WHITELIST = {
57
+ 'guess_created' => %w{id choice},
58
+ 'guess_updated' => %w{id choice},
59
+ 'message_published' => %w{id channel_id content tags},
60
+ 'user_follow' => %w{id username},
61
+ 'user_sign_up' => %w{id},
62
+ 'user_image_url_updated' => %w{id after before},
63
+ 'user_username_updated' => %w{id after before},
64
+ 'user_muted' => %w{id muted_until},
65
+ 'user_blacklisted' => %w{id ip},
66
+ }.freeze
67
+
68
+ def filter(data)
69
+ return {} unless FIELD_WHITELIST[event_type]
70
+ data.select {|k| FIELD_WHITELIST[event_type].include? k.to_s}
71
+ end
72
+ end
73
+
74
+ def self.Event(event_type, data, context)
75
+ Event.new(event_type, data, context).to_scrolls_hash
76
+ end
77
+
78
+ end
@@ -0,0 +1,3 @@
1
+ module PrePlaySports
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pre_play_sports/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "preplaysports"
8
+ spec.version = PrePlaySports::VERSION
9
+ spec.authors = ["Jérémy Van de Wyngaert"]
10
+ spec.email = ["jeremyvdw@gmail.com"]
11
+ spec.summary = "PrePlaySports utils and tools"
12
+ spec.homepage = "http://github.com/preplay/preplaysports"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.5"
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
23
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe PrePlaySports::Event do
4
+
5
+ subject { described_class.new(_event_type, _data, _context) }
6
+
7
+ let(:_event_type) do
8
+ 'user_follow'
9
+ end
10
+ let(:_data) do
11
+ {
12
+ id: 'johndoe',
13
+ username: 'john_doe',
14
+ forbidden: 'content'
15
+ }
16
+ end
17
+ let(:_context) do
18
+ {
19
+ some: 'context'
20
+ }
21
+ end
22
+
23
+ its(:event_type) { should eq _event_type }
24
+ its(:data) { should eq({ id: 'johndoe', username: 'john_doe' }) }
25
+ its(:context) { should eq _context }
26
+
27
+
28
+ describe "#to_scrolls_hash" do
29
+ let(:now) { Time.now.to_s }
30
+ before { allow(Time).to receive(:now).and_return(now) }
31
+
32
+ subject { super().to_scrolls_hash }
33
+
34
+ it { expect(subject).to eq({:"d.type"=>"user_follow", :"d.id"=>"johndoe", :"d.username"=>"john_doe", :"c.some"=>"context", :"m.dyno"=>nil, :"m.created_at"=>now, :preplay_event=>true}) }
35
+ end
36
+ end
@@ -0,0 +1 @@
1
+ require 'pre_play_sports'
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: preplaysports
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jérémy Van de Wyngaert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-02 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
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:
56
+ email:
57
+ - jeremyvdw@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - Rakefile
67
+ - lib/pre_play_sports.rb
68
+ - lib/pre_play_sports/event.rb
69
+ - lib/pre_play_sports/version.rb
70
+ - pre_play_sports.gemspec
71
+ - spec/pre_play_sports/event_spec.rb
72
+ - spec/spec_helper.rb
73
+ homepage: http://github.com/preplay/preplaysports
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.2
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: PrePlaySports utils and tools
97
+ test_files:
98
+ - spec/pre_play_sports/event_spec.rb
99
+ - spec/spec_helper.rb