textbelt 0.1.0 → 0.1.1
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/README.md +18 -0
- data/Rakefile +1 -0
- data/lib/textbelt.rb +3 -23
- data/lib/textbelt/textutils.rb +34 -0
- data/lib/textbelt/validators/phone_validator.rb +6 -3
- data/lib/textbelt/validators/response_validator.rb +21 -0
- data/lib/textbelt/version.rb +1 -1
- data/textbelt.gemspec +2 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38297e46bd3eae49514cf2c8f7bccae3f255dbdf
|
4
|
+
data.tar.gz: 8d1b3ab5d96f98aa37a6592cc89456c4da139671
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a1db7d63484bb4c3861708901db6fe1cbdf8a4f3ab205e591a12445a09a73dbc56b892e3df2b57dbde4635185f8b31993579febea2a03957890f980eaf53b62
|
7
|
+
data.tar.gz: b28735b08948bc4be828a64777f55931f134bb9de12530619b0def08407082af7c126ef278db51ac10c48a0f2aa4aea29aa41dd836148e0fb95413d188f7b572
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# Textbelt
|
2
2
|
|
3
3
|
[](https://travis-ci.org/djds23/textbelt-gem)
|
4
|
+
[](https://rubygems.org/gems/textbelt)
|
4
5
|
|
5
6
|
A ruby interface for sending texts free of charge through [TextBelt](http://textbelt.com/).
|
6
7
|
|
@@ -22,10 +23,27 @@ Or install it yourself as:
|
|
22
23
|
|
23
24
|
## Usage
|
24
25
|
|
26
|
+
The main API is [`TextBelt.text`](http://www.rubydoc.info/github/djds23/textbelt-gem/master/TextBelt.text). Sending messages should be as simple as passing a number & message, then watching it go!
|
27
|
+
|
25
28
|
```ruby
|
26
29
|
TextBelt.text('01234567', 'Hello, World!') #=> Your favorite cell phone number gets a text message
|
27
30
|
```
|
28
31
|
|
32
|
+
If there are any errors that happen server side, we raise then as exceptions locally, see the documentation for `text` for a look at the different errors that might be raised.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require 'textbelt'
|
36
|
+
|
37
|
+
def send_cats(number)
|
38
|
+
TextBelt.text(number, 'https://www.youtube.com/watch?v=tntOCGkgt98')
|
39
|
+
rescue TextBelt::Errors::PhoneQuotaExceededError => e
|
40
|
+
puts 'too many cats!!!!'
|
41
|
+
rescue TextBelt::Errors::BlackListedNumberError => e
|
42
|
+
puts 'can not send any more cats to that number :('
|
43
|
+
end
|
44
|
+
```
|
45
|
+
|
46
|
+
[See the full documentation here.](http://www.rubydoc.info/github/djds23/textbelt-gem/master)
|
29
47
|
## Development
|
30
48
|
|
31
49
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
data/lib/textbelt.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
module TextBelt
|
3
3
|
require 'textbelt/validators/response_validator'
|
4
4
|
require 'textbelt/validators/phone_validator'
|
5
|
+
require 'textbelt/textutils'
|
5
6
|
require 'textbelt/version'
|
6
7
|
require 'textbelt/errors'
|
7
8
|
require 'net/http'
|
@@ -28,34 +29,13 @@ module TextBelt
|
|
28
29
|
#
|
29
30
|
def text(phone_number, message, country = 'US')
|
30
31
|
PhoneValidator.validate(phone_number, country)
|
31
|
-
url = url_for(country)
|
32
|
+
url = TextUtils.url_for(country)
|
32
33
|
res = Net::HTTP.post_form(url, number: phone_number, message: message)
|
33
34
|
body = JSON.parse(res.body)
|
34
35
|
ResponseValidator.validate(phone_number, body)
|
35
36
|
body['success'.freeze]
|
36
37
|
end
|
37
38
|
|
38
|
-
# @private
|
39
|
-
def url_for(country)
|
40
|
-
url_string =
|
41
|
-
case country
|
42
|
-
when 'US'
|
43
|
-
base_url + 'text'
|
44
|
-
when 'CA'
|
45
|
-
base_url + 'canada'
|
46
|
-
else
|
47
|
-
base_url + 'intl'
|
48
|
-
end
|
49
|
-
|
50
|
-
URI(url_string)
|
51
|
-
end
|
52
|
-
|
53
|
-
# @private
|
54
|
-
def base_url
|
55
|
-
'http://textbelt.com/'
|
56
|
-
end
|
57
|
-
|
58
39
|
module_function :text
|
59
|
-
module_function :base_url
|
60
|
-
module_function :url_for
|
61
40
|
end
|
41
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# @author Dean Silfen
|
2
|
+
module TextBelt
|
3
|
+
class TextUtils
|
4
|
+
class << self
|
5
|
+
|
6
|
+
# Return the correct URL for the correct country code
|
7
|
+
#
|
8
|
+
# @param country [String] ISO 3166 Country code for destination country
|
9
|
+
#
|
10
|
+
# @return [URI] URI object holding the url to match the country code
|
11
|
+
def url_for(country)
|
12
|
+
url_string =
|
13
|
+
case country
|
14
|
+
when 'US'
|
15
|
+
base_url + 'text'
|
16
|
+
when 'CA'
|
17
|
+
base_url + 'canada'
|
18
|
+
else
|
19
|
+
base_url + 'intl'
|
20
|
+
end
|
21
|
+
|
22
|
+
URI(url_string)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# @private
|
28
|
+
def base_url
|
29
|
+
'http://textbelt.com/'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
@@ -1,9 +1,9 @@
|
|
1
|
-
# File to hold all the errors for TextBelt
|
2
|
-
#
|
3
|
-
# @author Dean Silfen
|
4
1
|
module TextBelt
|
5
2
|
require 'phonelib'
|
6
3
|
|
4
|
+
# Validator for outgoing phone numbers
|
5
|
+
#
|
6
|
+
# @author Dean Silfen
|
7
7
|
class PhoneValidator
|
8
8
|
class << self
|
9
9
|
|
@@ -12,6 +12,9 @@ module TextBelt
|
|
12
12
|
# @param phone_number [String] number to send the text to
|
13
13
|
# @param country [String] ISO 3166 Country code for destination country
|
14
14
|
#
|
15
|
+
# @raise [Errors::IntegerPhoneError] error raised if phone number is passed as an integer
|
16
|
+
# @raise [Errors::InvalidPhoneNumberError] error raised if phone number is not valid
|
17
|
+
#
|
15
18
|
# @return [Boolean] true if TextBelt successfully passed on the message,
|
16
19
|
# false if not
|
17
20
|
def validate(phone_number, country)
|
@@ -1,6 +1,25 @@
|
|
1
1
|
module TextBelt
|
2
|
+
|
3
|
+
# Validator for incoming http responses
|
4
|
+
#
|
5
|
+
# @author Dean Silfen
|
2
6
|
class ResponseValidator
|
3
7
|
class << self
|
8
|
+
|
9
|
+
# Validate the response from http service
|
10
|
+
#
|
11
|
+
# @param phone_number [String] number to send the text to
|
12
|
+
# @param body [Hash] The body of the server's http response
|
13
|
+
#
|
14
|
+
# @raise [Errors::BlackListedNumberError] http server says number is blacklisted
|
15
|
+
# @raise [Errors::GatewayFailureError] http server had a gateway error communicating with carrier
|
16
|
+
# @raise [Errors::PhoneCouldNotValidateError] http server cannot validate the phone\'s quota
|
17
|
+
# @raise [Errors::IPCouldNotValidateError] http server cannot validate the ip's quota
|
18
|
+
# @raise [Errors::PhoneQuotaExceededError] the phone's quota has been exceeded
|
19
|
+
# @raise [Errors::IPQuotaExceededError] IP's quota has been exceeded
|
20
|
+
#
|
21
|
+
# @return [Boolean] true if body is valid
|
22
|
+
#
|
4
23
|
def validate(phone_number, body)
|
5
24
|
return true if body['message'].nil? && body['success']
|
6
25
|
message = body['message']
|
@@ -27,6 +46,8 @@ module TextBelt
|
|
27
46
|
if message.include? 'Exceeded quota for this IP address.'
|
28
47
|
raise TextBelt::Errors::IPQuotaExceededError, message
|
29
48
|
end
|
49
|
+
|
50
|
+
true
|
30
51
|
end
|
31
52
|
end
|
32
53
|
end
|
data/lib/textbelt/version.rb
CHANGED
data/textbelt.gemspec
CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["dean.silfen@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{A ruby interface for sending texts with http://textbelt.com/}
|
13
|
-
spec.description = %q{A ruby interface for sending texts with http://textbelt.com
|
14
|
-
spec.homepage = "
|
13
|
+
spec.description = %q{A ruby interface for sending texts with http://textbelt.com/}
|
14
|
+
spec.homepage = "https://github.com/djds23/textbelt-gem"
|
15
15
|
|
16
16
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
17
|
# delete this section to allow pushing this gem to any host.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: textbelt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dean Silfen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: phonelib
|
@@ -94,8 +94,7 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description: A ruby interface for sending texts with http://textbelt.com
|
98
|
-
with configurable textbelt endpoint, in case you are hosting your own instance.
|
97
|
+
description: A ruby interface for sending texts with http://textbelt.com/
|
99
98
|
email:
|
100
99
|
- dean.silfen@gmail.com
|
101
100
|
executables: []
|
@@ -112,11 +111,12 @@ files:
|
|
112
111
|
- bin/setup
|
113
112
|
- lib/textbelt.rb
|
114
113
|
- lib/textbelt/errors.rb
|
114
|
+
- lib/textbelt/textutils.rb
|
115
115
|
- lib/textbelt/validators/phone_validator.rb
|
116
116
|
- lib/textbelt/validators/response_validator.rb
|
117
117
|
- lib/textbelt/version.rb
|
118
118
|
- textbelt.gemspec
|
119
|
-
homepage:
|
119
|
+
homepage: https://github.com/djds23/textbelt-gem
|
120
120
|
licenses: []
|
121
121
|
metadata: {}
|
122
122
|
post_install_message:
|