moromi-aws-sns 0.6.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/moromi/aws/sns/client.rb +13 -13
- data/lib/moromi/aws/sns/message/apns.rb +64 -0
- data/lib/moromi/aws/sns/message/base.rb +13 -7
- data/lib/moromi/aws/sns/message/fcm.rb +75 -0
- data/lib/moromi/aws/sns/message/parameter.rb +23 -3
- data/lib/moromi/aws/sns/version.rb +1 -1
- data/lib/moromi/aws/sns.rb +2 -0
- data/moromi-aws-sns.gemspec +3 -0
- metadata +19 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9be304eada55a17272c684d5700ca9778241c95
|
4
|
+
data.tar.gz: ef097f330567a35a4c65d863095164833e77faf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e06da11f8bde51e9e3e35c83be4b95fade05b1f127dcef6f794fa4ba0b36708e35eb390811b3100f402e74b9336053253ccf044e65094245637ee34bab7eed44
|
7
|
+
data.tar.gz: f8b1502822a12a9bc9819fc1d73d09ec2471d03c0ba0b36079c6a1719cae7cc2c9a3fa3df9000cd7dac06cbacb5679f29ff08a196f873a9dc766d0580afef80d
|
@@ -56,30 +56,25 @@ module Moromi
|
|
56
56
|
end
|
57
57
|
|
58
58
|
# @param [String] arn
|
59
|
-
# @param [Moromi::Aws::Sns::Message::
|
60
|
-
def
|
59
|
+
# @param [Moromi::Aws::Sns::Message::Parameter] parameter
|
60
|
+
def publish(arn, parameter)
|
61
61
|
options = {
|
62
62
|
target_arn: arn,
|
63
|
-
message:
|
63
|
+
message: parameter.to_json,
|
64
64
|
message_structure: 'json'
|
65
65
|
}
|
66
|
-
|
66
|
+
call_publish(options)
|
67
67
|
end
|
68
68
|
|
69
69
|
# @param [String] topic_arn
|
70
|
-
# @param [Moromi::Aws::Sns::Message::
|
71
|
-
def
|
70
|
+
# @param [Moromi::Aws::Sns::Message::Parameter] parameter
|
71
|
+
def publish_to_topic(topic_arn, parameter)
|
72
72
|
options = {
|
73
73
|
topic_arn: topic_arn,
|
74
|
-
message:
|
74
|
+
message: parameter.to_json,
|
75
75
|
message_structure: 'json'
|
76
76
|
}
|
77
|
-
|
78
|
-
end
|
79
|
-
|
80
|
-
def publish(options)
|
81
|
-
response = client.publish(options)
|
82
|
-
response.message_id
|
77
|
+
call_publish(options)
|
83
78
|
end
|
84
79
|
|
85
80
|
def get_endpoint_attributes(endpoint_arn)
|
@@ -99,6 +94,11 @@ module Moromi
|
|
99
94
|
def client
|
100
95
|
@client ||= ::Aws::SNS::Client.new(region: @region, credentials: credentials)
|
101
96
|
end
|
97
|
+
|
98
|
+
def call_publish(options)
|
99
|
+
response = client.publish(options)
|
100
|
+
response.message_id
|
101
|
+
end
|
102
102
|
end
|
103
103
|
end
|
104
104
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Moromi
|
2
|
+
module Aws
|
3
|
+
module Sns
|
4
|
+
module Message
|
5
|
+
class Apns < Base
|
6
|
+
attr_reader :alert
|
7
|
+
attr_reader :badge
|
8
|
+
attr_reader :sound
|
9
|
+
attr_reader :content_available
|
10
|
+
attr_reader :mutable_content
|
11
|
+
attr_reader :category
|
12
|
+
attr_reader :priority
|
13
|
+
attr_reader :type
|
14
|
+
attr_reader :custom_data
|
15
|
+
|
16
|
+
def initialize(alert:, badge:, sound: 'default', content_available: 1, mutable_content: 0, category: nil,
|
17
|
+
priority: 10, type: nil, custom_data: {})
|
18
|
+
@alert = alert
|
19
|
+
@badge = badge
|
20
|
+
@sound = sound
|
21
|
+
@content_available = content_available
|
22
|
+
@mutable_content = mutable_content
|
23
|
+
@category = category
|
24
|
+
@priority = priority
|
25
|
+
@type = type || self.class.name
|
26
|
+
@custom_data = setup_initial_custom_data({type: @type}.merge(custom_data))
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_hash
|
30
|
+
{
|
31
|
+
alert: @alert,
|
32
|
+
badge: @badge,
|
33
|
+
sound: @sound,
|
34
|
+
content_available: @content_available,
|
35
|
+
mutable_content: @mutable_content,
|
36
|
+
category: @category,
|
37
|
+
priority: @priority,
|
38
|
+
type: @type,
|
39
|
+
custom_data: @custom_data
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_message_json
|
44
|
+
aps = to_hash
|
45
|
+
%i[custom_data type].each { |k| aps.delete(k) }
|
46
|
+
@custom_data.merge({aps: aps}).to_json
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def setup_initial_custom_data(custom_data)
|
52
|
+
custom_data
|
53
|
+
end
|
54
|
+
|
55
|
+
class << self
|
56
|
+
def build_silent_push_message(priority: 10, custom_data: {})
|
57
|
+
new('', nil, sound: nil, content_available: 1, priority: priority, custom_data: custom_data)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -1,20 +1,26 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
1
3
|
module Moromi
|
2
4
|
module Aws
|
3
5
|
module Sns
|
4
6
|
module Message
|
5
|
-
|
6
|
-
|
7
|
-
def to_parameter
|
7
|
+
class Base
|
8
|
+
def to_hash
|
8
9
|
raise NotImplementedError
|
9
10
|
end
|
10
11
|
|
11
|
-
def
|
12
|
+
def to_message_json
|
12
13
|
raise NotImplementedError
|
13
14
|
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
def ==(other)
|
17
|
+
to_hash == other.to_hash
|
18
|
+
end
|
19
|
+
|
20
|
+
class << self
|
21
|
+
def build_from_hash(hash)
|
22
|
+
new(hash)
|
23
|
+
end
|
18
24
|
end
|
19
25
|
end
|
20
26
|
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
module Moromi
|
2
|
+
module Aws
|
3
|
+
module Sns
|
4
|
+
module Message
|
5
|
+
class Fcm < Base
|
6
|
+
# https://firebase.google.com/docs/cloud-messaging/http-server-ref?hl=ja#notification-payload-support
|
7
|
+
attr_reader :title
|
8
|
+
attr_reader :body
|
9
|
+
attr_reader :android_channel_id
|
10
|
+
attr_reader :icon
|
11
|
+
attr_reader :sound
|
12
|
+
attr_reader :tag
|
13
|
+
attr_reader :color
|
14
|
+
attr_reader :click_action
|
15
|
+
attr_reader :body_loc_key
|
16
|
+
attr_reader :body_loc_args
|
17
|
+
attr_reader :title_loc_key
|
18
|
+
attr_reader :title_loc_args
|
19
|
+
|
20
|
+
def initialize(title: nil, body: nil, android_channel_id: nil, icon: nil, sound: nil, tag: nil, color: nil,
|
21
|
+
click_action: nil,
|
22
|
+
body_loc_key: nil, body_loc_args: nil,
|
23
|
+
title_loc_key: nil, title_loc_args: nil,
|
24
|
+
type: nil, custom_data: {})
|
25
|
+
@title = title
|
26
|
+
@body = body
|
27
|
+
@android_channel_id = android_channel_id
|
28
|
+
@icon = icon
|
29
|
+
@sound = sound
|
30
|
+
@tag = tag
|
31
|
+
@color = color
|
32
|
+
@click_action = click_action
|
33
|
+
@body_loc_key = body_loc_key
|
34
|
+
@body_loc_args = body_loc_args
|
35
|
+
@title_loc_key = title_loc_key
|
36
|
+
@title_loc_args = title_loc_args
|
37
|
+
@type = type || self.class.name
|
38
|
+
@custom_data = setup_initial_custom_data({type: @type}.merge(custom_data))
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_hash
|
42
|
+
{
|
43
|
+
title: @title,
|
44
|
+
body: @body,
|
45
|
+
android_channel_id: @android_channel_id,
|
46
|
+
icon: @icon,
|
47
|
+
sound: @sound,
|
48
|
+
tag: @tag,
|
49
|
+
color: @color,
|
50
|
+
click_action: @click_action,
|
51
|
+
body_loc_key: @body_loc_key,
|
52
|
+
body_loc_args: @body_loc_args,
|
53
|
+
title_loc_key: @title_loc_key,
|
54
|
+
title_loc_args: @title_loc_args,
|
55
|
+
type: @type,
|
56
|
+
custom_data: @custom_data
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_message_json
|
61
|
+
notification = to_hash
|
62
|
+
%i[custom_data type].each { |k| notification.delete(k) }
|
63
|
+
{notification: notification, data: @custom_data}.to_json
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def setup_initial_custom_data(custom_data)
|
69
|
+
custom_data
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -5,19 +5,39 @@ module Moromi
|
|
5
5
|
module Sns
|
6
6
|
module Message
|
7
7
|
class Parameter
|
8
|
+
# @param [Moromi::Aws::Sns::Message::Apns] apns
|
9
|
+
# @param [Moromi::Aws::Sns::Message::Fcm] gcm
|
8
10
|
def initialize(apns: nil, gcm: nil)
|
9
11
|
@apns = apns
|
10
12
|
@gcm = gcm
|
11
13
|
end
|
12
14
|
|
15
|
+
def to_hash
|
16
|
+
{
|
17
|
+
klass_name: self.class.name,
|
18
|
+
apns: {name: @apns&.class&.name, data: @apns&.to_hash},
|
19
|
+
gcm: {name: @gcm&.class&.name, data: @gcm&.to_hash}
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
13
23
|
def to_json
|
14
24
|
{
|
15
25
|
'default': '',
|
16
|
-
'APNS_SANDBOX': @apns&.
|
17
|
-
'APNS': @apns&.
|
18
|
-
'GCM': @gcm&.
|
26
|
+
'APNS_SANDBOX': @apns&.to_message_json,
|
27
|
+
'APNS': @apns&.to_message_json,
|
28
|
+
'GCM': @gcm&.to_message_json
|
19
29
|
}.compact.to_json
|
20
30
|
end
|
31
|
+
|
32
|
+
def self.build_from_hash(hash)
|
33
|
+
apns_klass = hash.dig(:apns, :name)&.safe_constantize
|
34
|
+
apns = apns_klass&.build_from_hash(hash.dig(:apns, :data))
|
35
|
+
|
36
|
+
gcm_klass = hash.dig(:gcm, :name)&.safe_constantize
|
37
|
+
gcm = gcm_klass&.build_from_hash(hash.dig(:gcm, :data))
|
38
|
+
|
39
|
+
new(apns: apns, gcm: gcm)
|
40
|
+
end
|
21
41
|
end
|
22
42
|
end
|
23
43
|
end
|
data/lib/moromi/aws/sns.rb
CHANGED
data/moromi-aws-sns.gemspec
CHANGED
@@ -19,7 +19,10 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
+
spec.required_ruby_version = '>= 2.2'
|
23
|
+
|
22
24
|
spec.add_dependency 'aws-sdk', '~> 2'
|
25
|
+
spec.add_dependency 'activesupport', ['>= 4.2']
|
23
26
|
|
24
27
|
spec.add_development_dependency "bundler", "~> 1.12"
|
25
28
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: moromi-aws-sns
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takahiro Ooishi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.2'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -84,7 +98,9 @@ files:
|
|
84
98
|
- circle.yml
|
85
99
|
- lib/moromi/aws/sns.rb
|
86
100
|
- lib/moromi/aws/sns/client.rb
|
101
|
+
- lib/moromi/aws/sns/message/apns.rb
|
87
102
|
- lib/moromi/aws/sns/message/base.rb
|
103
|
+
- lib/moromi/aws/sns/message/fcm.rb
|
88
104
|
- lib/moromi/aws/sns/message/parameter.rb
|
89
105
|
- lib/moromi/aws/sns/version.rb
|
90
106
|
- moromi-aws-sns.gemspec
|
@@ -100,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
116
|
requirements:
|
101
117
|
- - ">="
|
102
118
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
119
|
+
version: '2.2'
|
104
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
121
|
requirements:
|
106
122
|
- - ">="
|