icalia-sdk-event-notification 0.3.0 → 0.3.1
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14687aebe9d830b5c8a5079c1b4a6c03b12b6d80b7f982ec648661e980101d76
|
4
|
+
data.tar.gz: 66992c9198453caf2ac3843b10cdb7767b6a0d4322b0a9ef10e4a01b51c0d043
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c9aa1f0af78346102b147c8a543d7b34c97203e2f6c58818e3a4612e6bcae0377526d8999d7f5be336740a59ccb741f599a1d53668abe94b3eddde64301a813
|
7
|
+
data.tar.gz: cc1dfaf6f5c3d4be367d0cece028e90e5e8e0573217a41aa567085c7c94aa7afa9bad3e7f1c223c8ed1910753dfabf9af0885cce463cdbbcd4a7c8297be36ad7
|
@@ -9,6 +9,7 @@ module Icalia
|
|
9
9
|
module Event
|
10
10
|
autoload :Version, 'icalia-sdk-event-notification/version'
|
11
11
|
autoload :Publisher, 'icalia-sdk-event-notification/publisher'
|
12
|
+
autoload :Subscriber, 'icalia-sdk-event-notification/subscriber'
|
12
13
|
autoload :Notification, 'icalia-sdk-event-notification/notification'
|
13
14
|
|
14
15
|
autoload :TopicMessageProcessing,
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'icalia-sdk-event-core'
|
4
|
+
|
5
|
+
module Icalia::Event
|
6
|
+
module Subscriber
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
include Subserver::Subscriber
|
11
|
+
|
12
|
+
mattr_reader(:topic_name) do
|
13
|
+
self.name.demodulize.chomp('Subscriber').underscore.dasherize
|
14
|
+
end
|
15
|
+
|
16
|
+
mattr_reader(:processor_map) { {} }
|
17
|
+
end
|
18
|
+
|
19
|
+
def perform(message)
|
20
|
+
raw_data = MessagePack.unpack(message.data)
|
21
|
+
event = Icalia::Event::Deserializer.new(raw_data).perform
|
22
|
+
event_class_name = event.class.name.demodulize
|
23
|
+
|
24
|
+
if (processor_class = processor_map[event_class_name])
|
25
|
+
(processor = processor_class.new(event, message.attributes)).perform
|
26
|
+
else
|
27
|
+
logger.info "There's no mapped processor for #{event_class_name}"
|
28
|
+
end
|
29
|
+
|
30
|
+
message.acknowledge!
|
31
|
+
end
|
32
|
+
|
33
|
+
module ClassMethods
|
34
|
+
def subscribe_to_topic(new_topic_name, options = {})
|
35
|
+
class_variable_set '@@topic_name', new_topic_name
|
36
|
+
subserver_options options.merge(subscription: subscription_name)
|
37
|
+
end
|
38
|
+
|
39
|
+
def subscription_name
|
40
|
+
Rails.application.class.module_parent_name.underscore +
|
41
|
+
'-' +
|
42
|
+
ENV.fetch('DEPLOYMENT_NAME', Rails.env).downcase +
|
43
|
+
"-#{topic_name}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def ensure_subscription_exists
|
47
|
+
client = Subserver::Pubsub.client
|
48
|
+
topic = client.topic(topic_name) || client.create_topic(topic_name)
|
49
|
+
|
50
|
+
topic.subscription(subscription_name) ||
|
51
|
+
topic.subscribe(subscription_name)
|
52
|
+
end
|
53
|
+
|
54
|
+
def process(event_class_name, options = {})
|
55
|
+
processor = options.delete :with
|
56
|
+
return unless processor.present?
|
57
|
+
processor_map[event_class_name] = processor
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: icalia-sdk-event-notification
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Roberto Quintanilla
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: icalia-sdk-event-core
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.3.
|
19
|
+
version: 0.3.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.3.
|
26
|
+
version: 0.3.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: activesupport
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,6 +119,7 @@ files:
|
|
119
119
|
- lib/icalia-sdk-event-notification.rb
|
120
120
|
- lib/icalia-sdk-event-notification/notification.rb
|
121
121
|
- lib/icalia-sdk-event-notification/publisher.rb
|
122
|
+
- lib/icalia-sdk-event-notification/subscriber.rb
|
122
123
|
- lib/icalia-sdk-event-notification/topic_message_processing.rb
|
123
124
|
- lib/icalia-sdk-event-notification/version.rb
|
124
125
|
homepage: https://github.com/IcaliaLabs/icalia-sdk-ruby
|