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: d4466c4f19eaba3dec12cc72bf6f10ff2a7016301838b36db555e4b0023c8f7d
4
- data.tar.gz: eb0de43b40ed889454363edcb9afc49c0b6e6297127bb18d2155f5c9295e67a7
3
+ metadata.gz: 14687aebe9d830b5c8a5079c1b4a6c03b12b6d80b7f982ec648661e980101d76
4
+ data.tar.gz: 66992c9198453caf2ac3843b10cdb7767b6a0d4322b0a9ef10e4a01b51c0d043
5
5
  SHA512:
6
- metadata.gz: 449b05229ccdfea47f221d13b82cb6c31f1096590db005310cf4084e8aa2681ab8394652bcce713d4fc018aa7bbec68034295e7107f3453663d8263b4643d0c0
7
- data.tar.gz: fb191efdadd7d68ce33ee3853c5198dc3e71fd37d45db39ed539db9b03e6e8132c66e443abf19fe734721dae4ee1c0a46645203f1a4dbd171dac12d17c049c26
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Icalia
4
4
  module Event
5
- NOTIFICATION_VERSION = '0.3.0'
5
+ NOTIFICATION_VERSION = '0.3.1'
6
6
  end
7
7
  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.0
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-03 00:00:00.000000000 Z
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.0
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.0
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