moromi-aws-sns 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e64d938c6604551cb1fe22ff8bfd8b8a03e47f2d
4
+ data.tar.gz: 0343864f2d302e89e463aef31d2ee9bde660aefc
5
+ SHA512:
6
+ metadata.gz: bdd7e9796d7987e5c85725971673a65567ddd396fc5fe104f8e2f7b9d1f048bdd9f1cc163ab1bcb5e1530596de890a458a07ba47e844e9a5199a7bf457f58abc
7
+ data.tar.gz: 11e686dff90f5eff11c2a15fc892cfa35922f35e6ab45da0942e5ac8e2a0dc9f549241b6328ceec0cd883df5e831afa4b8a7725e90eaba7094589c5bf425a11f
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ vendor
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in moromi-aws-sns.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 moromi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Moromi::Aws::Sns
2
+
3
+ AWS SNS client.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'moromi-aws-sns'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install moromi-aws-sns
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ 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.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/moromi/moromi-aws-sns.
34
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "moromi/aws/sns"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/circle.yml ADDED
@@ -0,0 +1,4 @@
1
+ machine:
2
+ ruby:
3
+ version:
4
+ 2.3.1
@@ -0,0 +1,77 @@
1
+ require 'json'
2
+
3
+ module Moromi
4
+ module Aws
5
+ module Sns
6
+ class Client
7
+ def initialize(access_key_id, secret_access_key, region, platform_application_arn)
8
+ @access_key_id = access_key_id
9
+ @secret_access_key = secret_access_key
10
+ @region = region
11
+ @platform_application_arn = platform_application_arn
12
+ end
13
+
14
+ def register(token:, force_enable: true)
15
+ params = {
16
+ platform_application_arn: @platform_application_arn,
17
+ token: token
18
+ }
19
+ params[:attributes] = {'Enabled' => 'true'} if force_enable
20
+
21
+ response = client.create_platform_endpoint(params)
22
+ response[:endpoint_arn]
23
+ end
24
+
25
+ def subscribe(topic_arn:, endpoint_arn:)
26
+ params = {
27
+ topic_arn: topic_arn,
28
+ protocol: 'application',
29
+ endpoint: endpoint_arn
30
+ }
31
+ client.subscribe(params)
32
+ end
33
+
34
+ def inactive(arn:)
35
+ params = {
36
+ endpoint_arn: arn,
37
+ attributes: {'Enabled' => 'false'}
38
+ }
39
+ client.set_endpoint_attributes(params)
40
+ end
41
+
42
+ def send_apns(arn:, params:, sandbox: true)
43
+ options = {
44
+ target_arn: arn,
45
+ message: build_apns_json_message(params, sandbox),
46
+ message_structure: 'json'
47
+ }
48
+ client.publish(options)
49
+ end
50
+
51
+ def send_apns_to_topic(topic_arn:, params:, sandbox: true)
52
+ options = {
53
+ topic_arn: topic_arn,
54
+ message: build_apns_json_message(params, sandbox),
55
+ message_structure: 'json'
56
+ }
57
+ client.publish(options)
58
+ end
59
+
60
+ private
61
+
62
+ def credentials
63
+ @credentials ||= ::Aws::Credentials.new(@access_key_id, @secret_access_key)
64
+ end
65
+
66
+ def client
67
+ @client ||= ::Aws::SNS::Client.new(region: @region, credentials: credentials)
68
+ end
69
+
70
+ def build_apns_json_message(params, sandbox)
71
+ endpoint = sandbox ? 'APNS_SANDBOX' : 'APNS'
72
+ {endpoint => params.to_json}.to_json
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,7 @@
1
+ module Moromi
2
+ module Aws
3
+ module Sns
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require "moromi/aws/sns/version"
2
+ require "moromi/aws/sns/client"
3
+
4
+ module Moromi
5
+ module Aws
6
+ module Sns
7
+ # Your code goes here...
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'moromi/aws/sns/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "moromi-aws-sns"
8
+ spec.version = Moromi::Aws::Sns::VERSION
9
+ spec.authors = ["Takahiro Ooishi"]
10
+ spec.email = ["taka0125@gmail.com"]
11
+
12
+ spec.summary = %q{AWS SNS client.}
13
+ spec.description = %q{AWS SNS client.}
14
+ spec.homepage = "https://github.com/moromi/moromi-aws-sns"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'aws-sdk', '~> 2.6'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.12"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: moromi-aws-sns
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Takahiro Ooishi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aws-sdk
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: AWS SNS client.
70
+ email:
71
+ - taka0125@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE
80
+ - README.md
81
+ - Rakefile
82
+ - bin/console
83
+ - bin/setup
84
+ - circle.yml
85
+ - lib/moromi/aws/sns.rb
86
+ - lib/moromi/aws/sns/client.rb
87
+ - lib/moromi/aws/sns/version.rb
88
+ - moromi-aws-sns.gemspec
89
+ homepage: https://github.com/moromi/moromi-aws-sns
90
+ licenses:
91
+ - MIT
92
+ metadata: {}
93
+ post_install_message:
94
+ rdoc_options: []
95
+ require_paths:
96
+ - lib
97
+ required_ruby_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ requirements: []
108
+ rubyforge_project:
109
+ rubygems_version: 2.5.1
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: AWS SNS client.
113
+ test_files: []