aws_sms 0.3.1 → 0.5.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 +4 -4
- data/Gemfile +0 -1
- data/README.md +66 -9
- data/aws_sms.gemspec +0 -10
- data/lib/aws_sms.rb +26 -31
- data/lib/aws_sms/config.rb +1 -9
- data/lib/aws_sms/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47cdb45a6f10acbce54889a2010dd46e969a99d4
|
4
|
+
data.tar.gz: a537521a71a187db1f3fb8d0c64d4a8fb4c5eb2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e37431515e656e256942baedd245285b257a16f21ce317cbfc60036f243a16b88addb005bac96a6a0b8c8e4116ff3407036dd79798fbb1ba5a4cebfe6e1fbe8
|
7
|
+
data.tar.gz: bb1c8f17bf8dd3652573832f76568b931db095173bbd2fbfe902df9251906e24fef714fe23d10ed0604198a581bf34486b6814b53cdf7c7d27c32d5d963f6caf
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
1
|
+
[](https://circleci.com/gh/KidA001/aws-sms)
|
2
2
|
|
3
|
-
|
3
|
+
# AwsSms
|
4
4
|
|
5
|
-
|
5
|
+
This gem acts as a simple wrapper for sending SMS Messages with Amazon SNS. It's as easy as adding your AWS Credentials and calling `AwsSms.new.send(phone_number, message)`
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -21,21 +21,78 @@ Or install it yourself as:
|
|
21
21
|
$ gem install aws_sms
|
22
22
|
|
23
23
|
## Usage
|
24
|
+
You must have an AWS Account Setup with SMS Enabled under your Simple Notification Service. You will need IAM Credentials that have `AmazonSNSFullAccess` permissions. Details below on how to load your credentials.
|
24
25
|
|
25
|
-
|
26
|
+
You must follow Amazon's requirements on sending text messages, for instance, you must provide a country code for the phone number you provide (e.g. `12225675309` where `1` is the country code) You can check [Amazon's Documentation](http://docs.aws.amazon.com/sdkforruby/api/Aws/SNS/Errors.html) for details on any errors that are raised.
|
26
27
|
|
27
|
-
|
28
|
+
### AWS Credentials
|
28
29
|
|
29
|
-
|
30
|
+
There are three ways to load your AWS Credentials:
|
30
31
|
|
31
|
-
|
32
|
+
You can initialzie `AwsSms` with your credentials as arguments:
|
33
|
+
```ruby
|
34
|
+
sms = AwsSms.new(
|
35
|
+
aws_default_region: 'us-west 2',
|
36
|
+
aws_access_key_id: 'your access key',
|
37
|
+
aws_secret_access_key: 'your secret key'
|
38
|
+
)
|
39
|
+
sms.send('15555555555', 'Some great message')
|
40
|
+
```
|
32
41
|
|
33
|
-
## Contributing
|
34
42
|
|
35
|
-
|
43
|
+
Set them through the config object. If you're using Rails you can store this in an initializer
|
44
|
+
```ruby
|
45
|
+
# config/initializers/aws_sms.rb
|
46
|
+
AwsSms::Config.set_credentials(
|
47
|
+
aws_default_region: 'us-west 2',
|
48
|
+
aws_access_key_id: ACCESS_KEY,
|
49
|
+
aws_secret_access_key: SECRET_KEY
|
50
|
+
)
|
51
|
+
...
|
52
|
+
# somewhere in your application
|
53
|
+
sms = AwsSms.new
|
54
|
+
sms.send('15555555555', 'Hello!')
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
Or you can securely store the credentials in your environment variables. This gem will search for them as follows:
|
59
|
+
```bash
|
60
|
+
# .env
|
61
|
+
AWS_ACCESS_KEY_ID=123456
|
62
|
+
AWS_SECRET_ACCESS_KEY=abc123foobarbaz
|
63
|
+
AWS_DEFAULT_REGION=us-east-2
|
64
|
+
...
|
65
|
+
```
|
66
|
+
```ruby
|
67
|
+
# somewhere in your application
|
68
|
+
|
69
|
+
sms = AwsSms.new
|
70
|
+
sms.send('15555555555', 'Foo bar baz!')
|
71
|
+
```
|
72
|
+
### AWS SMS Attributes
|
73
|
+
You can provide Amazon SMS Attributes in a similar way. Attributes default to `{ 'DefaultSMSType' => 'Transactional' }` if none are provided. See Amazon's Documentation on [SMS Attributes](http://docs.aws.amazon.com/sdkforruby/api/Aws/SNS/Client.html#set_sms_attributes-instance_method) to see what options are available to pass
|
74
|
+
```ruby
|
75
|
+
attributes = {
|
76
|
+
'DefaultSenderID' => 'SomeSenderId', 'DefaultSMSType' => 'Promotional'
|
77
|
+
}
|
78
|
+
sms = AwsSms.new(sms_attributes: attributes)
|
79
|
+
sms.send(...)
|
80
|
+
```
|
81
|
+
or
|
82
|
+
```ruby
|
83
|
+
AwsSms::Config.set_sms_attributes(
|
84
|
+
{ 'MonthlySpendLimit' => '1000', 'DefaultSMSType' => 'Promotional' }
|
85
|
+
)
|
86
|
+
```
|
87
|
+
|
88
|
+
## Contributing
|
36
89
|
|
90
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/KidA001/aws_sms. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
37
91
|
|
38
92
|
## License
|
39
93
|
|
40
94
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
95
|
|
96
|
+
## Code of Conduct
|
97
|
+
|
98
|
+
Everyone interacting in the AwsSms project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/aws_sms/blob/master/CODE_OF_CONDUCT.md).
|
data/aws_sms.gemspec
CHANGED
@@ -14,22 +14,12 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.homepage = "https://github.com/KidA001/aws-sms"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
-
# if spec.respond_to?(:metadata)
|
20
|
-
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
-
# else
|
22
|
-
# raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
-
# "public gem pushes."
|
24
|
-
# end
|
25
|
-
|
26
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
18
|
f.match(%r{^(test|spec|features)/})
|
28
19
|
end
|
29
20
|
spec.bindir = "exe"
|
30
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
22
|
spec.require_paths = ["lib"]
|
32
|
-
|
33
23
|
spec.add_development_dependency "bundler", "~> 1.14"
|
34
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
35
25
|
spec.add_development_dependency "rspec", "~> 3.0"
|
data/lib/aws_sms.rb
CHANGED
@@ -1,19 +1,16 @@
|
|
1
|
-
require
|
2
|
-
require 'aws-sdk'
|
3
|
-
require 'configatron'
|
1
|
+
require 'aws_sms/version'
|
4
2
|
require 'aws_sms/config'
|
3
|
+
require 'aws-sdk'
|
5
4
|
|
6
5
|
class AwsSms
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@default_sender_id = default_sender_id || Config.default_sender_id
|
16
|
-
@sms_attributes = sms_attributes || Config.sms_attributes
|
6
|
+
|
7
|
+
def initialize(aws_default_region: nil, aws_access_key_id: nil,
|
8
|
+
aws_secret_access_key: nil, sms_attributes: nil)
|
9
|
+
|
10
|
+
@aws_default_region = aws_default_region || Config.region
|
11
|
+
@aws_access_key_id = aws_access_key_id || Config.access_key
|
12
|
+
@aws_secret_access_key = aws_secret_access_key || Config.secret_key
|
13
|
+
@sms_attributes = sms_attributes || Config.sms_attributes
|
17
14
|
validate_args!
|
18
15
|
set_config!
|
19
16
|
end
|
@@ -22,35 +19,33 @@ class AwsSms
|
|
22
19
|
client.publish(phone_number: phone_number, message: message)
|
23
20
|
end
|
24
21
|
|
25
|
-
private
|
26
|
-
attr_reader :region, :access_key_id, :secret_key, :default_sender_id,
|
27
|
-
:default_sms_type
|
28
|
-
|
29
22
|
def client
|
30
23
|
@client ||= begin
|
31
|
-
sns =
|
32
|
-
sns.set_sms_attributes({ attributes:
|
33
|
-
"DefaultSMSType" => default_sms_type,
|
34
|
-
"DefaultSenderID" => default_sender_id
|
35
|
-
}})
|
24
|
+
sns = Aws::SNS::Client.new()
|
25
|
+
sns.set_sms_attributes({ attributes: sms_attributes })
|
36
26
|
sns
|
37
27
|
end
|
38
28
|
end
|
39
29
|
|
30
|
+
private
|
31
|
+
attr_reader :aws_default_region, :aws_access_key_id, :aws_secret_access_key,
|
32
|
+
:sms_attributes
|
33
|
+
|
40
34
|
def set_config!
|
41
|
-
|
42
|
-
|
43
|
-
credentials: Aws::Credentials.new(
|
35
|
+
Aws.config.update({
|
36
|
+
aws_default_region: aws_default_region,
|
37
|
+
credentials: Aws::Credentials.new(aws_access_key_id, aws_secret_access_key)
|
44
38
|
})
|
45
39
|
end
|
46
40
|
|
47
41
|
def validate_args!
|
48
|
-
if
|
49
|
-
message = 'ERROR:
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
42
|
+
if aws_default_region.nil? || aws_access_key_id.nil? || aws_secret_access_key.nil?
|
43
|
+
message = 'ERROR: aws_default_region, aws_access_key_id, and '\
|
44
|
+
'aws_secret_access_key arguments must be provided. You can '\
|
45
|
+
'explicitly set them when initializing AwsSms, set them in '\
|
46
|
+
'your Environment Variables as: AWS_DEFAULT_REGION, '\
|
47
|
+
'AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, or use '\
|
48
|
+
'AwsSms::Config.set_credentials'
|
54
49
|
raise ArgumentError, message
|
55
50
|
end
|
56
51
|
end
|
data/lib/aws_sms/config.rb
CHANGED
@@ -27,17 +27,9 @@ class AwsSms
|
|
27
27
|
|
28
28
|
def self.sms_attributes
|
29
29
|
unless configatron.has_key?(:sms_attributes)
|
30
|
-
configatron.sms_attributes = {
|
30
|
+
configatron.sms_attributes = { 'DefaultSMSType' => 'Transactional' }
|
31
31
|
end
|
32
32
|
configatron.sms_attributes
|
33
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
34
|
end
|
43
35
|
end
|
data/lib/aws_sms/version.rb
CHANGED
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.5.0
|
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-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.2.2
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
99
|
summary: A simple wrapper for sending SMS via AWS SNS
|