notifilter 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34f2160d3fe7cb3aefacb464e0197490c22ab2f0
4
- data.tar.gz: 5ca4f221162d402f07758fcf622cf4d80bebf07e
3
+ metadata.gz: 9181b7933bce88c7fd655a44f5922b516f69fea7
4
+ data.tar.gz: 595ec219a635b7f0866075ab09a43758924ffb73
5
5
  SHA512:
6
- metadata.gz: dbfaa701a8fc179f36f421416be29b507002c19079c0fe2d7defdc74ef22a34158ac04e7b879ad4002a646b20b1d188ff21bae8f171131ac9128753fb3a0987a
7
- data.tar.gz: f195b5936017cbf0580eaa038e5b5ab5dd0e591ec13e2f08db80064cc4c9b72a9e5a3f9c5b07485175f6b15ac054a562f1b0ad4abc40075b65e4c9e7e1110d50
6
+ metadata.gz: fb6473b27555340febc11a57ad21e8fc501164f5746c81ecbeeddaf2a50e5a888aec53e0e4f568b9e7567a531a9a6f64f482bc39192eab95d8a4d3ae00eb4906
7
+ data.tar.gz: 5169506a9f65dab11cf6220d9d0ddbf9120d2ca6f9b9386f5670ebf453c854b3aba4242f276f6e0594a0de16772d0a68849b70434fbd80e25c15eb0c397447df
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.2.3
5
+ - 2.1.7
6
+
7
+ script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem 'rspec'
5
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ GEM
2
+ specs:
3
+ diff-lcs (1.2.5)
4
+ rspec (3.3.0)
5
+ rspec-core (~> 3.3.0)
6
+ rspec-expectations (~> 3.3.0)
7
+ rspec-mocks (~> 3.3.0)
8
+ rspec-core (3.3.2)
9
+ rspec-support (~> 3.3.0)
10
+ rspec-expectations (3.3.1)
11
+ diff-lcs (>= 1.2.0, < 2.0)
12
+ rspec-support (~> 3.3.0)
13
+ rspec-mocks (3.3.2)
14
+ diff-lcs (>= 1.2.0, < 2.0)
15
+ rspec-support (~> 3.3.0)
16
+ rspec-support (3.3.0)
17
+
18
+ PLATFORMS
19
+ ruby
20
+
21
+ DEPENDENCIES
22
+ rspec
data/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # Notifilter Gem
2
+
3
+ [![Build Status](https://travis-ci.org/bittersweet/notifilter-rb.svg)](https://travis-ci.org/bittersweet/notifilter-rb)
4
+
5
+ This is a early, early version of a gem that sends events to
6
+ [Notifilter](https://github.com/bittersweet/notifilter). It is currently UDP
7
+ based, so fire and forget.
8
+
9
+ A TCP version will be forthcoming once everything has ran in production for a
10
+ while.
11
+
12
+ ### Ecosystem
13
+
14
+ [Server](https://github.com/bittersweet/notifilter)
15
+
16
+ ### How to use
17
+
18
+ ```
19
+ $notifilter = Notifilter.new("application_name", "127.0.0.1", "8000")
20
+ $notifilter.notify("event_identifier", { product_id: 1 })
21
+ ```
22
+
@@ -1,3 +1,3 @@
1
1
  class Notifilter
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/notifilter.rb CHANGED
@@ -2,23 +2,22 @@ require 'socket'
2
2
  require 'json'
3
3
 
4
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
5
+ def initialize(application, host = nil, port = nil)
6
+ @application = application
7
+ @host = host || "127.0.0.1"
8
+ @port = port || "8000"
10
9
  end
11
10
 
12
- def self.notify(application, identifier, data)
11
+ def notify(identifier, data)
13
12
  message = {
14
- "application" => application,
15
- "identifier" => identifier,
16
- "data" => data
13
+ application: @application,
14
+ identifier: identifier,
15
+ data: data
17
16
  }.to_json
18
17
 
19
18
  begin
20
19
  socket = UDPSocket.new
21
- socket.send(message, 0, host, port)
20
+ socket.send(message, 0, @host, @port)
22
21
  rescue Exception => e
23
22
  puts "Exception in Notifilter: #{e.message}"
24
23
  ensure
@@ -7,7 +7,7 @@ jobs = []
7
7
  jobs << Thread.new do
8
8
  100.times do |i|
9
9
  data = { user_id: rand(10), created_at: Time.now }
10
- Notifilter.notify("test_app", "signup", data)
10
+ Notifilter.notify("signup", data)
11
11
  end
12
12
  end
13
13
  end
@@ -1,18 +1,17 @@
1
1
  require "./lib/notifilter"
2
- require "byebug"
3
2
 
4
3
  describe Notifilter do
5
4
  around do |spec|
6
5
  @server = UDPSocket.new
7
6
  @server.bind("127.0.0.1", "8001")
8
- ENV["NOTIFILTER_PORT"] = "8001"
9
7
  spec.run
10
8
  @server.close
11
9
  end
12
10
 
13
11
  it "sends correct message" do
14
12
  data = { "id" => 1, "name" => "John Doe", "active" => false }
15
- Notifilter.notify("test_app", "user.created", data)
13
+ notifilter = Notifilter.new("test_app", "127.0.0.1", "8001")
14
+ notifilter.notify("user.created", data)
16
15
 
17
16
  received = @server.recv(1000)
18
17
  result = { "application" => "test_app", "identifier" => "user.created", "data" => data }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notifilter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Mulder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-12 00:00:00.000000000 Z
11
+ date: 2015-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -59,6 +59,10 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - ".travis.yml"
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - README.md
62
66
  - Rakefile
63
67
  - lib/notifilter.rb
64
68
  - lib/notifilter/version.rb