moromi-aws-sns 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/moromi/aws/sns/client.rb +40 -15
- data/lib/moromi/aws/sns/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: dc6a4814cd91348b337477f10ffc275785792bc5
|
4
|
+
data.tar.gz: d88f65bfab26aed81fd7180cecd188d08d5eb904
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c0e6af1ba87305910e00c958a0fb227f6a90efb498453279f198600e903056ad67e04283de20971ef2241d6b5d9e03333771f5ef23edda880534968d47414d5
|
7
|
+
data.tar.gz: 52132034a346cfb8b52cfa7efc776998d69366f7cb79e55ed8284773b534d71444594da4eec50ab8ccfe8911d1b08291e028482017dca61d9a62d2c0316dba34
|
data/README.md
CHANGED
@@ -11,27 +11,44 @@ module Moromi
|
|
11
11
|
@platform_application_arn = platform_application_arn
|
12
12
|
end
|
13
13
|
|
14
|
-
def register(token
|
14
|
+
def register(token, force_enable: true)
|
15
15
|
params = {
|
16
16
|
platform_application_arn: @platform_application_arn,
|
17
17
|
token: token
|
18
18
|
}
|
19
|
-
params[:attributes] = {'Enabled' => 'true'} if force_enable
|
20
19
|
|
21
20
|
response = client.create_platform_endpoint(params)
|
22
|
-
response
|
21
|
+
arn = response.endpoint_arn
|
22
|
+
|
23
|
+
if force_enable
|
24
|
+
params = {
|
25
|
+
endpoint_arn: arn,
|
26
|
+
attributes: {'Enabled' => 'true'}
|
27
|
+
}
|
28
|
+
client.set_endpoint_attributes(params)
|
29
|
+
end
|
30
|
+
|
31
|
+
arn
|
23
32
|
end
|
24
33
|
|
25
|
-
def subscribe(topic_arn
|
34
|
+
def subscribe(topic_arn, endpoint_arn)
|
26
35
|
params = {
|
27
36
|
topic_arn: topic_arn,
|
28
37
|
protocol: 'application',
|
29
38
|
endpoint: endpoint_arn
|
30
39
|
}
|
31
|
-
client.subscribe(params)
|
40
|
+
response = client.subscribe(params)
|
41
|
+
response.subscription_arn
|
42
|
+
end
|
43
|
+
|
44
|
+
def unsubscribe(subscription_arn)
|
45
|
+
params = {
|
46
|
+
subscription_arn: subscription_arn
|
47
|
+
}
|
48
|
+
client.unsubscribe(params)
|
32
49
|
end
|
33
50
|
|
34
|
-
def inactive(arn
|
51
|
+
def inactive(arn)
|
35
52
|
params = {
|
36
53
|
endpoint_arn: arn,
|
37
54
|
attributes: {'Enabled' => 'false'}
|
@@ -39,22 +56,27 @@ module Moromi
|
|
39
56
|
client.set_endpoint_attributes(params)
|
40
57
|
end
|
41
58
|
|
42
|
-
def send_apns(arn
|
59
|
+
def send_apns(arn, params)
|
43
60
|
options = {
|
44
61
|
target_arn: arn,
|
45
|
-
message: build_apns_json_message(params
|
62
|
+
message: build_apns_json_message(params),
|
46
63
|
message_structure: 'json'
|
47
64
|
}
|
48
|
-
|
65
|
+
publish(options)
|
49
66
|
end
|
50
67
|
|
51
|
-
def send_apns_to_topic(topic_arn
|
68
|
+
def send_apns_to_topic(topic_arn, params)
|
52
69
|
options = {
|
53
70
|
topic_arn: topic_arn,
|
54
|
-
message: build_apns_json_message(params
|
71
|
+
message: build_apns_json_message(params),
|
55
72
|
message_structure: 'json'
|
56
73
|
}
|
57
|
-
|
74
|
+
publish(options)
|
75
|
+
end
|
76
|
+
|
77
|
+
def publish(options)
|
78
|
+
response = client.publish(options)
|
79
|
+
response.message_id
|
58
80
|
end
|
59
81
|
|
60
82
|
private
|
@@ -67,9 +89,12 @@ module Moromi
|
|
67
89
|
@client ||= ::Aws::SNS::Client.new(region: @region, credentials: credentials)
|
68
90
|
end
|
69
91
|
|
70
|
-
def build_apns_json_message(params
|
71
|
-
|
72
|
-
|
92
|
+
def build_apns_json_message(params)
|
93
|
+
{
|
94
|
+
'default': '',
|
95
|
+
'APNS_SANDBOX' => params.to_json,
|
96
|
+
'APNS' => params.to_json
|
97
|
+
}.to_json
|
73
98
|
end
|
74
99
|
end
|
75
100
|
end
|
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.2.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: 2016-10-
|
11
|
+
date: 2016-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|