aws_sms 0.2.2 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/lib/aws_sms/config.rb +43 -0
- data/lib/aws_sms/version.rb +1 -1
- data/lib/aws_sms.rb +28 -29
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9919b56610030d592728da2a1a35be5a5c20c6ea
|
4
|
+
data.tar.gz: 5a4481404dea2e827ebb2265872d23c48f6aa981
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c7f368396fd6d998220db0257d85ae8abbbdc2716e2d9e5ea03562ca35faaf725d256c59e0ceef7ceb21b5afc8fb8144ac0d3f0772117edd9975fb0a66f464c
|
7
|
+
data.tar.gz: 68f38bd47279b5fe34ed951fe8d61a10f394f47ac83df6ef58f82852239ea062f5c3557a0c92fc707e8e2a6bc4a3d541ef62362a068b60448fd6f5c84d85fad5
|
data/Gemfile
CHANGED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'configatron'
|
2
|
+
|
3
|
+
class AwsSms
|
4
|
+
module Config
|
5
|
+
|
6
|
+
def self.set_credentials(aws_default_region:, aws_access_key_id: , aws_secret_access_key:)
|
7
|
+
configatron.aws_default_region = aws_default_region
|
8
|
+
configatron.aws_access_key_id = aws_access_key_id
|
9
|
+
configatron.aws_secret_access_key = aws_secret_access_key
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.set_sms_attributes(attributes)
|
13
|
+
configatron.sms_attributes = attributes
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.access_key
|
17
|
+
ENV['AWS_ACCESS_KEY_ID'] || configatron.aws_access_key_id
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.region
|
21
|
+
ENV['AWS_DEFAULT_REGION'] || configatron.aws_default_region
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.secret_key
|
25
|
+
ENV['AWS_SECRET_ACCESS_KEY'] || configatron.aws_secret_access_key
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.sms_attributes
|
29
|
+
unless configatron.has_key?(:sms_attributes)
|
30
|
+
configatron.sms_attributes = { "DefaultSMSType" => 'Transactional' }
|
31
|
+
end
|
32
|
+
configatron.sms_attributes
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.sms_type
|
36
|
+
configatron.default_sms_type
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.default_sender_id
|
40
|
+
configatron.default_sender_id
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/aws_sms/version.rb
CHANGED
data/lib/aws_sms.rb
CHANGED
@@ -1,27 +1,25 @@
|
|
1
1
|
require "aws_sms/version"
|
2
2
|
require 'aws-sdk'
|
3
|
+
require 'configatron'
|
4
|
+
require 'aws_sms/config'
|
3
5
|
|
4
6
|
class AwsSms
|
5
7
|
class SNSClientError < StandardError; end
|
6
8
|
class InvalidNumber < StandardError; end
|
7
9
|
|
8
|
-
def initialize(region: nil, access_key_id: nil, secret_key: nil,
|
9
|
-
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
10
|
+
def initialize(region: nil, access_key_id: nil, secret_key: nil, sms_attributes: nil)
|
11
|
+
@region = region || Config.region
|
12
|
+
@access_key_id = access_key_id || Config.access_key
|
13
|
+
@secret_key = secret_key || Config.secret_key
|
14
|
+
@default_sms_type = default_sms_type || Config.sms_type
|
15
|
+
@default_sender_id = default_sender_id || Config.default_sender_id
|
16
|
+
@sms_attributes = sms_attributes || Config.sms_attributes
|
17
|
+
validate_args!
|
18
|
+
set_config!
|
15
19
|
end
|
16
20
|
|
17
21
|
def send(phone_number, message)
|
18
|
-
validate_args!
|
19
|
-
|
20
22
|
client.publish(phone_number: phone_number, message: message)
|
21
|
-
rescue ::Aws::SNS::Errors::InvalidParameter => e
|
22
|
-
raise InvalidNumber, 'Invalid phone number'
|
23
|
-
rescue ::Aws::SNS::Errors::ServiceError => e
|
24
|
-
raise SNSClientError, e.message
|
25
23
|
end
|
26
24
|
|
27
25
|
private
|
@@ -29,29 +27,30 @@ class AwsSms
|
|
29
27
|
:default_sms_type
|
30
28
|
|
31
29
|
def client
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
access_key_id, secret_key
|
36
|
-
)
|
37
|
-
})
|
38
|
-
|
39
|
-
sns = ::Aws::SNS::Client.new()
|
40
|
-
sns.set_sms_attributes({
|
41
|
-
attributes: {
|
30
|
+
@client ||= begin
|
31
|
+
sns = ::Aws::SNS::Client.new()
|
32
|
+
sns.set_sms_attributes({ attributes: {
|
42
33
|
"DefaultSMSType" => default_sms_type,
|
43
34
|
"DefaultSenderID" => default_sender_id
|
44
|
-
}
|
35
|
+
}})
|
36
|
+
sns
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def set_config!
|
41
|
+
::Aws.config.update({
|
42
|
+
region: region,
|
43
|
+
credentials: Aws::Credentials.new(access_key_id, secret_key)
|
45
44
|
})
|
46
|
-
sns
|
47
45
|
end
|
48
46
|
|
49
47
|
def validate_args!
|
50
48
|
if region.nil? || access_key_id.nil? || secret_key.nil?
|
51
|
-
message = 'region, access_key_id, and secret_key arguments must
|
52
|
-
'provided. You can explicitly set them when initializing '\
|
53
|
-
'
|
54
|
-
'AWS_DEFAULT_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY'
|
49
|
+
message = 'ERROR: region, access_key_id, and secret_key arguments must '\
|
50
|
+
'be provided. You can explicitly set them when initializing '\
|
51
|
+
'AwsSms, set them in your Environment Variables as: '\
|
52
|
+
'AWS_DEFAULT_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, '\
|
53
|
+
'or use AwsSms::Config.set_credentials'
|
55
54
|
raise ArgumentError, message
|
56
55
|
end
|
57
56
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aws_sms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Vogelgesang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-06-
|
11
|
+
date: 2017-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -71,6 +71,7 @@ files:
|
|
71
71
|
- bin/console
|
72
72
|
- bin/setup
|
73
73
|
- lib/aws_sms.rb
|
74
|
+
- lib/aws_sms/config.rb
|
74
75
|
- lib/aws_sms/version.rb
|
75
76
|
homepage: https://github.com/KidA001/aws-sms
|
76
77
|
licenses:
|