notification_hub 0.1.4 → 0.1.5
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/generators/notification_hub/templates/jobs/active_job.rb +8 -2
- data/lib/generators/notification_hub/templates/jobs/sidekiq_job.rb +8 -2
- data/lib/notification_hub.rb +29 -7
- data/lib/notification_hub/subscription_manager.rb +6 -6
- data/lib/notification_hub/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8895e84d5c3c0daf5214e941b639693ae9385e6
|
4
|
+
data.tar.gz: 91502ea58fb041ae93b06951265a471e12469fa7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cf1e16be88979de44447a2885941960ef7539d120417adc7b09db1c042d026abe9da1cf960a8345857ac5ba6521f71037b8de3b3102088f3e33ffc24a1e56c8
|
7
|
+
data.tar.gz: 3f6b80333ab94cd4d88b2cd6633a81cff22a9f5779cf44979f07cc4c8aa83b3a96d59c8faea96b16a8c2b2648d5f1bd6acc9316db7d09cf5c2687749e3c49a0e
|
@@ -1,7 +1,13 @@
|
|
1
1
|
class NotificationHubJob < ActiveJob::Base
|
2
2
|
queue_as :<%= queue_name %>
|
3
3
|
|
4
|
-
def perform(association_model_id, event_code, data,
|
5
|
-
|
4
|
+
def perform(method, association_model_id, event_code, data, device_details=nil,
|
5
|
+
channel_code=nil, gateway_code=nil)
|
6
|
+
if method == "deliver"
|
7
|
+
NotificationHub.send_message(association_model_id, event_code, data)
|
8
|
+
elsif method == "deliver_direct"
|
9
|
+
NotificationHub.send_direct_message(event_code, data, device_details,
|
10
|
+
channel_code, gateway_code)
|
11
|
+
end
|
6
12
|
end
|
7
13
|
end
|
@@ -2,7 +2,13 @@ class NotificationHubJob
|
|
2
2
|
include Sidekiq::Worker
|
3
3
|
sidekiq_options :queue => :<%= queue_name %>, :retry => 10, :backtrace => true
|
4
4
|
|
5
|
-
def perform(association_model_id, event_code, data,
|
6
|
-
|
5
|
+
def perform(method, association_model_id, event_code, data, device_details=nil,
|
6
|
+
channel_code=nil, gateway_code=nil)
|
7
|
+
if method == "deliver"
|
8
|
+
NotificationHub.send_message(association_model_id, event_code, data)
|
9
|
+
elsif method == "deliver_direct"
|
10
|
+
NotificationHub.send_direct_message(event_code, data, device_details,
|
11
|
+
channel_code, gateway_code)
|
12
|
+
end
|
7
13
|
end
|
8
14
|
end
|
data/lib/notification_hub.rb
CHANGED
@@ -29,19 +29,31 @@ module NotificationHub
|
|
29
29
|
"NotificationHub::Channels::#{channel.to_s.camelize}::#{gateway.to_s.camelize}".constantize.new(options)
|
30
30
|
end
|
31
31
|
|
32
|
-
def deliver_now(association_model_id, event_code, data
|
33
|
-
send_message(association_model_id, event_code, data
|
32
|
+
def deliver_now(association_model_id, event_code, data)
|
33
|
+
send_message(association_model_id, event_code, data)
|
34
34
|
end
|
35
35
|
|
36
|
-
def deliver(association_model_id, event_code, data
|
36
|
+
def deliver(association_model_id, event_code, data)
|
37
37
|
if NotificationHubJob.respond_to?("perform_later".to_sym)
|
38
|
-
NotificationHubJob.perform_later(association_model_id, event_code, data
|
38
|
+
NotificationHubJob.perform_later("deliver", association_model_id, event_code, data)
|
39
39
|
elsif NotificationHubJob.respond_to?("perform_async".to_sym)
|
40
|
-
NotificationHubJob.perform_async(association_model_id, event_code, data
|
40
|
+
NotificationHubJob.perform_async("deliver", association_model_id, event_code, data)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
44
|
+
def deliver_direct_now(event_code, data, device_details, channel_code, gateway_code=nil)
|
45
|
+
send_direct_message(event_code, data, device_details, channel_code, gateway_code)
|
46
|
+
end
|
47
|
+
|
48
|
+
def deliver_direct(event_code, data, device_details, channel_code, gateway_code=nil)
|
49
|
+
if NotificationHubJob.respond_to?("perform_later".to_sym)
|
50
|
+
NotificationHubJob.perform_later("deliver_direct", nil, event_code, data, device_details, channel_code, gateway_code)
|
51
|
+
elsif NotificationHubJob.respond_to?("perform_async".to_sym)
|
52
|
+
NotificationHubJob.perform_async("deliver_direct", nil, event_code, data, device_details, channel_code, gateway_code)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def send_message(association_model_id, event_code, data_wrapper)
|
45
57
|
# Fetch data from the database if record id is passed.
|
46
58
|
data = {}
|
47
59
|
data_wrapper.each do |key,value|
|
@@ -74,7 +86,17 @@ module NotificationHub
|
|
74
86
|
end
|
75
87
|
end
|
76
88
|
|
77
|
-
def
|
89
|
+
def send_direct_message(event_code, data_wrapper, device_details, channel_code, gateway_code=nil)
|
90
|
+
# Fetch data from the database if record id is passed.
|
91
|
+
data = {}
|
92
|
+
data_wrapper.each do |key,value|
|
93
|
+
if value.is_a?(Integer)
|
94
|
+
data[key.to_sym] = key.to_s.classify.constantize.find_by_id(value)
|
95
|
+
else
|
96
|
+
data[key.to_sym] = value
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
78
100
|
if gateway_code.present?
|
79
101
|
channel_const = "NotificationHub::Channels::#{channel_code.camelize}::#{gateway_code.camelize}".constantize
|
80
102
|
else
|
@@ -6,9 +6,9 @@ module NotificationHub
|
|
6
6
|
|
7
7
|
def create_subscription(association_model_id, event_code, channel_code, device_details=nil)
|
8
8
|
subscription = NotificationHub::Subscription.
|
9
|
-
where("#{NotificationHub.association_model}_id" => association_model_id,
|
10
|
-
|
11
|
-
|
9
|
+
where("#{NotificationHub.association_model}_id" => association_model_id,
|
10
|
+
event_code: event_code, channel_code: channel_code).first_or_create!
|
11
|
+
|
12
12
|
if device_details
|
13
13
|
device = NotificationHub::DeviceManager.create_device(association_model_id, channel_code, device_details)
|
14
14
|
|
@@ -20,7 +20,7 @@ module NotificationHub
|
|
20
20
|
|
21
21
|
def update_subscription(id, event_code, channel_code, device_details)
|
22
22
|
subscription = NotificationHub::Subscription.find(id)
|
23
|
-
subscription.update_attributes(event_code: event_code, channel_code: channel_code)
|
23
|
+
subscription.update_attributes!(event_code: event_code, channel_code: channel_code)
|
24
24
|
if device_details
|
25
25
|
subscription.notification_hub_subscription_devices.destroy_all
|
26
26
|
association_model_id = eval("subscription.#{NotificationHub.association_model}.id")
|
@@ -35,10 +35,10 @@ module NotificationHub
|
|
35
35
|
def create_subscription_device(association_model_id, device_id, event_code, channel_code)
|
36
36
|
subscription = NotificationHub::Subscription.
|
37
37
|
where("#{NotificationHub.association_model}_id" => association_model_id, event_code: event_code,
|
38
|
-
channel_code: channel_code).first_or_create
|
38
|
+
channel_code: channel_code).first_or_create!
|
39
39
|
|
40
40
|
subscription_device = NotificationHub::SubscriptionDevice.where(notification_hub_subscription_id:
|
41
|
-
subscription.id, notification_hub_device_id: device_id).first_or_create
|
41
|
+
subscription.id, notification_hub_device_id: device_id).first_or_create!
|
42
42
|
|
43
43
|
subscription_device
|
44
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notification_hub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Viduranga Wijesooriya
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05
|
11
|
+
date: 2017-06-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|