icalia-sdk-event-notification 0.3.4 → 0.3.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68d43a0fe5186e878f12b625757d4caf2cb2d4042a3926bc2b70258f30b5aa5d
4
- data.tar.gz: 90e43d36c1f4b0c0c9e359815ad3c003e04df237dc0d4789a92edeb18afe5412
3
+ metadata.gz: 262b17e89332287df31286f253e822e23651a54fe0dc023ecec7718daa0cab25
4
+ data.tar.gz: 215cfbc97c5ebe34f04f0de471692bb780fb0179111d383ac251ba8d424d1109
5
5
  SHA512:
6
- metadata.gz: 6aa2008b800eacc27622322c159d88bef9babc73a24afd73e76e5ac2783e12074e324b86d08ef5ca71b68599b7bdfa6606f412547acb9711881dfb64c958fd0a
7
- data.tar.gz: aeeea190256615ffb363603ca9c9af04ab9103f8a421f53ac92ab6a001d4a2457a7680b77951ba438cdfaa6b96821a0ffee8e9eba6130d14a8033a139ee6cb72
6
+ metadata.gz: 9e5b3ba20bf2fd21db199f1dad479e8b725a7fa203ce0a81a052edb1d1b5c3174e744a9c37c00b8c02118dfa1cdfc3d9a8a03c332c83dd68c6f7b803b7f3f906
7
+ data.tar.gz: f25855f418711b1a2e40785f19aa51078135b60fdbc63fb8c11487947c95372862d712e7cc0b23bf0193fb38530a9d4c5a9ef580b467223725d3500fa677cc0d
data/lib/.DS_Store ADDED
Binary file
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'icalia-sdk-event-core'
3
+ require 'icalia-sdk-core'
4
4
 
5
5
  module Icalia::Event
6
6
  module Subscriber
@@ -18,7 +18,7 @@ module Icalia::Event
18
18
 
19
19
  def perform(message)
20
20
  raw_data = MessagePack.unpack(message.data)
21
- event = Icalia::Event::Deserializer.new(raw_data).perform
21
+ event = Icalia::Deserializer.new(raw_data).perform
22
22
  event_class_name = event.class.name.demodulize
23
23
 
24
24
  if (processor_class = processor_map[event_class_name])
@@ -37,25 +37,50 @@ module Icalia::Event
37
37
  end
38
38
 
39
39
  def subscription_name
40
- Rails.application.class.module_parent_name.underscore +
41
- '-' +
42
- ENV.fetch('DEPLOYMENT_NAME', Rails.env).downcase +
43
- "-#{topic_name}"
40
+ "#{subscription_name_prefix}-#{topic_name}"
44
41
  end
45
42
 
46
- def ensure_subscription_exists
43
+ def auto_subscribe
47
44
  client = Subserver::Pubsub.client
48
45
  topic = client.topic(topic_name) || client.create_topic(topic_name)
49
46
 
50
47
  topic.subscription(subscription_name) ||
51
- topic.subscribe(subscription_name)
48
+ topic.subscribe(subscription_name)
52
49
  end
53
50
 
54
51
  def process(event_class_name, options = {})
55
- processor = options.delete :with
56
- return unless processor.present?
52
+ return unless (processor = options.delete(:with)).present?
53
+
57
54
  processor_map[event_class_name] = processor
58
55
  end
56
+
57
+ protected
58
+
59
+ def subscription_name_prefix
60
+ "#{rails_app_name.underscore}-#{deployment_name.underscore}"
61
+ end
62
+
63
+ def deployment_name
64
+ ENV.fetch('DEPLOYMENT_NAME', Rails.env)
65
+ end
66
+
67
+ def rails_app_name
68
+ return rails_app_name_since_rails_six if parent_name_deprecated?
69
+
70
+ rails_app_name_until_rails_six
71
+ end
72
+
73
+ def parent_name_deprecated?
74
+ Rails::VERSION::MAJOR >= 6
75
+ end
76
+
77
+ def rails_app_name_until_rails_six
78
+ Rails.application.class.parent_name
79
+ end
80
+
81
+ def rails_app_name_since_rails_six
82
+ Rails.application.class.module_parent_name
83
+ end
59
84
  end
60
85
  end
61
86
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Icalia
4
- module Event
5
- NOTIFICATION_VERSION = '0.3.4'
4
+ module SDK
5
+ EVENT_NOTIFICATION_VERSION = '0.3.8'
6
6
  end
7
7
  end
@@ -1,19 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'icalia-sdk-event-core'
3
+ require 'icalia-sdk-core'
4
+ require 'icalia-sdk-event-notification/version'
4
5
 
5
6
  require 'active_support'
6
7
  require 'active_support/core_ext/object/blank'
7
8
 
8
9
  module Icalia
9
10
  module Event
10
- autoload :Version, 'icalia-sdk-event-notification/version'
11
- autoload :Publisher, 'icalia-sdk-event-notification/publisher'
12
- autoload :Subscriber, 'icalia-sdk-event-notification/subscriber'
13
- autoload :Notification, 'icalia-sdk-event-notification/notification'
14
-
15
- autoload :TopicMessageProcessing,
16
- 'icalia-sdk-event-notification/topic_message_processing'
11
+ autoload :Publisher, 'icalia/event/publisher'
12
+ autoload :Subscriber, 'icalia/event/subscriber'
13
+ autoload :TopicMessageProcessing, 'icalia/event/topic_message_processing'
17
14
 
