moromi-apns-aws_sns_adapter 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: 5e4720f19e973e8de1bef3af5dc581addc1c8bc9
4
- data.tar.gz: 67d3bc57e9aeb7a8a75513009dea51528217c45c
3
+ metadata.gz: d2daf222c5f0edca84b597c0d0612e805ac37fab
4
+ data.tar.gz: 186cfbe33939616e74b5b15039178e89540d8543
5
5
  SHA512:
6
- metadata.gz: b6169af8bdfa7c5456fb01ffae8411389f666a6570aa829c4755fc6a1d67094d36c3bc4aebb66e668bf021741bcae7c55e5f42b64be509b3257a72ef596abad3
7
- data.tar.gz: a40099cd5c1b33a1b03bb93e9d0482728117c6b9d07cf2b19b4eccd125a2143ac74179b4c225b6925970afcf0e5c1693556f836b318d9b73f2c8b3d226aa725c
6
+ metadata.gz: 89339d7eab94a846103c4773ff802895b7419c32eadcb88999456045577c5be298cce0e9032e0473cec2f529a5c6eba91b8c08f44fa3518e849baca86b646a20
7
+ data.tar.gz: 5c74aa4ce478d5dcf04707b12bcc2012cc248799635233d44163b739b507e92b0d1e3e47c849f579c49825b0f654515433d29e314b1c18c27ed511e97140fd5c
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Moromi::Apns::AwsSnsAdapter
2
2
 
3
+ [![Latest Version](https://img.shields.io/gem/v/moromi-apns-aws_sns_adapter.svg)](http://rubygems.org/gems/moromi-apns-aws_sns_adapter)
4
+
3
5
  extension for moromi-apns and moromi-aws-sns
4
6
 
5
7
  ## Installation
@@ -18,6 +20,102 @@ Or install it yourself as:
18
20
 
19
21
  $ gem install moromi-apns-aws_sns_adapter
20
22
 
23
+ ## Usage
24
+
25
+ - config/initializers/moromi/apns.rb
26
+
27
+ ```ruby
28
+ Moromi::Apns.configure do |config|
29
+ config.identifiers = {
30
+ production: 'com.example.moromi.apns.production',
31
+ in_house: 'com.example.moromi.apns.inhouse',
32
+ debug: 'com.example.moromi.apns.debug'
33
+ }
34
+ end
35
+
36
+ Moromi::Apns::AwsSnsAdapter.configure do |config|
37
+ config.aws_sns_application_arns = {
38
+ production: 'arn:aws:sns:ap-northeast-1:000000000000:app/APNS/moromi-apns-production',
39
+ in_house: 'arn:aws:sns:ap-northeast-1:000000000000:app/APNS/moromi-apns-in_house',
40
+ debug: 'arn:aws:sns:ap-northeast-1:000000000000:app/APNS_SANDBOX/moromi-apns-debug'
41
+ }
42
+ end
43
+ ```
44
+
45
+ - config/initializers/moromi/aws_sns.rb
46
+
47
+ ```ruby
48
+ module Moromi
49
+ module Aws
50
+ module Sns
51
+ class Client
52
+ # @param [Moromi::Apns::Environment::Base]
53
+ def self.create(environment)
54
+ new(ENV['AWS_ACCESS_KEY'], ENV['AWS_SECRET_ACCESS_KEY'], ENV['AWS_REGION'], environment.aws_sns_application_arn)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ ```
61
+
62
+ ### Register device
63
+
64
+ ```ruby
65
+ environment = Moromi::Apns.environment('com.example.moromi.apns.production')
66
+ arn = Moromi::Aws::Sns::Client.create(environment).register(token: token)
67
+ # store arn
68
+ ```
69
+
70
+ ### Send APNS
71
+
72
+ ```ruby
73
+ environment = Moromi::Apns.environment('com.example.moromi.apns.production')
74
+ message = Moromi::Apns::Message::Announce.make(message: 'Message')
75
+
76
+ client = Moromi::Aws::Sns::Client.create(environment)
77
+ client.send_apns_message(arn: arn, message: message, sandbox: environment.sandbox?)
78
+ ```
79
+
80
+ - use ActiveJob
81
+
82
+ ```ruby
83
+ class AmazonSnsJob < ApplicationJob
84
+ queue_as :amazon_sns
85
+
86
+ def perform(hash)
87
+ params = hash.with_indifferent_access
88
+
89
+ bundle_identifier = params[:bundle_identifier]
90
+ arn = params[:arn]
91
+
92
+ message = Moromi::Apns::Message::Builder.build(params[:data])
93
+ raise unless message.is_a? Moromi::Apns::Message::Base
94
+
95
+ environment = Moromi::Apns.environment(bundle_identifier)
96
+
97
+ client = Moromi::Aws::Sns::Client.create(environment)
98
+ client.send_apns_message(arn: arn, message: message, sandbox: environment.sandbox?)
99
+ rescue Moromi::Apns::Environment::InvalidEnvironment => e
100
+ Rails.logger.error e.message
101
+ rescue Aws::SNS::Errors::EndpointDisabled => e
102
+ Rails.logger.info e.message
103
+ end
104
+
105
+ # @param [Moromi::Apns::Message::Base] message
106
+ # @param [String] bundle_identifier
107
+ # @param [String] arn
108
+ def self.enqueue_job(bundle_identifier, arn, message)
109
+ params = {
110
+ bundle_identifier: bundle_identifier,
111
+ arn: arn,
112
+ data: message.serialize
113
+ }
114
+ perform_later(params)
115
+ end
116
+ end
117
+ ```
118
+
21
119
  ## Development
22
120
 
23
121
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -1,9 +1,9 @@
1
1
  class Moromi::Aws::Sns::Client
2
- def send_apns_message(arn:, message:, sandbox: true)
3
- send_apns(arn: arn, params: message.to_aws_sns_params, sandbox: sandbox)
2
+ def send_apns_message(arn, message)
3
+ send_apns(arn, message.to_aws_sns_params)
4
4
  end
5
5
 
6
- def send_apns_message_to_topic(topic_arn:, message:, sandbox: true)
7
- send_apns_to_topic(topic_arn: topic_arn, params: message.to_aws_sns_params, sandbox: sandbox)
6
+ def send_apns_message_to_topic(topic_arn, message)
7
+ send_apns_to_topic(topic_arn, message.to_aws_sns_params)
8
8
  end
9
9
  end
@@ -1,7 +1,7 @@
1
1
  module Moromi
2
2
  module Apns
3
3
  module AwsSnsAdapter
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-apns-aws_sns_adapter
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: activesupport