notifilter 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Rakefile +3 -0
- data/lib/notifilter/version.rb +3 -0
- data/lib/notifilter.rb +29 -0
- data/notifilter.gemspec +22 -0
- data/script/send_test_data.rb +15 -0
- data/spec/notifilter_spec.rb +21 -0
- metadata +93 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 34f2160d3fe7cb3aefacb464e0197490c22ab2f0
|
4
|
+
data.tar.gz: 5ca4f221162d402f07758fcf622cf4d80bebf07e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dbfaa701a8fc179f36f421416be29b507002c19079c0fe2d7defdc74ef22a34158ac04e7b879ad4002a646b20b1d188ff21bae8f171131ac9128753fb3a0987a
|
7
|
+
data.tar.gz: f195b5936017cbf0580eaa038e5b5ab5dd0e591ec13e2f08db80064cc4c9b72a9e5a3f9c5b07485175f6b15ac054a562f1b0ad4abc40075b65e4c9e7e1110d50
|
data/Rakefile
ADDED
data/lib/notifilter.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class Notifilter
|
5
|
+
def self.host
|
6
|
+
ENV["NOTIFILTER_HOST"] || "127.0.0.1"
|
7
|
+
end
|
8
|
+
def self.port
|
9
|
+
ENV["NOTIFILTER_PORT"] || 8000
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.notify(application, identifier, data)
|
13
|
+
message = {
|
14
|
+
"application" => application,
|
15
|
+
"identifier" => identifier,
|
16
|
+
"data" => data
|
17
|
+
}.to_json
|
18
|
+
|
19
|
+
begin
|
20
|
+
socket = UDPSocket.new
|
21
|
+
socket.send(message, 0, host, port)
|
22
|
+
rescue Exception => e
|
23
|
+
puts "Exception in Notifilter: #{e.message}"
|
24
|
+
ensure
|
25
|
+
socket.close if socket
|
26
|
+
true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/notifilter.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/notifilter/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Mark Mulder"]
|
6
|
+
gem.email = ["markmulder@gmail.com"]
|
7
|
+
gem.description = "Track events and get notified"
|
8
|
+
gem.summary = "Gem to track events into https://github.com/bittersweet/notifilter"
|
9
|
+
gem.homepage = "https://github.com/bittersweet/notifilter-rb"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split("\n")
|
12
|
+
gem.test_files = `git ls-files -- spec/*`.split("\n")
|
13
|
+
gem.name = "notifilter"
|
14
|
+
gem.require_paths = ['lib']
|
15
|
+
gem.version = Notifilter::VERSION
|
16
|
+
|
17
|
+
gem.add_runtime_dependency 'json'
|
18
|
+
|
19
|
+
gem.add_development_dependency 'rspec'
|
20
|
+
gem.add_development_dependency 'byebug'
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'thread'
|
2
|
+
|
3
|
+
require 'notifilter'
|
4
|
+
|
5
|
+
jobs = []
|
6
|
+
25.times do
|
7
|
+
jobs << Thread.new do
|
8
|
+
100.times do |i|
|
9
|
+
data = { user_id: rand(10), created_at: Time.now }
|
10
|
+
Notifilter.notify("test_app", "signup", data)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
jobs.map(&:join)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "./lib/notifilter"
|
2
|
+
require "byebug"
|
3
|
+
|
4
|
+
describe Notifilter do
|
5
|
+
around do |spec|
|
6
|
+
@server = UDPSocket.new
|
7
|
+
@server.bind("127.0.0.1", "8001")
|
8
|
+
ENV["NOTIFILTER_PORT"] = "8001"
|
9
|
+
spec.run
|
10
|
+
@server.close
|
11
|
+
end
|
12
|
+
|
13
|
+
it "sends correct message" do
|
14
|
+
data = { "id" => 1, "name" => "John Doe", "active" => false }
|
15
|
+
Notifilter.notify("test_app", "user.created", data)
|
16
|
+
|
17
|
+
received = @server.recv(1000)
|
18
|
+
result = { "application" => "test_app", "identifier" => "user.created", "data" => data }
|
19
|
+
expect(JSON.parse(received)).to eq result
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: notifilter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mark Mulder
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
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: byebug
|
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: Track events and get notified
|
56
|
+
email:
|
57
|
+
- markmulder@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- Rakefile
|
63
|
+
- lib/notifilter.rb
|
64
|
+
- lib/notifilter/version.rb
|
65
|
+
- notifilter.gemspec
|
66
|
+
- script/send_test_data.rb
|
67
|
+
- spec/notifilter_spec.rb
|
68
|
+
homepage: https://github.com/bittersweet/notifilter-rb
|
69
|
+
licenses: []
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.2.2
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Gem to track events into https://github.com/bittersweet/notifilter
|
91
|
+
test_files:
|
92
|
+
- spec/notifilter_spec.rb
|
93
|
+
has_rdoc:
|