18
15
  mattr_reader :deferred_publishing, default: true
19
16
  end
metadata CHANGED
@@ -1,71 +1,71 @@
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
4
+ version: 0.3.8
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-16 00:00:00.000000000 Z
11
+ date: 2022-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: icalia-sdk-event-core
14
+ name: icalia-sdk-core
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.4
19
+ version: 0.3.8
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.4
26
+ version: 0.3.8
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 5.2.0
33
+ version: '5.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 5.2.0
40
+ version: '5.2'
41
41
  - !ruby/object:Gem::Dependency
42
- name: msgpack
42
+ name: google-cloud-pubsub
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.3'
47
+ version: '0.31'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.3'
54
+ version: '0.31'
55
55
  - !ruby/object:Gem::Dependency
56
- name: google-cloud-pubsub
56
+ name: msgpack
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0.31'
61
+ version: '1.3'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.31'
68
+ version: '1.3'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: bundler
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '10.0'
89
+ version: '13.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '10.0'
96
+ version: '13.0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rspec
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -108,20 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '3.0'
111
- description: Official Ruby gem for Icalia Events via AWS Simple Notification Service.
112
- This gem is part of the Icalia SDK for Ruby.
111
+ description: Official Ruby gem for Icalia Event Notification via Google Cloud Pub/Sub
112
+ Service. This gem is part of the Icalia SDK for Ruby.
113
113
  email:
114
114
  - vov@icalialabs.com
115
115
  executables: []
116
116
  extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
+ - lib/.DS_Store
119
120
  - lib/icalia-sdk-event-notification.rb
120
- - lib/icalia-sdk-event-notification/notification.rb
121
- - lib/icalia-sdk-event-notification/publisher.rb
122
- - lib/icalia-sdk-event-notification/subscriber.rb
123
- - lib/icalia-sdk-event-notification/topic_message_processing.rb
124
121
  - lib/icalia-sdk-event-notification/version.rb
122
+ - lib/icalia/event/publisher.rb
123
+ - lib/icalia/event/subscriber.rb
124
+ - lib/icalia/event/topic_message_processing.rb
125
125
  homepage: https://github.com/IcaliaLabs/icalia-sdk-ruby
126
126
  licenses:
127
127
  - MIT
@@ -148,5 +148,5 @@ requirements: []
148
148
  rubygems_version: 3.0.3
149
149
  signing_key:
150
150
  specification_version: 4
151
- summary: Icalia SDK Events for Ruby - via AWS Simple Notification Service
151
+ summary: Icalia SDK Event Notification for Ruby
152
152
  test_files: []
@@ -1,75 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Icalia::Event
4
- #= Icalia::Event::Notification
5
- class Notification
6
- attr_reader :data,
7
- :topic,
8
- :event_data,
9
- :included_data,
10
- :metadata
11
-
12
- def initialize(raw_notification)
13
- @data = parse_raw_notification raw_notification
14
- end
15
-
16
- def topic_arn; data.fetch :topic_arn; end
17
- def topic; @topic ||= topic_arn.split(':')[5..-1].join(':'); end
18
-
19
- def metadata; @metadata ||= data.dig :message, :meta; end
20
- def emitter; metadata.dig :emitter; end
21
-
22
- def message; data.fetch :message; end
23
-
24
- def event_data; @event_data ||= deserialize_data(message.fetch(:data)); end
25
- def action; event_data.fetch(:action, 'message'); end
26
-
27
- def included_data
28
- @included_data ||= message
29
- .fetch(:included)
30
- .each_with_object({}) do |data, included|
31
- included[data.slice(:id, :type)] = deserialize_data(data)
32
- end
33
- end
34
-
35
- def fetch_data(property_name)
36
- fetched_property = fetch_attribute property_name
37
- return fetched_property if fetched_property.present?
38
-
39
- fetch_relationship property_name
40
- end
41
-
42
- delegate :parse_raw_notification, :deserialize_data, to: :class
43
-
44
- class << self
45
- delegate :decode, to: ActiveSupport::JSON, prefix: :json
46
-
47
- def parse_raw_notification(raw_notification)
48
- json_decode(raw_notification)
49
- .transform_keys(&:underscore)
50
- .tap { |parsed| parsed['message'] = json_decode parsed['message'] }
51
- .with_indifferent_access
52
- end
53
-
54
- def deserialize_data(data)
55
- klass = data.fetch(:type).underscore.classify
56
- deserializer = "Icalia::Event::Deserializable#{klass}".constantize
57
- deserializer.call(data).with_indifferent_access
58
- end
59
- end
60
-
61
- private
62
-
63
- def fetch_attribute(attribute_name)
64
- message.dig(:data, :attributes, attribute_name) ||
65
- message.dig(:data, :attributes, attribute_name.to_s.dasherize)
66
- end
67
-
68
- def fetch_relationship(relationship_name)
69
- rel = message.dig(:data, :relationships, relationship_name) ||
70
- message.dig(:data, :relationships, relationship_name.to_s.dasherize)
71
- return unless rel.present?
72
- included_data[rel.fetch(:data)]
73
- end
74
- end
75
- end