sns_helper 0.0.2
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 +7 -0
- data/jobs/aws_sms_job.rb +6 -0
- data/lib/sns_helper.rb +62 -0
- metadata +73 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ad752d00983f72b2ccb61166515bfd121217cb41
|
4
|
+
data.tar.gz: c414767ad6c6364698c46a3de4fedab29feca25e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d846b69951d1730979f145d7f0333c570d9587b2c5f7f678b500a02eb919dfc2903f85a63846375686573acc2369ad26a0831369ba6e719a5ed2a03a74acca90
|
7
|
+
data.tar.gz: fc40cff066a53338368137e270fad7ce9c5ff5e199252eafb3bf008d0ec5d4a93178df2b6677d0e9e9d2f2f24eeb390db58029a451f5803362d887b50dafa680
|
data/jobs/aws_sms_job.rb
ADDED
data/lib/sns_helper.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'aws-sdk'
|
2
|
+
|
3
|
+
# This is the main file of sns_helper gem
|
4
|
+
class SnsHelper
|
5
|
+
attr_reader :sns
|
6
|
+
|
7
|
+
# say hi to the world
|
8
|
+
#
|
9
|
+
# Example:
|
10
|
+
# >> SnsHelper.hi
|
11
|
+
# => This is hello world from sns_helper!
|
12
|
+
#
|
13
|
+
def self.hi
|
14
|
+
'This is hello world from sns_helper!'
|
15
|
+
end
|
16
|
+
|
17
|
+
# By initialize a SnsHelper, you can then simply use the send_message method to deliver your send_message
|
18
|
+
# Remember to set up the aws creditical for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY
|
19
|
+
#
|
20
|
+
# Example:
|
21
|
+
# >> service = SnsHelper.new
|
22
|
+
# => #<SnsHelper:0x00007fe6ee435e40 @sns=#<Aws::SNS::Client>>
|
23
|
+
#
|
24
|
+
def initialize(region: 'ap-northeast-1')
|
25
|
+
@sns = Aws::SNS::Client.new(
|
26
|
+
region: region,
|
27
|
+
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
|
28
|
+
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
def sms_attr
|
33
|
+
sns.get_sms_attributes
|
34
|
+
end
|
35
|
+
|
36
|
+
def sms_type=(type: 'Promotional')
|
37
|
+
return false unless %w[Promotional Transactional].include?(type)
|
38
|
+
sns.set_sms_attributes(
|
39
|
+
attributes: {
|
40
|
+
DefaultSMSType: type
|
41
|
+
}
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
def send_async_message(phone_number, message)
|
46
|
+
AwsSmsJob.perform_later(phone_number, message)
|
47
|
+
end
|
48
|
+
|
49
|
+
def send_message(phone_number, message)
|
50
|
+
if valid_phone_number(phone_number)
|
51
|
+
sns.publish(phone_number: phone_number, message: message)
|
52
|
+
else
|
53
|
+
false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# The current pattern is only for Taiwan
|
58
|
+
def valid_phone_number(phone_number)
|
59
|
+
return false unless /^\+8869\d{8}/ =~ phone_number
|
60
|
+
true
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sns_helper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jason Shen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: aws-sdk-rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aws-sdk-sns
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
description: Just a simple gem to get the project working with AWS SNS service
|
42
|
+
email: sikajs@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- jobs/aws_sms_job.rb
|
48
|
+
- lib/sns_helper.rb
|
49
|
+
homepage: https://sikaplayground.blogspot.com/
|
50
|
+
licenses:
|
51
|
+
- MIT
|
52
|
+
metadata: {}
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 2.6.14
|
70
|
+
signing_key:
|
71
|
+
specification_version: 4
|
72
|
+
summary: A simple gem to get the project working with AWS SNS service
|
73
|
+
test_files: []
|