aws_sns_kit 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +141 -0
- data/Rakefile +11 -0
- data/aws_sns_kit.gemspec +31 -0
- data/lib/aws_sns_kit/apns.rb +22 -0
- data/lib/aws_sns_kit/aws_client.rb +51 -0
- data/lib/aws_sns_kit/aws_sdk_configure.rb +0 -0
- data/lib/aws_sns_kit/configuration.rb +46 -0
- data/lib/aws_sns_kit/notification.rb +18 -0
- data/lib/aws_sns_kit/notifier.rb +8 -0
- data/lib/aws_sns_kit/version.rb +3 -0
- data/lib/aws_sns_kit.rb +27 -0
- data/lib/generators/aws_sns_kit/install/install_generator.rb +24 -0
- data/lib/generators/aws_sns_kit/templates/initializer.rb +10 -0
- data/lib/generators/aws_sns_kit/templates/migration.rb +15 -0
- data/spec/aws_sns_kit/apns_spec.rb +43 -0
- data/spec/aws_sns_kit/aws_client_spec.rb +55 -0
- data/spec/aws_sns_kit/configuration_spec.rb +73 -0
- data/spec/aws_sns_kit/notification_spec.rb +22 -0
- data/spec/aws_sns_kit/notifier_spec.rb +31 -0
- data/spec/aws_sns_kit_spec.rb +32 -0
- data/spec/spec_helper.rb +81 -0
- metadata +202 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 30ca90b654e3d13f6f0397266237bd0fd9412471
|
4
|
+
data.tar.gz: 1fbbcab590c875b55080aa1b65ac1b02a4fadf4b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 10d42a7d3f43987fe65fb48e5db5d95427d56077636c42e7fb722d6cadcb9a084114db37e69fda0514d52b6c9a3791275b4fe3832462e3ae4268d667053dc799
|
7
|
+
data.tar.gz: 2463a468daeff88390a0bf1b487c252c67ff3471fd7f20f65abd3885ad89e2ddc19f5ba845efed6b8ee08ad72328147c666d6f11778c18ff14210576c422c479
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
23
|
+
*.swp
|
24
|
+
*.swo
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 awingla
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
# AwsSnsKit
|
2
|
+
|
3
|
+
## What is this?
|
4
|
+
|
5
|
+
AwsSnsKit is a solution for integrating Amazon Web Service(AWS) Simple Notification Service(SNS) into a Rails application.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'aws_sns_kit'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install aws_sns_kit
|
20
|
+
|
21
|
+
## Configuration
|
22
|
+
|
23
|
+
Before using aws_sns_kit, you need to generate files using a generator.
|
24
|
+
Specify your model as first argument.
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
rails generate aws_sns_kit:install MODEL_NAME
|
28
|
+
```
|
29
|
+
|
30
|
+
ex.
|
31
|
+
```ruby
|
32
|
+
rails generate aws_sns_kit:install User
|
33
|
+
```
|
34
|
+
|
35
|
+
|
36
|
+
This generator command create following files.
|
37
|
+
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
config/initializers/aws_sns_kit.rb
|
41
|
+
|
42
|
+
db/migrate/20140715070941_add_aws_sns_kit_to_users.rb
|
43
|
+
```
|
44
|
+
|
45
|
+
Then, migrate.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
rake db:migrate
|
49
|
+
```
|
50
|
+
|
51
|
+
Also, you need to configure your initializer file.
|
52
|
+
|
53
|
+
Following configuration is for using aws-sdk.
|
54
|
+
More information here. https://github.com/aws/aws-sdk-ruby
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
#config/initializers/aws_sns_kit.rb
|
58
|
+
|
59
|
+
AwsSnsKit.configure do |config|
|
60
|
+
config.access_key_id = 'your access_key_id here'
|
61
|
+
config.secret_access_key = 'your secret_access_key here'
|
62
|
+
config.region = 'your region here'
|
63
|
+
|
64
|
+
#specify PlatformApplicationArn respectively.
|
65
|
+
|
66
|
+
config.end_point = {
|
67
|
+
apns: '',
|
68
|
+
apns_sandbox: '',
|
69
|
+
gcm: ''
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
## How to use?
|
76
|
+
|
77
|
+
#### APNS(Apple Push Notification Service)
|
78
|
+
|
79
|
+
You can use `push_notify` instance method with your model instance to send push notification via AWS SNS.
|
80
|
+
Before using this method, make sure that your model includes Notifier module from aws_sns_kit.
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
class User < ActiveRecord::Base
|
84
|
+
include AwsSnsKit::Notifier
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
88
|
+
|
89
|
+
Create a notification payload hash and send it by applying argument to `push_notify` method.
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
user = User.first
|
93
|
+
|
94
|
+
notification = {
|
95
|
+
alert: 'Message received via aws_sns_kit',
|
96
|
+
sound: 'bingbong.aiff',
|
97
|
+
badge: 2,
|
98
|
+
content_available: 1,
|
99
|
+
custom_data: { awesome: 'something' }
|
100
|
+
}
|
101
|
+
|
102
|
+
user.push_notify(notification)
|
103
|
+
```
|
104
|
+
|
105
|
+
##### NOTE:
|
106
|
+
Since AWS SNS can send a notification to multiple platform, aws_sns_kit expect your MODEL to return the name of the platform when `sns_platform` method is called.
|
107
|
+
Specify your platform name from one of the following to your MODEL's attributes or instance method.
|
108
|
+
|
109
|
+
`[:apns, :apns_sandbox, :gcm]`
|
110
|
+
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
# Set platform using model attribute
|
114
|
+
|
115
|
+
pry(main)> User.first.sns_platform
|
116
|
+
=> :apns
|
117
|
+
|
118
|
+
# Or specify it using instance method
|
119
|
+
|
120
|
+
class User < ActiveRecord::Base
|
121
|
+
def sns_platform
|
122
|
+
:apns
|
123
|
+
end
|
124
|
+
end
|
125
|
+
```
|
126
|
+
|
127
|
+
#### GCM(Google Cloud Messaging)
|
128
|
+
|
129
|
+
Work in progress now.
|
130
|
+
|
131
|
+
#### Topics & Subscription
|
132
|
+
|
133
|
+
Work in progress now.
|
134
|
+
|
135
|
+
## Contributing
|
136
|
+
|
137
|
+
1. Fork it ( https://github.com/awingla/aws_sns_kit/fork )
|
138
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
139
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
140
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
141
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/aws_sns_kit.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'aws_sns_kit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "aws_sns_kit"
|
8
|
+
spec.version = AwsSnsKit::VERSION
|
9
|
+
spec.authors = ["Tsubasa Ito"]
|
10
|
+
spec.email = ["stpanisush@gmail.com"]
|
11
|
+
spec.summary = %q{Easy integration for AWS SNS.}
|
12
|
+
spec.description = %q{Easy integration for AWS SNS.}
|
13
|
+
spec.homepage = "https://github.com/awingla/aws_sns_kit"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "pry"
|
25
|
+
spec.add_development_dependency "activerecord", ">= 3.0"
|
26
|
+
spec.add_development_dependency "sqlite3"
|
27
|
+
spec.add_development_dependency "rspec-activemodel-mocks"
|
28
|
+
|
29
|
+
spec.add_dependency "railties"
|
30
|
+
spec.add_dependency "aws-sdk"
|
31
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module AwsSnsKit
|
4
|
+
class Apns
|
5
|
+
attr_accessor :alert, :sound, :badge, :content_available, :custom_data
|
6
|
+
|
7
|
+
def initialize(options)
|
8
|
+
@alert = options[:alert]
|
9
|
+
@sound = options[:sound]
|
10
|
+
@badge = options[:badge]
|
11
|
+
@content_available = options[:content_available]
|
12
|
+
@custom_data = options[:custom_data]
|
13
|
+
end
|
14
|
+
|
15
|
+
def message
|
16
|
+
payload = { aps: { alert: alert, sound: sound, badge: badge } }.to_json
|
17
|
+
{ APNS: payload,
|
18
|
+
APNS_SANDBOX: payload
|
19
|
+
}.to_json
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module AwsSnsKit
|
2
|
+
class AwsClient
|
3
|
+
attr_reader :client_wrapper, :instance, :notification
|
4
|
+
|
5
|
+
def initialize(instance, notification)
|
6
|
+
@client_wrapper = AWS::SNS.new.client
|
7
|
+
@instance = instance
|
8
|
+
@notification = notification
|
9
|
+
end
|
10
|
+
|
11
|
+
def publish
|
12
|
+
client_wrapper.publish(target_arn: platform_endpoint, message: notification.message, message_structure: "json")
|
13
|
+
rescue AWS::SNS::Errors::EndpointDisabled
|
14
|
+
retry if enable
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def enable
|
20
|
+
client_wrapper.set_endpoint_attributes({
|
21
|
+
attributes: { "Enabled" => "true", "CustomUserData" => instance.custom_data},
|
22
|
+
endpoint_arn: platform_endpoint
|
23
|
+
})
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_endpoint
|
27
|
+
arn = AwsSnsKit.configuration.end_point(instance.sns_platform)
|
28
|
+
response = client_wrapper.create_platform_endpoint(
|
29
|
+
platform_application_arn: arn,
|
30
|
+
token: instance.device_token
|
31
|
+
)
|
32
|
+
instance.platform_endpoint = response[:endpoint_arn]
|
33
|
+
instance.save!
|
34
|
+
end
|
35
|
+
|
36
|
+
def platform_endpoint
|
37
|
+
if publishable?
|
38
|
+
instance.platform_endpoint
|
39
|
+
else
|
40
|
+
if create_endpoint
|
41
|
+
instance.platform_endpoint
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def publishable?
|
47
|
+
instance.platform_endpoint?
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
File without changes
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
module AwsSnsKit
|
4
|
+
class Configuration
|
5
|
+
attr_accessor :access_key_id, :secret_access_key, :region, :end_point
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@access_key_id = nil
|
9
|
+
@secret_access_key = nil
|
10
|
+
@region = 'us-east-1'
|
11
|
+
@end_point = {
|
12
|
+
apns: '',
|
13
|
+
apns_sandbox: '',
|
14
|
+
gcm: ''
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
def access_key_id=(value)
|
19
|
+
AWS.config({access_key_id: value})
|
20
|
+
end
|
21
|
+
|
22
|
+
def access_key_id
|
23
|
+
AWS.config.access_key_id
|
24
|
+
end
|
25
|
+
|
26
|
+
def secret_access_key=(value)
|
27
|
+
AWS.config({secret_access_key: value})
|
28
|
+
end
|
29
|
+
|
30
|
+
def secret_access_key
|
31
|
+
AWS.config.secret_access_key
|
32
|
+
end
|
33
|
+
|
34
|
+
def region=(value)
|
35
|
+
AWS.config({region: value})
|
36
|
+
end
|
37
|
+
|
38
|
+
def region
|
39
|
+
AWS.config.region
|
40
|
+
end
|
41
|
+
|
42
|
+
def end_point(platform)
|
43
|
+
@end_point[platform.to_sym]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module AwsSnsKit
|
2
|
+
class Notification
|
3
|
+
|
4
|
+
def initialize(options, platform_symbol)
|
5
|
+
@options = OpenStruct.new(options)
|
6
|
+
@platform_symbol = platform_symbol
|
7
|
+
end
|
8
|
+
|
9
|
+
def message
|
10
|
+
platform.message
|
11
|
+
end
|
12
|
+
|
13
|
+
def platform
|
14
|
+
@platform = Apns.new(@options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
data/lib/aws_sns_kit.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'aws_sns_kit/version'
|
2
|
+
require 'aws_sns_kit/notification'
|
3
|
+
require 'aws_sns_kit/apns'
|
4
|
+
require 'ostruct'
|
5
|
+
require 'aws_sns_kit/notifier'
|
6
|
+
require 'active_record'
|
7
|
+
require 'aws_sns_kit/aws_client'
|
8
|
+
require 'aws_sns_kit/configuration'
|
9
|
+
j
|
10
|
+
begin
|
11
|
+
require 'pry'
|
12
|
+
rescue LoadError
|
13
|
+
end
|
14
|
+
|
15
|
+
module AwsSnsKit
|
16
|
+
class << self
|
17
|
+
attr_accessor :configuration
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.configuration
|
21
|
+
@configuration ||= Configuration.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.configure
|
25
|
+
yield(configuration)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
|
3
|
+
module AwsSnsKit
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ActiveRecord::Generators::Base
|
6
|
+
source_root File.expand_path("../../templates", __FILE__)
|
7
|
+
|
8
|
+
def create_migration_file
|
9
|
+
migration_template "migration.rb", "db/migrate/add_aws_sns_kit_to_#{table_name}.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_initialize_file
|
13
|
+
template "initializer.rb", "config/initializers/aws_sns_kit.rb"
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def table_name
|
19
|
+
name.constantize.table_name
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class AddAwsSnsKitTo<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
change_table(:<%= table_name %>) do |t|
|
4
|
+
t.string :device_token, unique: true
|
5
|
+
t.string :platform_endpoint, unique: true
|
6
|
+
t.string :sns_custom_data
|
7
|
+
t.string :sns_platform
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.down
|
12
|
+
raise ActiveRecord::IrreversibleMigration
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module AwsSnsKit
|
4
|
+
describe Apns do
|
5
|
+
let(:apns_options) {
|
6
|
+
OpenStruct.new({
|
7
|
+
alert: 'Message received via aws_sns_kit',
|
8
|
+
sound: 'bingbong.aiff',
|
9
|
+
badge: 9,
|
10
|
+
content_available: 1,
|
11
|
+
custom_data: { awesome: 'something' }
|
12
|
+
})
|
13
|
+
}
|
14
|
+
|
15
|
+
let(:apns) { AwsSnsKit::Apns.new(apns_options) }
|
16
|
+
|
17
|
+
describe '#alert' do
|
18
|
+
it { expect(apns.alert).to eq(apns_options.alert) }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#sound' do
|
22
|
+
it { expect(apns.sound).to eq(apns_options.sound) }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#badge' do
|
26
|
+
it { expect(apns.badge).to eq(apns_options.badge) }
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#content_available' do
|
30
|
+
it { expect(apns.content_available).to eq(apns_options.content_available) }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '#custom_data' do
|
34
|
+
it { expect(apns.custom_data).to eq(apns_options.custom_data) }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#message' do
|
38
|
+
it 'returns actual message combined with attributes ' do
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec-activemodel-mocks'
|
3
|
+
|
4
|
+
module AwsSnsKit
|
5
|
+
describe AwsClient do
|
6
|
+
let(:instance) { mock_model(
|
7
|
+
'User',
|
8
|
+
save!: true,
|
9
|
+
platform_endpoint?: true,
|
10
|
+
platform_endpoint: '',
|
11
|
+
sns_platform: :apns,
|
12
|
+
device_token: ''
|
13
|
+
)}
|
14
|
+
|
15
|
+
before :each do
|
16
|
+
AWS.config({
|
17
|
+
access_key_id: '1',
|
18
|
+
secret_access_key: 'awesome',
|
19
|
+
region: 'us-east-1'
|
20
|
+
})
|
21
|
+
AWS.stub!
|
22
|
+
allow(instance).to receive(:platform_endpoint=)
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:notification) { notification_info = {
|
26
|
+
alert: 'Message received via aws_sns_kit',
|
27
|
+
sound: 'bingbong.aiff',
|
28
|
+
badge: 2,
|
29
|
+
content_available: 1,
|
30
|
+
custom_data: { awesome: 'something' }
|
31
|
+
}
|
32
|
+
Notification.new(notification_info, :apns)
|
33
|
+
}
|
34
|
+
|
35
|
+
let(:client) { AwsSnsKit::AwsClient.new(instance, notification) }
|
36
|
+
|
37
|
+
describe '#publish' do
|
38
|
+
it 'sends message to AWS SNS' do
|
39
|
+
expect(client.publish.data).to eq(AWS::Core::Response.new.data)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#create_endpoint' do
|
44
|
+
before :each do
|
45
|
+
response = client.client_wrapper.stub_for(:create_platform_endpoint)
|
46
|
+
response.data[:endpoint_arn] = 'endpoint_arn'
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'saves endpoint to instance' do
|
50
|
+
expect(client.instance_eval{ create_endpoint }).not_to eq(instance.platform_endpoint == 'endpoint_arn')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module AwsSnsKit
|
4
|
+
describe Configuration do
|
5
|
+
let (:access_key_id) { 'AOIJOJOFIEJOWJILJFQW' }
|
6
|
+
let (:secret_access_key) { 'LSKGmpBV/CqRUTLUFCDcQBRRFRFKHO3DRbfpQB8h' }
|
7
|
+
let (:region) { 'ap-northeast-1' }
|
8
|
+
let (:endpoint) {
|
9
|
+
{
|
10
|
+
apns: 'arn:aws:sns:ap-northeast-1:99999999999:app/APNS_SANDBOX/aws_sns_kit-iOS',
|
11
|
+
apns_sandbox: 'arn:aws:sns:ap-northeast-1:99999999999:app/APNS_SANDBOX/aws_sns_kit-iOS-Sandbox',
|
12
|
+
gcm: 'arn:aws:sns:ap-northeast-1:999999999999:app/GCM/aws_sns_kit-Android'
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
let(:configuration) { Configuration.new }
|
17
|
+
|
18
|
+
describe 'access_key_id' do
|
19
|
+
before :each do
|
20
|
+
configuration.access_key_id = access_key_id
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#access_key_id' do
|
24
|
+
it 'returns AWS.config.access_key_id' do
|
25
|
+
expect(configuration.access_key_id).to eq(AWS.config.access_key_id)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#access_key_id=' do
|
30
|
+
it 'can set value to AWS.config' do
|
31
|
+
expect(AWS.config.access_key_id).to eq(access_key_id)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'secret_access_key' do
|
37
|
+
before :each do
|
38
|
+
configuration.secret_access_key = secret_access_key
|
39
|
+
end
|
40
|
+
|
41
|
+
describe '#secret_access_key' do
|
42
|
+
it 'returns AWS.config.secret_access_key' do
|
43
|
+
expect(configuration.secret_access_key).to eq(AWS.config.secret_access_key)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#secret_access_key=' do
|
48
|
+
it 'set AWS.config with id and secret' do
|
49
|
+
expect(AWS.config.secret_access_key).to eq(secret_access_key)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe 'region' do
|
55
|
+
before :each do
|
56
|
+
configuration.region = region
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#region' do
|
60
|
+
it 'returns AWS.config.region' do
|
61
|
+
expect(configuration.region).to eq(AWS.config.region)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#region=' do
|
66
|
+
it 'returns AWS.config.region' do
|
67
|
+
expect(AWS.config.region).to eq(region)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module AwsSnsKit
|
4
|
+
describe Notification do
|
5
|
+
let(:notification) { AwsSnsKit::Notification.new(OpenStruct.new, :apns) }
|
6
|
+
let(:platform) { notification.platform }
|
7
|
+
|
8
|
+
describe '#message' do
|
9
|
+
it 'returns actual message by platform' do
|
10
|
+
expect(notification.message).to eq(platform.message)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#create_platform' do
|
15
|
+
it 'create platform by platform argument' do
|
16
|
+
expect(notification.platform).to be_an_instance_of(Apns)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module AwsSnsKit
|
4
|
+
describe Notifier do
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
ActiveRecord::Base.establish_connection(
|
8
|
+
adapter: 'sqlite3',
|
9
|
+
database: ':memory:'
|
10
|
+
)
|
11
|
+
|
12
|
+
ActiveRecord::Schema.define do
|
13
|
+
create_table :users, force: true do |t|
|
14
|
+
t.string :device_token, default: "<abcde7a2 f8f9aay5 81b9b988 46hb15ca a15ea931 900cfa9c 178eaebf c2cb6702>"
|
15
|
+
t.string :platform, default: 'ios'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#push_notify' do
|
21
|
+
before :each do
|
22
|
+
class ::User < ActiveRecord::Base
|
23
|
+
include AwsSnsKit::Notifier
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'send push_notification to instance device_token'
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AwsSnsKit do
|
4
|
+
describe '#configure' do
|
5
|
+
let (:access_key_id) { 'AOIJOJOFIEJOWJILJFQW' }
|
6
|
+
let (:secret_access_key) { 'LSKGmpBV/CqRUTLUFCDcQBRRFRFKHO3DRbfpQB8h' }
|
7
|
+
let (:region) { 'ap-northeast-1' }
|
8
|
+
let (:endpoint) {
|
9
|
+
{
|
10
|
+
apns: 'arn:aws:sns:ap-northeast-1:99999999999:app/APNS_SANDBOX/aws_sns_kit-iOS',
|
11
|
+
apns_sandbox: 'arn:aws:sns:ap-northeast-1:99999999999:app/APNS_SANDBOX/aws_sns_kit-iOS-Sandbox',
|
12
|
+
gcm: 'arn:aws:sns:ap-northeast-1:999999999999:app/GCM/aws_sns_kit-Android'
|
13
|
+
}
|
14
|
+
}
|
15
|
+
let(:notification) { AwsSnsKit::Notification.new({}, :apns) }
|
16
|
+
let(:configuration) { AwsSnsKit.configuration }
|
17
|
+
|
18
|
+
before do
|
19
|
+
AwsSnsKit.configure do |config|
|
20
|
+
config.access_key_id = access_key_id
|
21
|
+
config.secret_access_key = secret_access_key
|
22
|
+
config.region = region
|
23
|
+
config.end_point = endpoint
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'set configuration with id and secret' do
|
28
|
+
expect(configuration.access_key_id).to eq(access_key_id)
|
29
|
+
expect(configuration.secret_access_key).to eq(secret_access_key)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'aws_sns_kit'
|
2
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
3
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
4
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
5
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, make a
|
11
|
+
# separate helper file that requires this one and then use it only in the specs
|
12
|
+
# that actually need it.
|
13
|
+
#
|
14
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
15
|
+
# users commonly want.
|
16
|
+
#
|
17
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
18
|
+
RSpec.configure do |config|
|
19
|
+
config.filter_run :focus
|
20
|
+
config.run_all_when_everything_filtered = true
|
21
|
+
# The settings below are suggested to provide a good initial experience
|
22
|
+
# with RSpec, but feel free to customize to your heart's content.
|
23
|
+
=begin
|
24
|
+
# These two settings work together to allow you to limit a spec run
|
25
|
+
# to individual examples or groups you care about by tagging them with
|
26
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
27
|
+
# get run.
|
28
|
+
config.filter_run :focus
|
29
|
+
config.run_all_when_everything_filtered = true
|
30
|
+
|
31
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
32
|
+
# file, and it's useful to allow more verbose output when running an
|
33
|
+
# individual spec file.
|
34
|
+
if config.files_to_run.one?
|
35
|
+
# Use the documentation formatter for detailed output,
|
36
|
+
# unless a formatter has already been configured
|
37
|
+
# (e.g. via a command-line flag).
|
38
|
+
config.default_formatter = 'doc'
|
39
|
+
end
|
40
|
+
|
41
|
+
# Print the 10 slowest examples and example groups at the
|
42
|
+
# end of the spec run, to help surface which specs are running
|
43
|
+
# particularly slow.
|
44
|
+
config.profile_examples = 10
|
45
|
+
|
46
|
+
# Run specs in random order to surface order dependencies. If you find an
|
47
|
+
# order dependency and want to debug it, you can fix the order by providing
|
48
|
+
# the seed, which is printed after each run.
|
49
|
+
# --seed 1234
|
50
|
+
config.order = :random
|
51
|
+
|
52
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
53
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
54
|
+
# test failures related to randomization by passing the same `--seed` value
|
55
|
+
# as the one that triggered the failure.
|
56
|
+
Kernel.srand config.seed
|
57
|
+
|
58
|
+
# rspec-expectations config goes here. You can use an alternate
|
59
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
60
|
+
# assertions if you prefer.
|
61
|
+
config.expect_with :rspec do |expectations|
|
62
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
63
|
+
# For more details, see:
|
64
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
65
|
+
expectations.syntax = :expect
|
66
|
+
end
|
67
|
+
|
68
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
69
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
70
|
+
config.mock_with :rspec do |mocks|
|
71
|
+
# Enable only the newer, non-monkey-patching expect syntax.
|
72
|
+
# For more details, see:
|
73
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
74
|
+
mocks.syntax = :expect
|
75
|
+
|
76
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
77
|
+
# a real object. This is generally recommended.
|
78
|
+
mocks.verify_partial_doubles = true
|
79
|
+
end
|
80
|
+
=end
|
81
|
+
end
|
metadata
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aws_sns_kit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tsubasa Ito
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-07-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activerecord
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sqlite3
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec-activemodel-mocks
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: railties
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: aws-sdk
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: Easy integration for AWS SNS.
|
140
|
+
email:
|
141
|
+
- stpanisush@gmail.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".rspec"
|
148
|
+
- Gemfile
|
149
|
+
- LICENSE.txt
|
150
|
+
- README.md
|
151
|
+
- Rakefile
|
152
|
+
- aws_sns_kit.gemspec
|
153
|
+
- lib/aws_sns_kit.rb
|
154
|
+
- lib/aws_sns_kit/apns.rb
|
155
|
+
- lib/aws_sns_kit/aws_client.rb
|
156
|
+
- lib/aws_sns_kit/aws_sdk_configure.rb
|
157
|
+
- lib/aws_sns_kit/configuration.rb
|
158
|
+
- lib/aws_sns_kit/notification.rb
|
159
|
+
- lib/aws_sns_kit/notifier.rb
|
160
|
+
- lib/aws_sns_kit/version.rb
|
161
|
+
- lib/generators/aws_sns_kit/install/install_generator.rb
|
162
|
+
- lib/generators/aws_sns_kit/templates/initializer.rb
|
163
|
+
- lib/generators/aws_sns_kit/templates/migration.rb
|
164
|
+
- spec/aws_sns_kit/apns_spec.rb
|
165
|
+
- spec/aws_sns_kit/aws_client_spec.rb
|
166
|
+
- spec/aws_sns_kit/configuration_spec.rb
|
167
|
+
- spec/aws_sns_kit/notification_spec.rb
|
168
|
+
- spec/aws_sns_kit/notifier_spec.rb
|
169
|
+
- spec/aws_sns_kit_spec.rb
|
170
|
+
- spec/spec_helper.rb
|
171
|
+
homepage: https://github.com/awingla/aws_sns_kit
|
172
|
+
licenses:
|
173
|
+
- MIT
|
174
|
+
metadata: {}
|
175
|
+
post_install_message:
|
176
|
+
rdoc_options: []
|
177
|
+
require_paths:
|
178
|
+
- lib
|
179
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
180
|
+
requirements:
|
181
|
+
- - ">="
|
182
|
+
- !ruby/object:Gem::Version
|
183
|
+
version: '0'
|
184
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - ">="
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
requirements: []
|
190
|
+
rubyforge_project:
|
191
|
+
rubygems_version: 2.2.2
|
192
|
+
signing_key:
|
193
|
+
specification_version: 4
|
194
|
+
summary: Easy integration for AWS SNS.
|
195
|
+
test_files:
|
196
|
+
- spec/aws_sns_kit/apns_spec.rb
|
197
|
+
- spec/aws_sns_kit/aws_client_spec.rb
|
198
|
+
- spec/aws_sns_kit/configuration_spec.rb
|
199
|
+
- spec/aws_sns_kit/notification_spec.rb
|
200
|
+
- spec/aws_sns_kit/notifier_spec.rb
|
201
|
+
- spec/aws_sns_kit_spec.rb
|
202
|
+
- spec/spec_helper.rb
|