messaging_client 0.1.4 → 0.1.5

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
  SHA1:
3
- metadata.gz: 53aee60c590183fe4d36042156b1fec5ce8ffada
4
- data.tar.gz: 8a6aace9d5d714761fc0f0e8ed04b71d34d2dbef
3
+ metadata.gz: dadb5c678a9fdb5f0e6b223e34e401c95332dc0a
4
+ data.tar.gz: ae6421553882c82c2aa547952b55f2e5a42cb556
5
5
  SHA512:
6
- metadata.gz: 507beb1c204bd54e5eb364ed615982cb18f4b5361ae9f13c3c43fd39ff310aa394c0c03f94a6c5a6afa42035f31ae374c4cb132ff511bec4acb03e7f3ce4cf1a
7
- data.tar.gz: 267877d19f0f940279b76db438c33218e3c21a872103bedcfb357532d29e2f3f846826a2fe5184812d52ac277518b9525276735deb3d3aeb01d488b0ff75934a
6
+ metadata.gz: dafa32f1bed397b24a00c767130872cffa7cb818f10302b0c3b7cf35d276b876bf4d763e1a32e74b12db3ee5f1c788da9cb19c9e20f7af03b2a07c883c406748
7
+ data.tar.gz: 14142c1e17000bc145b8dd6639172535f01b0ed8ff7017fb11a25f996bdfc4b106b591d897f1d54a8a8d5b1695c62da6495331860f3404f1949a16206b9b61fa
@@ -0,0 +1,39 @@
1
+ module SnsHelper
2
+ def sns_verified?
3
+ # TODO https://docs.aws.amazon.com/sns/latest/dg/SendMessageToHttp.verify.signature.html
4
+ return true
5
+ end
6
+
7
+ def sns_message
8
+ @sns_message ||= ActiveSupport::JSON.decode(sns_data[:Message]).symbolize_keys!
9
+ end
10
+
11
+ # topic, without all the ARN
12
+ def sns_topic
13
+ sns_data[:TopicArn].match(/([^:]*)$/)[0]
14
+ end
15
+
16
+ def sns_type
17
+ request.headers['x-amz-sns-message-type']
18
+ end
19
+
20
+ def sns_notification_id
21
+ request.headers['x-amz-sns-message-id']
22
+ end
23
+
24
+ def sns_data
25
+ @sns_data ||= ActiveSupport::JSON.decode(request.body).symbolize_keys!
26
+ end
27
+
28
+ def sns_message_id
29
+ sns_data[:MessageId]
30
+ end
31
+
32
+ def sns_set_as_received!
33
+ Rails.cache.write(sns_message_id, true, expires_in: 2.minutes)
34
+ end
35
+
36
+ def sns_duplicate_submission?
37
+ Rails.cache.read(sns_message_id)
38
+ end
39
+ end
@@ -18,7 +18,11 @@ module Messaging
18
18
  # @param key [String]
19
19
  # @param data [Hash]
20
20
  def self.post_message(key,data={})
21
- publish_to_sns(key,data)
21
+ begin
22
+ publish_to_sns(key,data)
23
+ rescue
24
+ # on transition ignore errors.
25
+ end
22
26
 
23
27
  m = Message.new(key_name: key, data: data.to_json)
24
28
  m.create
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: messaging_client
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
  - Dwayne Macgowan
@@ -59,6 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - app/helpers/sns_helper.rb
62
63
  - app/models/messaging/message.rb
63
64
  - app/models/messaging/notify_me.rb
64
65
  - config/initializers/messaging_client.rb