mobile_text_alerts 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +58 -0
- data/LICENSE.txt +21 -0
- data/README.md +143 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/mobile_text_alerts.rb +28 -0
- data/lib/mobile_text_alerts/actions/group.rb +54 -0
- data/lib/mobile_text_alerts/actions/member.rb +115 -0
- data/lib/mobile_text_alerts/actions/mms.rb +35 -0
- data/lib/mobile_text_alerts/actions/sms.rb +31 -0
- data/lib/mobile_text_alerts/actions/tts.rb +31 -0
- data/lib/mobile_text_alerts/client.rb +30 -0
- data/lib/mobile_text_alerts/utils.rb +45 -0
- data/lib/mobile_text_alerts/version.rb +3 -0
- data/mobile_text_alerts.gemspec +33 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2d2f42c2de5db446924cf72e5129385feee11e64d9c0e30386603b27f02ba2e6
|
4
|
+
data.tar.gz: 8246ff5baa6fc2392eff5b9c0bd550f1fc6e9072bddb56d97299ada0b2034c7a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 02b9d63cb04323acacbeb2bf68d48e831b98d199dacadff31eefc8798b164b1700cd0228e6845111bf740d2c75cb372a7acfdc7dbaa901db835fa537a8d57a79
|
7
|
+
data.tar.gz: 96ebea6bc51b9f64542735f27ce0a504ddb196fc6e5fd182900582218fd57f6d269c90f7cd46ca2c07c665482ae585826adf51b76cb0d4f177f174dbb674e979
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at jr180180@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mobile_text_alerts (0.1.0)
|
5
|
+
httparty (~> 0.18.1)
|
6
|
+
json (~> 2.3, >= 2.3.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
addressable (2.7.0)
|
12
|
+
public_suffix (>= 2.0.2, < 5.0)
|
13
|
+
byebug (11.1.3)
|
14
|
+
crack (0.4.3)
|
15
|
+
safe_yaml (~> 1.0.0)
|
16
|
+
diff-lcs (1.4.4)
|
17
|
+
hashdiff (1.0.1)
|
18
|
+
httparty (0.18.1)
|
19
|
+
mime-types (~> 3.0)
|
20
|
+
multi_xml (>= 0.5.2)
|
21
|
+
json (2.3.1)
|
22
|
+
mime-types (3.3.1)
|
23
|
+
mime-types-data (~> 3.2015)
|
24
|
+
mime-types-data (3.2020.0512)
|
25
|
+
multi_xml (0.6.0)
|
26
|
+
public_suffix (4.0.6)
|
27
|
+
rake (12.3.3)
|
28
|
+
rspec (3.9.0)
|
29
|
+
rspec-core (~> 3.9.0)
|
30
|
+
rspec-expectations (~> 3.9.0)
|
31
|
+
rspec-mocks (~> 3.9.0)
|
32
|
+
rspec-core (3.9.2)
|
33
|
+
rspec-support (~> 3.9.3)
|
34
|
+
rspec-expectations (3.9.2)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.9.0)
|
37
|
+
rspec-mocks (3.9.1)
|
38
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
39
|
+
rspec-support (~> 3.9.0)
|
40
|
+
rspec-support (3.9.3)
|
41
|
+
safe_yaml (1.0.5)
|
42
|
+
webmock (3.8.3)
|
43
|
+
addressable (>= 2.3.6)
|
44
|
+
crack (>= 0.3.2)
|
45
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
ruby
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
byebug
|
52
|
+
mobile_text_alerts!
|
53
|
+
rake (~> 12.0)
|
54
|
+
rspec (~> 3.0)
|
55
|
+
webmock
|
56
|
+
|
57
|
+
BUNDLED WITH
|
58
|
+
2.0.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 John Sanchez
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
# MobileTextAlerts
|
2
|
+
|
3
|
+
A simple Ruby wrapper for working with the Mobile-Text-Alerts.com API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'mobile_text_alerts'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install mobile_text_alerts
|
20
|
+
|
21
|
+
### Setup your project
|
22
|
+
|
23
|
+
After installing the gem in your project, you need to add the following configuration to your project:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
# config/initializers/mobile_text_alerts.rb
|
27
|
+
MobileTextAlerts.configure do |config|
|
28
|
+
config.api_key = YOUR_API_KEY
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
Of course, replace `YOUR_API_KEY` with your Mobile Text Alerts API key from your developer settings area in your account.
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
The following examples assume that you've instantiated your MTA client.
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
client = MobileTextAlerts.new
|
40
|
+
```
|
41
|
+
|
42
|
+
### SMS Messages
|
43
|
+
|
44
|
+
#### Sending SMS messages to a phone number
|
45
|
+
|
46
|
+
Pass in the phone number and the message.
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
client.send_sms_to_number('1112223333', 'foo bar')
|
50
|
+
```
|
51
|
+
|
52
|
+
#### Sending SMS messages to a MTA group
|
53
|
+
|
54
|
+
Pass in the group id from MTA and the message.
|
55
|
+
|
56
|
+
If you would like to send the message to all of your subscribers, use `'all'` as the group_id parameter.
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
client.send_sms_to_group('1', 'foo bar')
|
60
|
+
```
|
61
|
+
|
62
|
+
### MMS Messages
|
63
|
+
|
64
|
+
#### Sending MMS messages to a phone number
|
65
|
+
|
66
|
+
Pass in the phone number, the message, and the url to the image file.
|
67
|
+
|
68
|
+
```ruby
|
69
|
+
client.send_mms_to_number('1112223333', 'foo bar', 'https://foo.bar/image.png')
|
70
|
+
```
|
71
|
+
|
72
|
+
#### Sending MMS messages to a MTA group
|
73
|
+
|
74
|
+
Pass in the group id from MTA, the message, and the image url.
|
75
|
+
|
76
|
+
If you would like to send the message to all of your subscribers, use `'all'` as the group_id parameter.
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
client.send_mms_to_group('1112223333', 'foo bar', 'https://foo.bar/image.png')
|
80
|
+
```
|
81
|
+
|
82
|
+
### TTS Messages
|
83
|
+
|
84
|
+
#### Sending TTS messages to a phone number
|
85
|
+
|
86
|
+
Pass in the phone number, the message, and the url to the image file.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
client.send_tts_to_number('1112223333', 'foo bar')
|
90
|
+
```
|
91
|
+
|
92
|
+
#### Sending TTS messages to a MTA group
|
93
|
+
|
94
|
+
Pass in the group id from MTA, the message, and the image url.
|
95
|
+
|
96
|
+
If you would like to send the message to all of your subscribers, use `'all'` as the group_id parameter.
|
97
|
+
|
98
|
+
```ruby
|
99
|
+
client.send_tts_to_group('1112223333', 'foo bar')
|
100
|
+
```
|
101
|
+
|
102
|
+
### Adding contacts/members to your account
|
103
|
+
|
104
|
+
Pass in a hash of the contacts information. You must provide at the very least, the phone number or email address of the contact.
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
contact_info = {
|
108
|
+
phone_number: phone_number,
|
109
|
+
email: email,
|
110
|
+
first_name: 'Foo',
|
111
|
+
last_name: 'Bar',
|
112
|
+
groups: ['11111']
|
113
|
+
}
|
114
|
+
client.add_member(contact_info)
|
115
|
+
```
|
116
|
+
|
117
|
+
### Delete contacts/members from your account
|
118
|
+
|
119
|
+
You must pass either the phone number or email address of the contact in your account.
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
client.delete_member_via_number(phone_number)
|
123
|
+
# OR
|
124
|
+
client.delete_member_via_email(email)
|
125
|
+
```
|
126
|
+
|
127
|
+
## Development
|
128
|
+
|
129
|
+
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.
|
130
|
+
|
131
|
+
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).
|
132
|
+
|
133
|
+
## Contributing
|
134
|
+
|
135
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jr180180/mobile_text_alerts. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/jr180180/mobile_text_alerts/blob/master/CODE_OF_CONDUCT.md).
|
136
|
+
|
137
|
+
## License
|
138
|
+
|
139
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
140
|
+
|
141
|
+
## Code of Conduct
|
142
|
+
|
143
|
+
Everyone interacting in the MobileTextAlerts project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jr180180/mobile_text_alerts/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "mobile_text_alerts"
|
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(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'mobile_text_alerts/version'
|
2
|
+
require 'mobile_text_alerts/client'
|
3
|
+
|
4
|
+
module MobileTextAlerts
|
5
|
+
class Error < StandardError; end
|
6
|
+
|
7
|
+
class << self
|
8
|
+
attr_accessor :configuration
|
9
|
+
|
10
|
+
def new
|
11
|
+
@configuration ||= Configuration.new
|
12
|
+
MobileTextAlerts::Client.new(@configuration.api_key)
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure
|
16
|
+
@configuration ||= Configuration.new
|
17
|
+
yield(@configuration)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Configuration
|
22
|
+
attr_accessor :api_key
|
23
|
+
|
24
|
+
def initialize
|
25
|
+
@api_key = 'foo'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module MobileTextAlerts
|
2
|
+
module Actions
|
3
|
+
module Group
|
4
|
+
|
5
|
+
# Todo - add specs for below actions
|
6
|
+
|
7
|
+
# Add a group to your account.
|
8
|
+
# @param [String] name
|
9
|
+
# @param [String] keyword
|
10
|
+
def add_group(name, keyword)
|
11
|
+
uri = base_uri + 'add_group'
|
12
|
+
uri += "&name=#{name}"
|
13
|
+
uri += "&keyword=#{keyword}"
|
14
|
+
|
15
|
+
Utils.send_request!(uri)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Remove a group from your account.
|
19
|
+
# @param [String] id
|
20
|
+
def remove_group_via_id(id)
|
21
|
+
uri = base_uri + 'remove_group'
|
22
|
+
uri += "&id=#{id}"
|
23
|
+
|
24
|
+
Utils.send_request!(uri)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Remove a group from your account.
|
28
|
+
# @param [String] keyword
|
29
|
+
def remove_group_via_keyword(keyword)
|
30
|
+
uri = base_uri + 'remove_group'
|
31
|
+
uri += "&keyword=#{keyword}"
|
32
|
+
|
33
|
+
Utils.send_request!(uri)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Retrieve all groups on your account.
|
37
|
+
def list_groups
|
38
|
+
uri = base_uri + 'list_groups'
|
39
|
+
|
40
|
+
Utils.send_request!(uri)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Retrieve all members for a specific group belonging to the account
|
44
|
+
# @param [String] group_id
|
45
|
+
def list_group_members(group_id)
|
46
|
+
uri = base_uri + 'list_group_members'
|
47
|
+
uri += "&group_id=#{group_id}"
|
48
|
+
|
49
|
+
Utils.send_request!(uri)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
module MobileTextAlerts
|
2
|
+
module Actions
|
3
|
+
module Member
|
4
|
+
|
5
|
+
# Add a subscriber to your text alert system
|
6
|
+
# @param [Hash] args
|
7
|
+
# {
|
8
|
+
# phone_number: '1112223333',
|
9
|
+
# email: 'foo@bar.com',
|
10
|
+
# first_name: 'Foo',
|
11
|
+
# last_name: 'Bar',
|
12
|
+
# groups: ['11111']
|
13
|
+
# }
|
14
|
+
def add_member(**args)
|
15
|
+
raise(MobileTextAlerts::Error, 'Phone number or email required.') if args[:phone_number].nil? && args[:email].nil?
|
16
|
+
|
17
|
+
phone_number = Utils.parse_number(args[:phone_number]) if args[:phone_number]
|
18
|
+
|
19
|
+
uri = base_uri + 'add_member'
|
20
|
+
uri += "&number=#{phone_number}" if phone_number
|
21
|
+
uri += "&email=#{args[:email]}" if args[:email]
|
22
|
+
uri += "&first_name=#{args[:first_name]}" if args[:first_name]
|
23
|
+
uri += "&last_name=#{args[:last_name]}" if args[:last_name]
|
24
|
+
uri += "&groups=#{args[:groups].to_json}" if args[:groups]
|
25
|
+
|
26
|
+
Utils.send_request!(uri)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Remove a subscriber via phone number from your account
|
30
|
+
# @param [String] phone_number
|
31
|
+
# @return [Hash]
|
32
|
+
def delete_member_via_number(phone_number)
|
33
|
+
phone_number = Utils.parse_number(phone_number)
|
34
|
+
uri = base_uri + 'delete_member'
|
35
|
+
uri += "&number=#{phone_number}"
|
36
|
+
|
37
|
+
Utils.send_request!(uri)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Remove a subscriber via email from your account
|
41
|
+
# @param [String] email
|
42
|
+
# @return [Hash]
|
43
|
+
def delete_member_via_email(email)
|
44
|
+
uri = base_uri + 'delete_member'
|
45
|
+
uri += "&email=#{email}"
|
46
|
+
|
47
|
+
Utils.send_request!(uri)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Add a member to a group.
|
51
|
+
# @param [String] phone_number
|
52
|
+
# @param [Hash] args - requires either the group_id or group_name key/value. You do not need to pass both.
|
53
|
+
# {
|
54
|
+
# group_id: '111',
|
55
|
+
# group_name: 'Group'
|
56
|
+
# }
|
57
|
+
def add_member_to_group(phone_number, **args)
|
58
|
+
raise(MobileTextAlerts::Error, 'Group name or id is required') if args[:group_name].nil? && args[:group_id].nil?
|
59
|
+
|
60
|
+
phone_number = Utils.parse_number(phone_number)
|
61
|
+
|
62
|
+
uri = base_uri + 'add_to_group'
|
63
|
+
uri += "&number=#{phone_number}"
|
64
|
+
uri += "&group_id=#{args[:group_id]}" if args[:group_id]
|
65
|
+
uri += "&group_name=#{args[:group_name]}" if args[:group_name]
|
66
|
+
|
67
|
+
Utils.send_request!(uri)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Remove a subscriber from a group
|
71
|
+
# @param [String] group_id
|
72
|
+
# @param [String] phone_number
|
73
|
+
def remove_from_group_via_number(group_id, phone_number)
|
74
|
+
phone_number = Utils.parse_number(phone_number)
|
75
|
+
|
76
|
+
uri = base_uri + 'remove_from_group'
|
77
|
+
uri += "&group_id=#{group_id}"
|
78
|
+
uri += "&number=#{phone_number}"
|
79
|
+
|
80
|
+
Utils.send_request!(uri)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Remove a subscriber from a group
|
84
|
+
# @param [String] group_id
|
85
|
+
# @param [String] email - may pass 'all' to remove all members from the group
|
86
|
+
def remove_from_group_via_email(group_id, email)
|
87
|
+
uri = base_uri + 'remove_from_group'
|
88
|
+
uri += "&group_id=#{group_id}"
|
89
|
+
uri += "&number=#{email}"
|
90
|
+
|
91
|
+
Utils.send_request!(uri)
|
92
|
+
end
|
93
|
+
|
94
|
+
# Retrieve all members for a specific account
|
95
|
+
# @return [Hash]
|
96
|
+
def list_members
|
97
|
+
uri = base_uri + 'list_members'
|
98
|
+
|
99
|
+
Utils.send_request!(uri)
|
100
|
+
end
|
101
|
+
|
102
|
+
# Retrieve member for a specific account
|
103
|
+
# @param [String] phone_number
|
104
|
+
def get_member(phone_number)
|
105
|
+
phone_number = Utils.parse_number(phone_number)
|
106
|
+
|
107
|
+
uri = base_uri + 'get_member'
|
108
|
+
uri += "&number=#{phone_number}"
|
109
|
+
|
110
|
+
Utils.send_request!(uri)
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module MobileTextAlerts
|
2
|
+
module Actions
|
3
|
+
module Mms
|
4
|
+
|
5
|
+
# Allows you to send a MMS message to a recipient's phone number
|
6
|
+
# @param [String] phone_number
|
7
|
+
# @param [String] message
|
8
|
+
# @param [String] attachment_url to jpg, jpeg, png, gif file (optional)
|
9
|
+
# @return [Hash] response body
|
10
|
+
def send_mms_to_number(phone_number, message, attachment_url)
|
11
|
+
phone_number = Utils.parse_number(phone_number)
|
12
|
+
uri = base_uri + 'send_mms_message'
|
13
|
+
uri += "&number=#{phone_number}"
|
14
|
+
uri += "&message=#{message}"
|
15
|
+
uri += "&attachment=#{attachment_url}" if attachment_url
|
16
|
+
Utils.send_request!(uri)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Allows you to send MMS messages to a group of recipients or all subscribers.
|
20
|
+
# Pass in 'all' as the the `group_id` to send to all of your subscribers.
|
21
|
+
# @param [String] group_id
|
22
|
+
# @param [String] message
|
23
|
+
# @param [String] attachment_url to jpg, jpeg, png, gif file (optional)
|
24
|
+
# @return [Hash]
|
25
|
+
def send_mms_to_group(group_id, message, attachment_url = nil)
|
26
|
+
uri = base_uri + 'send_mms_message'
|
27
|
+
uri += "&group_id=#{group_id}"
|
28
|
+
uri += "&message=#{message}"
|
29
|
+
uri += "&attachment=#{attachment_url}" if attachment_url
|
30
|
+
Utils.send_request!(uri)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module MobileTextAlerts
|
2
|
+
module Actions
|
3
|
+
module Sms
|
4
|
+
|
5
|
+
# Allows you to send an SMS message to a recipient's phone number
|
6
|
+
# @param [String] phone_number
|
7
|
+
# @param [String] message
|
8
|
+
# @return [Hash] response body
|
9
|
+
def send_sms_to_number(phone_number, message)
|
10
|
+
phone_number = Utils.parse_number(phone_number)
|
11
|
+
uri = base_uri + 'send_message'
|
12
|
+
uri += "&number=#{phone_number}"
|
13
|
+
uri += "&message=#{message}"
|
14
|
+
Utils.send_request!(uri)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Allows you to send SMS messages to a group of recipients or all subscribers.
|
18
|
+
# Pass in 'all' as the the `group_id` to send to all of your subscribers.
|
19
|
+
# @param [String] group_id
|
20
|
+
# @param [String] message
|
21
|
+
# @return [Hash]
|
22
|
+
def send_sms_to_group(group_id, message)
|
23
|
+
uri = base_uri + 'send_message'
|
24
|
+
uri += "&group_id=#{group_id}"
|
25
|
+
uri += "&message=#{message}"
|
26
|
+
Utils.send_request!(uri)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module MobileTextAlerts
|
2
|
+
module Actions
|
3
|
+
module Tts
|
4
|
+
|
5
|
+
# Allows you to send a TTS message to a recipient's phone number
|
6
|
+
# @param [String] phone_number
|
7
|
+
# @param [String] message
|
8
|
+
# @return [Hash] response body
|
9
|
+
def send_tts_to_number(phone_number, message)
|
10
|
+
phone_number = Utils.parse_number(phone_number)
|
11
|
+
uri = base_uri + 'send_tts_message'
|
12
|
+
uri += "&number=#{phone_number}"
|
13
|
+
uri += "&message=#{message}"
|
14
|
+
Utils.send_request!(uri)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Allows you to send TTS messages to a group of recipients or all subscribers.
|
18
|
+
# Pass in 'all' as the the `group_id` to send to all of your subscribers.
|
19
|
+
# @param [String] group_id
|
20
|
+
# @param [String] message
|
21
|
+
# @return [Hash]
|
22
|
+
def send_tts_to_group(group_id, message)
|
23
|
+
uri = base_uri + 'send_tts_message'
|
24
|
+
uri += "&group_id=#{group_id}"
|
25
|
+
uri += "&message=#{message}"
|
26
|
+
Utils.send_request!(uri)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
require 'mobile_text_alerts/version'
|
5
|
+
require 'mobile_text_alerts/client'
|
6
|
+
require 'mobile_text_alerts/utils'
|
7
|
+
require 'mobile_text_alerts/actions/sms'
|
8
|
+
require 'mobile_text_alerts/actions/mms'
|
9
|
+
require 'mobile_text_alerts/actions/tts'
|
10
|
+
require 'mobile_text_alerts/actions/member'
|
11
|
+
require 'mobile_text_alerts/actions/group'
|
12
|
+
|
13
|
+
module MobileTextAlerts
|
14
|
+
class Client
|
15
|
+
include HTTParty
|
16
|
+
include MobileTextAlerts::Utils
|
17
|
+
include MobileTextAlerts::Actions::Sms
|
18
|
+
include MobileTextAlerts::Actions::Mms
|
19
|
+
include MobileTextAlerts::Actions::Tts
|
20
|
+
include MobileTextAlerts::Actions::Member
|
21
|
+
include MobileTextAlerts::Actions::Group
|
22
|
+
|
23
|
+
attr_reader :api_key, :base_uri
|
24
|
+
|
25
|
+
def initialize(api_key)
|
26
|
+
@api_key = api_key
|
27
|
+
@base_uri = "https://mobile-text-alerts.com/rest/?key=#{api_key}&request="
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module MobileTextAlerts
|
2
|
+
module Utils
|
3
|
+
|
4
|
+
class << self
|
5
|
+
|
6
|
+
# Removes any non-digits from the phone_number string
|
7
|
+
# @param [String] phone_number
|
8
|
+
# @return [String]
|
9
|
+
def parse_number(phone_number)
|
10
|
+
phone_number.delete('^0-9')
|
11
|
+
end
|
12
|
+
|
13
|
+
# Raises an exception if the response is an error response
|
14
|
+
# Otherwise, it returns the response hash
|
15
|
+
# @param [Hash] response
|
16
|
+
def raise_error_on(response)
|
17
|
+
if response.is_a?(Hash) && response['error']
|
18
|
+
raise Error.new(response['error'])
|
19
|
+
elsif response.is_a?(Hash) && response['failed_numbers']
|
20
|
+
message = response['failed_numbers']
|
21
|
+
# may be an array?
|
22
|
+
message = message.is_a?(String) ? message : message.join(', ')
|
23
|
+
raise Error.new(message)
|
24
|
+
else
|
25
|
+
response
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def parse_response(http_response)
|
30
|
+
response = http_response.parsed_response
|
31
|
+
response.kind_of?(Hash) ? response : JSON.parse(response)
|
32
|
+
end
|
33
|
+
|
34
|
+
def send_request!(uri)
|
35
|
+
response = HTTParty.get(uri)
|
36
|
+
response = Utils.parse_response(response)
|
37
|
+
Utils.raise_error_on(response)
|
38
|
+
|
39
|
+
response
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'lib/mobile_text_alerts/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'mobile_text_alerts'
|
5
|
+
spec.version = MobileTextAlerts::VERSION
|
6
|
+
spec.authors = ['John Sanchez']
|
7
|
+
spec.email = ['jr180180@gmail.com']
|
8
|
+
|
9
|
+
spec.summary = 'Ruby wrapper for the Mobile-Text-Alerts.com API'
|
10
|
+
spec.homepage = 'https://github.com/jr180180'
|
11
|
+
spec.license = 'MIT'
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
13
|
+
|
14
|
+
spec.metadata['homepage_uri'] = spec.homepage + '/mobile-text-alerts'
|
15
|
+
spec.metadata['source_code_uri'] = spec.homepage + '/mobile-text-alerts'
|
16
|
+
spec.metadata['changelog_uri'] = spec.homepage + '/mobile-text-alerts'
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
21
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
22
|
+
end
|
23
|
+
spec.bindir = 'exe'
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.add_dependency 'httparty', '~> 0.18.1'
|
28
|
+
spec.add_dependency 'json', '~> 2.3', '>= 2.3.1'
|
29
|
+
|
30
|
+
spec.add_development_dependency 'rspec'
|
31
|
+
spec.add_development_dependency 'webmock'
|
32
|
+
spec.add_development_dependency 'byebug'
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mobile_text_alerts
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Sanchez
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.18.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.18.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.3'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 2.3.1
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '2.3'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.3.1
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: webmock
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: byebug
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
description:
|
90
|
+
email:
|
91
|
+
- jr180180@gmail.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- ".gitignore"
|
97
|
+
- ".rspec"
|
98
|
+
- ".travis.yml"
|
99
|
+
- CODE_OF_CONDUCT.md
|
100
|
+
- Gemfile
|
101
|
+
- Gemfile.lock
|
102
|
+
- LICENSE.txt
|
103
|
+
- README.md
|
104
|
+
- Rakefile
|
105
|
+
- bin/console
|
106
|
+
- bin/setup
|
107
|
+
- lib/mobile_text_alerts.rb
|
108
|
+
- lib/mobile_text_alerts/actions/group.rb
|
109
|
+
- lib/mobile_text_alerts/actions/member.rb
|
110
|
+
- lib/mobile_text_alerts/actions/mms.rb
|
111
|
+
- lib/mobile_text_alerts/actions/sms.rb
|
112
|
+
- lib/mobile_text_alerts/actions/tts.rb
|
113
|
+
- lib/mobile_text_alerts/client.rb
|
114
|
+
- lib/mobile_text_alerts/utils.rb
|
115
|
+
- lib/mobile_text_alerts/version.rb
|
116
|
+
- mobile_text_alerts.gemspec
|
117
|
+
homepage: https://github.com/jr180180
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata:
|
121
|
+
homepage_uri: https://github.com/jr180180/mobile-text-alerts
|
122
|
+
source_code_uri: https://github.com/jr180180/mobile-text-alerts
|
123
|
+
changelog_uri: https://github.com/jr180180/mobile-text-alerts
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 2.3.0
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubygems_version: 3.1.2
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: Ruby wrapper for the Mobile-Text-Alerts.com API
|
143
|
+
test_files: []
|