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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e64d938c6604551cb1fe22ff8bfd8b8a03e47f2d
4
- data.tar.gz: 0343864f2d302e89e463aef31d2ee9bde660aefc
3
+ metadata.gz: dc6a4814cd91348b337477f10ffc275785792bc5
4
+ data.tar.gz: d88f65bfab26aed81fd7180cecd188d08d5eb904
5
5
  SHA512:
6
- metadata.gz: bdd7e9796d7987e5c85725971673a65567ddd396fc5fe104f8e2f7b9d1f048bdd9f1cc163ab1bcb5e1530596de890a458a07ba47e844e9a5199a7bf457f58abc
7
- data.tar.gz: 11e686dff90f5eff11c2a15fc892cfa35922f35e6ab45da0942e5ac8e2a0dc9f549241b6328ceec0cd883df5e831afa4b8a7725e90eaba7094589c5bf425a11f
6
+ metadata.gz: 0c0e6af1ba87305910e00c958a0fb227f6a90efb498453279f198600e903056ad67e04283de20971ef2241d6b5d9e03333771f5ef23edda880534968d47414d5
7
+ data.tar.gz: 52132034a346cfb8b52cfa7efc776998d69366f7cb79e55ed8284773b534d71444594da4eec50ab8ccfe8911d1b08291e028482017dca61d9a62d2c0316dba34
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Moromi::Aws::Sns
2
2
 
3
+ [![Latest Version](https://img.shields.io/gem/v/moromi-aws-sns.svg)](http://rubygems.org/gems/moromi-aws-sns)
4
+
3
5
  AWS SNS client.
4
6
 
5
7
  ## Installation
@@ -11,27 +11,44 @@ module Moromi
11
11
  @platform_application_arn = platform_application_arn
12
12
  end
13
13
 
14
- def register(token:, force_enable: true)
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[:endpoint_arn]
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:, endpoint_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:, params:, sandbox: true)
59
+ def send_apns(arn, params)
43
60
  options = {
44
61
  target_arn: arn,
45
- message: build_apns_json_message(params, sandbox),
62
+ message: build_apns_json_message(params),
46
63
  message_structure: 'json'
47
64
  }
48
- client.publish(options)
65
+ publish(options)
49
66
  end
50
67
 
51
- def send_apns_to_topic(topic_arn:, params:, sandbox: true)
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, sandbox),
71
+ message: build_apns_json_message(params),
55
72
  message_structure: 'json'
56
73
  }
57
- client.publish(options)
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, sandbox)
71
- endpoint = sandbox ? 'APNS_SANDBOX' : 'APNS'
72
- {endpoint => params.to_json}.to_json
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
@@ -1,7 +1,7 @@
1
1
  module Moromi
2
2
  module Aws
3
3
  module Sns
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  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.1.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-04 00:00:00.000000000 Z
11
+ date: 2016-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk