smyte 0.1.0 → 0.2.0
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 +4 -4
- data/lib/smyte.rb +3 -2
- data/lib/smyte/classification.rb +4 -2
- data/lib/smyte/client.rb +2 -2
- data/lib/smyte/notification.rb +9 -4
- data/lib/smyte/util.rb +25 -0
- data/lib/smyte/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5af59903cb12b29c2de562a6218c49e0760c63c3
|
4
|
+
data.tar.gz: aed4b1c24734dd8ad920050ad1dff604a8441e0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a80beaf6eececa81fe1d7890d30fed4dbd522d6f4021dd7b4b835e4b57512c74152129bd5eabe0c42dfd2dd37f0c05041198cb294c27d9f8d9d40de4df27092f
|
7
|
+
data.tar.gz: 35547ee0b8a17d9a79254651abf700338b2a7512c2419ea32bacf16869c8f1be90c8a6db526176f6601150df631932e986fd7905049f4d0812e2d65bf08ab9a0
|
data/lib/smyte.rb
CHANGED
@@ -8,6 +8,7 @@ module Smyte
|
|
8
8
|
autoload :Config, 'smyte/config'
|
9
9
|
autoload :LabelReporter, 'smyte/label_reporter'
|
10
10
|
autoload :Notification, 'smyte/notification'
|
11
|
+
autoload :Util, 'smyte/util'
|
11
12
|
|
12
13
|
class << self
|
13
14
|
extend Forwardable
|
@@ -21,8 +22,8 @@ module Smyte
|
|
21
22
|
def_delegators :client, :action, :classify
|
22
23
|
|
23
24
|
|
24
|
-
def webhook(secret, response)
|
25
|
-
::Smyte::Notification.parse(secret, response)
|
25
|
+
def webhook(secret, response, options={})
|
26
|
+
::Smyte::Notification.parse(secret, response, options)
|
26
27
|
end
|
27
28
|
|
28
29
|
protected
|
data/lib/smyte/classification.rb
CHANGED
@@ -6,10 +6,11 @@ module Smyte
|
|
6
6
|
new('verdict' => "ALLOW", 'labels' => {})
|
7
7
|
end
|
8
8
|
|
9
|
-
attr_reader :response
|
9
|
+
attr_reader :response, :options
|
10
10
|
|
11
|
-
def initialize(response)
|
11
|
+
def initialize(response, options={})
|
12
12
|
@response = response
|
13
|
+
@options = options || {}
|
13
14
|
end
|
14
15
|
|
15
16
|
protected
|
@@ -18,6 +19,7 @@ module Smyte
|
|
18
19
|
out = []
|
19
20
|
labels = response["labels"] || {}
|
20
21
|
labels.each do |name, attributes|
|
22
|
+
next unless ::Smyte::Util.label_interesting?(name, options)
|
21
23
|
out << Smyte::Classification::Label.new(name, attributes)
|
22
24
|
end
|
23
25
|
out
|
data/lib/smyte/client.rb
CHANGED
@@ -25,11 +25,11 @@ module Smyte
|
|
25
25
|
true # any success is just true - nothing else to know
|
26
26
|
end
|
27
27
|
|
28
|
-
def classify(event_name, payload)
|
28
|
+
def classify(event_name, payload, options={})
|
29
29
|
return Smyte::Classification.allowed if !enabled
|
30
30
|
|
31
31
|
response = process(event_name, payload, "/v2/action/classify")
|
32
|
-
Smyte::Classification.new(response)
|
32
|
+
Smyte::Classification.new(response, options)
|
33
33
|
end
|
34
34
|
|
35
35
|
protected
|
data/lib/smyte/notification.rb
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
module Smyte
|
2
2
|
class Notification
|
3
|
-
def self.parse(webhook_secret, response)
|
3
|
+
def self.parse(webhook_secret, response, options = {})
|
4
4
|
if webhook_secret != Smyte.webhook_secret
|
5
5
|
raise "invalid webhook_secret: #{webhook_secret}"
|
6
6
|
end
|
7
|
-
Smyte::Notification.new(response)
|
7
|
+
Smyte::Notification.new(response, options)
|
8
8
|
end
|
9
9
|
|
10
|
-
attr_reader :response
|
10
|
+
attr_reader :response, :options
|
11
11
|
|
12
|
-
def initialize(response)
|
12
|
+
def initialize(response, options = {})
|
13
13
|
@response = response
|
14
|
+
@options = options || {}
|
14
15
|
end
|
15
16
|
|
16
17
|
def items
|
@@ -25,6 +26,10 @@ module Smyte
|
|
25
26
|
items.each do |hash|
|
26
27
|
key = hash["item"]
|
27
28
|
next unless key
|
29
|
+
name = hash['labelName']
|
30
|
+
next unless name
|
31
|
+
next unless ::Smyte::Util.label_interesting?(name, options)
|
32
|
+
|
28
33
|
if out[key]
|
29
34
|
out[key].send(:add_response, hash)
|
30
35
|
else
|
data/lib/smyte/util.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
module Smyte
|
2
|
+
class Util
|
3
|
+
class << self
|
4
|
+
def label_interesting?(name, options)
|
5
|
+
return true unless options
|
6
|
+
return true unless options[:labels]
|
7
|
+
return true if options[:labels].empty?
|
8
|
+
|
9
|
+
pieces = name.split(":")
|
10
|
+
|
11
|
+
options[:labels].each do |check|
|
12
|
+
if check.is_a?(String)
|
13
|
+
return true if name == check
|
14
|
+
return true if pieces.last == check
|
15
|
+
elsif check.is_a?(Regexp)
|
16
|
+
return true if name =~ check
|
17
|
+
return true if pieces.last =~ check
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
return false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/smyte/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smyte
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Leonard
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -127,6 +127,7 @@ files:
|
|
127
127
|
- lib/smyte/config.rb
|
128
128
|
- lib/smyte/label_reporter.rb
|
129
129
|
- lib/smyte/notification.rb
|
130
|
+
- lib/smyte/util.rb
|
130
131
|
- lib/smyte/version.rb
|
131
132
|
- smyte.gemspec
|
132
133
|
homepage: https://www.taskrabbit.com
|