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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e7f71402bbe668a01735d421b5a70a08008b0b2f
4
- data.tar.gz: 7cbaeedc0f217c0dbd54154c9f4f122b1613108d
3
+ metadata.gz: a8895e84d5c3c0daf5214e941b639693ae9385e6
4
+ data.tar.gz: 91502ea58fb041ae93b06951265a471e12469fa7
5
5
  SHA512:
6
- metadata.gz: 7116589dc0ca3bc5b14b15cbf2235116d34ed78eabf22d3e48b4a4d470004c267dbda3b8ebd10e820545e681c7276f7b7a9f3ae1f23105e1d4d85152d33562bf
7
- data.tar.gz: 63d42acaa6ba0206d0147d83561d33c6589c81efe4be762dfa0eca7a1d705e302a9ebd3c838b803f8f2ef3aae35d71c99d8befa94814a289088b87b3d3937ca2
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, options)
5
- NotificationHub.send_message(association_model_id, event_code, data, options)
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, options)
6
- NotificationHub.send_message(association_model_id, event_code, data, options)
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
@@ -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, options=nil)
33
- send_message(association_model_id, event_code, data, options)
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, options=nil)
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, options)
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, options)
40
+ NotificationHubJob.perform_async("deliver", association_model_id, event_code, data)
41
41
  end
42
42
  end
43
43
 
44
- def send_message(association_model_id, event_code, data_wrapper, options)
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 send_direct(event_code, data, device_details, channel_code, gateway_code=nil)
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, event_code: event_code,
10
- channel_code: channel_code).first_or_create
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
@@ -1,3 +1,3 @@
1
1
  module NotificationHub
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  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
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-31 00:00:00.000000000 Z
11
+ date: 2017-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler