sms-pilot-api-v1 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -3
- data/.yardopts +8 -0
- data/CHANGELOG.md +8 -2
- data/Gemfile.lock +1 -24
- data/README.md +9 -4
- data/lib/sms_pilot/client.rb +262 -45
- data/lib/sms_pilot/errors.rb +5 -1
- data/lib/sms_pilot/version.rb +4 -1
- data/sms-pilot-api-v1.gemspec +5 -7
- metadata +7 -21
- data/sms-pilot-api-v1-0.0.2.gem +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1438f40054c6f5347c861fddb4530b2f86f7321ef4998eba159c18e70db520c
|
4
|
+
data.tar.gz: fccbb5e7fb2c505e5a8bd80cc9e1410db5673b71aa2ac6ffac0bf41a89610797
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86070669bff561d19b18242c595acc0bfc22ea6607bead4456e74391671e143ee6f1e269b1d4cd989d751d3ffda4c68fd85144d331a7e0499a64d7c114e344be
|
7
|
+
data.tar.gz: '028935012e1fd06b533aa264d8d46f0eb87ee245fc08fe5bad688c89ceb2db77610ae75caea32a3193145d0d442f4f2d32f31e1b218a6951ef78e49c6b40e558'
|
data/.gitignore
CHANGED
data/.yardopts
ADDED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
-
|
1
|
+
# Changelog
|
2
2
|
|
3
|
-
## [0.
|
3
|
+
## [0.0.4] - 2021-05-09
|
4
|
+
|
5
|
+
- Drop dependence on HTTP.rb gem
|
6
|
+
- Corrects what `#send_sms` returns (could return String errors instead of Booleans)
|
7
|
+
- Adds extensive [documentation](https://rubydoc.info/github/sergeypedan/sms-pilot-api-v1/master/SmsPilot/Client) via YARD & RubyDoc
|
8
|
+
|
9
|
+
## [0.0.3] - 2021-05-06
|
4
10
|
|
5
11
|
- Initial release
|
data/Gemfile.lock
CHANGED
@@ -1,32 +1,12 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sms-pilot-api-v1 (0.
|
5
|
-
http (>= 4.4)
|
4
|
+
sms-pilot-api-v1 (0.0.3)
|
6
5
|
|
7
6
|
GEM
|
8
7
|
remote: https://rubygems.org/
|
9
8
|
specs:
|
10
|
-
addressable (2.7.0)
|
11
|
-
public_suffix (>= 2.0.2, < 5.0)
|
12
9
|
diff-lcs (1.4.4)
|
13
|
-
domain_name (0.5.20190701)
|
14
|
-
unf (>= 0.0.5, < 1.0.0)
|
15
|
-
ffi (1.15.0)
|
16
|
-
ffi-compiler (1.0.1)
|
17
|
-
ffi (>= 1.0.0)
|
18
|
-
rake
|
19
|
-
http (4.4.1)
|
20
|
-
addressable (~> 2.3)
|
21
|
-
http-cookie (~> 1.0)
|
22
|
-
http-form_data (~> 2.2)
|
23
|
-
http-parser (~> 1.2.0)
|
24
|
-
http-cookie (1.0.3)
|
25
|
-
domain_name (~> 0.5)
|
26
|
-
http-form_data (2.3.0)
|
27
|
-
http-parser (1.2.3)
|
28
|
-
ffi-compiler (>= 1.0, < 2.0)
|
29
|
-
public_suffix (4.0.6)
|
30
10
|
rake (13.0.3)
|
31
11
|
rspec (3.10.0)
|
32
12
|
rspec-core (~> 3.10.0)
|
@@ -41,9 +21,6 @@ GEM
|
|
41
21
|
diff-lcs (>= 1.2.0, < 2.0)
|
42
22
|
rspec-support (~> 3.10.0)
|
43
23
|
rspec-support (3.10.2)
|
44
|
-
unf (0.1.4)
|
45
|
-
unf_ext
|
46
|
-
unf_ext (0.0.7.7)
|
47
24
|
|
48
25
|
PLATFORMS
|
49
26
|
x86_64-darwin-17
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# SmsPilot API v1 client
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/sms-pilot-api-v1.svg)](https://badge.fury.io/rb/sms-pilot-api-v1)
|
4
|
+
|
5
|
+
Simple wrapper around SMS pilot API v1. Version 1 because it returns more data within its standard response.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -28,6 +30,8 @@ bin/console
|
|
28
30
|
### Initialize
|
29
31
|
|
30
32
|
```ruby
|
33
|
+
require "sms_pilot"
|
34
|
+
|
31
35
|
client = SmsPilot::Client.new(api_key: "XXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZXXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZ")
|
32
36
|
#<SmsPilot::Client:0x00007fb1c602d490 @api_key="XXXXX...", @error=nil, @response_status=nil, @response_headers=nil, @response_body=nil, @response_data={}, @url=nil>
|
33
37
|
```
|
@@ -42,7 +46,7 @@ client.phone # => nil
|
|
42
46
|
client.rejected? # => false
|
43
47
|
client.response_body # => nil
|
44
48
|
client.response_data # => {}
|
45
|
-
client.response_headers # =>
|
49
|
+
client.response_headers # => {}
|
46
50
|
client.response_status # => nil
|
47
51
|
client.sender_blocked? # => false
|
48
52
|
client.sms_cost # => nil
|
@@ -140,10 +144,11 @@ SMS sent:
|
|
140
144
|
|
141
145
|
```json
|
142
146
|
{
|
147
|
+
"balance": "11908.50",
|
148
|
+
"cost": "1.68",
|
143
149
|
"send": [
|
144
150
|
{ "server_id": "10000", "phone": "79021234567", "price": "1.68", "status": "0" }
|
145
|
-
]
|
146
|
-
"balance": "11908.50", "cost": "1.68"
|
151
|
+
]
|
147
152
|
}
|
148
153
|
```
|
149
154
|
|
data/lib/sms_pilot/client.rb
CHANGED
@@ -1,14 +1,87 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "
|
3
|
+
require "json"
|
4
|
+
require "net/https"
|
4
5
|
require "uri"
|
5
6
|
|
6
7
|
module SmsPilot
|
7
8
|
|
8
|
-
|
9
|
-
|
9
|
+
# @!attribute [r] api_key
|
10
|
+
# @return [String] Your API key.
|
11
|
+
#
|
12
|
+
# @!attribute [r] error
|
13
|
+
# Error message returned from the API, combined with the error code
|
14
|
+
# @example
|
15
|
+
# client.error #=> "Пользователь временно блокирован (спорная ситуация) (error code: 122)"
|
16
|
+
# @return [nil, String]
|
17
|
+
# @see #error_code
|
18
|
+
# @see #error_description
|
19
|
+
#
|
20
|
+
# @!attribute [r] response_body
|
21
|
+
# Response format is JSON (because we request it that way in {#build_uri}.
|
22
|
+
# @example
|
23
|
+
# "{\"send\":[{\"server_id\":\"10000\",\"phone\":\"79021234567\",\"price\":\"1.68\",\"status\":\"0\"}],\"balance\":\"20006.97\",\"cost\":\"1.68\"}"
|
24
|
+
# @return [nil, String] Unmodified HTTP resonse body that API returned
|
25
|
+
# @see #response_data
|
26
|
+
# @see #response_headers
|
27
|
+
# @see #response_status
|
28
|
+
#
|
29
|
+
# @!attribute [r] response_data
|
30
|
+
# Parsed <tt>@response_body</tt>. May be an empty <tt>Hash</tt> if parsing fails.
|
31
|
+
# @example
|
32
|
+
# {
|
33
|
+
# "balance" => "20006.97",
|
34
|
+
# "cost" => "1.68",
|
35
|
+
# "send" => [
|
36
|
+
# {
|
37
|
+
# "phone" => "79021234567",
|
38
|
+
# "price" => "1.68",
|
39
|
+
# "server_id" => "10000",
|
40
|
+
# "status" => "0"
|
41
|
+
# }
|
42
|
+
# ]
|
43
|
+
# }
|
44
|
+
# @return [Hash]
|
45
|
+
# @see #response_body
|
46
|
+
# @see #response_headers
|
47
|
+
# @see #response_status
|
48
|
+
#
|
49
|
+
# @!attribute [r] response_headers
|
50
|
+
# @example
|
51
|
+
# {
|
52
|
+
# "Access-Control-Allow-Origin" => "*",
|
53
|
+
# "Connection" => "close",
|
54
|
+
# "Content-Length" => "179",
|
55
|
+
# "Content-Type" => "application/json; charset=utf-8",
|
56
|
+
# "Date" => "Thu, 06 May 2021 04:52:58 GMT",
|
57
|
+
# "Server" => "nginx"
|
58
|
+
# }
|
59
|
+
# @return [nil, String] Unmodified HTTP resonse headers that API returned.
|
60
|
+
# @see #response_body
|
61
|
+
# @see #response_data
|
62
|
+
# @see #response_status
|
63
|
+
#
|
64
|
+
# @!attribute [r] response_status
|
65
|
+
# HTTP status of the request to the API. 200 in case of success.
|
66
|
+
# @example
|
67
|
+
# client.response_status #=> 200
|
68
|
+
#
|
69
|
+
# @return [nil, Integer]
|
70
|
+
# @see #response_body
|
71
|
+
# @see #response_data
|
72
|
+
# @see #response_headers
|
73
|
+
#
|
74
|
+
# @!attribute [r] url
|
75
|
+
# @example
|
76
|
+
# client.url #=> "https://smspilot.ru/api.php?api_key=XXX&format=json&send=TEXT&to=79021234567"
|
77
|
+
# @return [String] URL generated by combining <tt>API_ENDPOINT</tt>, your API key, SMS text & phone
|
78
|
+
#
|
10
79
|
class Client
|
11
80
|
|
81
|
+
# Check current API endpoint URL at {https://smspilot.ru/apikey.php#api1}
|
82
|
+
#
|
83
|
+
API_ENDPOINT = "https://smspilot.ru/api.php".freeze
|
84
|
+
|
12
85
|
attr_reader :api_key
|
13
86
|
attr_reader :error
|
14
87
|
attr_reader :phone
|
@@ -19,128 +92,272 @@ module SmsPilot
|
|
19
92
|
attr_reader :url
|
20
93
|
|
21
94
|
|
95
|
+
# @param api_key [String]
|
96
|
+
# @return [SmsPilot::Client]
|
97
|
+
# @raise [SmsPilot::InvalidAPIkeyError] if you pass anything but a non-empty String
|
98
|
+
# @see https://smspilot.ru/my-settings.php Get your production API key here
|
99
|
+
# @see https://smspilot.ru/apikey.php Get your development API key here
|
100
|
+
# @note Current development API key is <tt>"XXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZXXXXXXXXXXXXYYYYYYYYYYYYZZZZZZZZ"</tt>
|
101
|
+
#
|
102
|
+
# @example
|
103
|
+
# client = SmsPilot::Client.new(api_key: ENV["SMS_PILOT_API_KEY"])
|
104
|
+
#
|
22
105
|
def initialize(api_key:)
|
23
|
-
fail
|
24
|
-
fail
|
106
|
+
fail SmsPilot::InvalidAPIkeyError, "API key must be a String, you pass a #{api_key.class} (#{api_key})" unless api_key.is_a? String
|
107
|
+
fail SmsPilot::InvalidAPIkeyError, "API key cannot be empty" if api_key == ""
|
25
108
|
|
26
109
|
@api_key = api_key
|
27
110
|
@error = nil
|
28
111
|
@response_status = nil
|
29
|
-
@response_headers =
|
112
|
+
@response_headers = {}
|
30
113
|
@response_body = nil
|
31
114
|
@response_data = {}
|
32
115
|
@url = nil
|
33
116
|
end
|
34
117
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
118
|
+
|
119
|
+
# @!group Main
|
120
|
+
|
121
|
+
# Send HTTP request to the API to ask them to transmit your SMS
|
122
|
+
#
|
123
|
+
# @return [Boolean] <tt>true</tt> if the SMS has been sent, <tt>false</tt> otherwise
|
124
|
+
#
|
125
|
+
# @param [String] phone The phone to send the SMS to. In free-form, will be sanitized.
|
126
|
+
# @param [String] message The text of your message.
|
127
|
+
#
|
128
|
+
# @raise [SmsPilot::InvalidPhoneError] if you pass anythig but a String with the <tt>phone</tt> argument
|
129
|
+
# @raise [SmsPilot::InvalidMessageError] if you pass anythig but a String with the <tt>message</tt> argument
|
130
|
+
# @raise [SmsPilot::InvalidMessageError] if your message is empty
|
131
|
+
# @raise [SmsPilot::InvalidPhoneError] if your phone is empty
|
132
|
+
# @raise [SmsPilot::InvalidPhoneError] if your phone has no digits
|
133
|
+
#
|
134
|
+
# @example
|
135
|
+
# client.send_sms("+7 (902) 123-45-67", "Привет, мир!") # => true
|
136
|
+
#
|
137
|
+
def send_sms(phone, message)
|
138
|
+
validate_phone! phone
|
139
|
+
validate_message! message
|
41
140
|
|
42
141
|
@phone = normalize_phone(phone)
|
43
|
-
|
142
|
+
uri = build_uri(@phone, message)
|
143
|
+
@url = uri.to_s
|
144
|
+
|
145
|
+
response = Net::HTTP.get_response(uri)
|
44
146
|
|
45
|
-
|
46
|
-
@response_status = response.
|
47
|
-
@response_headers = response.
|
48
|
-
@response_body = response.body.to_s
|
147
|
+
@response_body = response.body
|
148
|
+
@response_status = response.code.to_i
|
149
|
+
@response_headers = response.each_capitalized.to_h
|
49
150
|
|
50
|
-
unless response.
|
51
|
-
@error = "HTTP request failed with code #{response.
|
151
|
+
unless response.is_a?(Net::HTTPSuccess)
|
152
|
+
@error = "HTTP request failed with code #{response.code}"
|
52
153
|
return false
|
53
154
|
end
|
54
155
|
|
55
156
|
@response_data = JSON.parse @response_body
|
56
157
|
|
57
|
-
|
158
|
+
if rejected?
|
159
|
+
@error = "#{error_description} (error code: #{error_code})"
|
160
|
+
return false
|
161
|
+
end
|
162
|
+
|
58
163
|
return true
|
59
164
|
|
60
165
|
rescue JSON::ParserError => error
|
61
166
|
@error = "API returned invalid JSON. #{error.message}"
|
167
|
+
return false
|
62
168
|
|
63
|
-
rescue
|
64
|
-
|
65
|
-
|
66
|
-
rescue => error
|
169
|
+
rescue SocketError, EOFError, IOError, SystemCallError,
|
170
|
+
Timeout::Error, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
|
171
|
+
Net::ProtocolError, OpenSSL::SSL::SSLError => error
|
67
172
|
@error = error.message
|
173
|
+
return false
|
68
174
|
end
|
69
175
|
|
176
|
+
# @!endgroup
|
70
177
|
|
178
|
+
|
179
|
+
# @!group State accessors
|
180
|
+
|
181
|
+
# Your current balance, remaining after sending that latest SMS.
|
182
|
+
#
|
183
|
+
# @return [nil, Float] Always <tt>nil</tt> before you send SMS and if the SMS was not sent, always Float after successfull SMS transmission.
|
184
|
+
# @example
|
185
|
+
# client.balance #=> 20215.25
|
186
|
+
#
|
71
187
|
def balance
|
72
188
|
@response_data["balance"]&.to_f if sms_sent?
|
73
189
|
end
|
74
190
|
|
75
191
|
|
76
|
-
#
|
77
|
-
#
|
192
|
+
# Numerical code of the error that occured when sending the SMS. In the range from 0 to 715 (which may change).
|
193
|
+
#
|
194
|
+
# @return [nil, Integer] <tt>nil</tt> is returned before sending SMS. Otherwise <tt>Integer</tt>
|
195
|
+
# @example
|
196
|
+
# client.error_code #=> 122
|
197
|
+
# @see #error
|
198
|
+
# @see #error_description
|
199
|
+
# @see https://smspilot.ru/apikey.php#err Error codes at the API documentation website
|
78
200
|
#
|
79
201
|
def error_code
|
80
202
|
@response_data.dig("error", "code")&.to_i if rejected?
|
81
203
|
end
|
82
204
|
|
83
205
|
|
84
|
-
#
|
85
|
-
#
|
206
|
+
# Description of the error that occured when sending the SMS
|
207
|
+
#
|
208
|
+
# @return [nil, String] <tt>nil</tt> is returned before sending SMS. Otherwise <tt>String</tt>
|
209
|
+
# @example
|
210
|
+
# client.error_description #=> "Пользователь временно блокирован (спорная ситуация)"
|
211
|
+
# @see #error
|
212
|
+
# @see #error_code
|
213
|
+
# @see https://smspilot.ru/apikey.php#err Error codes at the API documentation website
|
86
214
|
#
|
87
215
|
def error_description
|
88
216
|
@response_data.dig("error", "description_ru") if rejected?
|
89
217
|
end
|
90
218
|
|
91
219
|
|
92
|
-
#
|
220
|
+
# Did the API reject your request to send that SMS
|
221
|
+
#
|
222
|
+
# @return [Boolean] <tt>false</tt> is returned before sending SMS. Otherwise the <tt>Boolean</tt> corresponds to whether your request to send an SMS was rejected.
|
223
|
+
# @example
|
224
|
+
# client.rejected? #=> false
|
225
|
+
#
|
93
226
|
def rejected?
|
94
227
|
return false if sms_sent?
|
95
228
|
@response_data["error"].is_a? Hash
|
96
229
|
end
|
97
230
|
|
98
231
|
|
99
|
-
#
|
232
|
+
# Did the API block you
|
100
233
|
#
|
101
|
-
#
|
102
|
-
#
|
103
|
-
#
|
104
|
-
#
|
234
|
+
# Error code | Description
|
235
|
+
# :---|:------------------
|
236
|
+
# 105 | из-за низкого баланса
|
237
|
+
# 106 | за спам/ошибки
|
238
|
+
# 107 | за недостоверные учетные данные / недоступна эл. почта / проблемы с телефоном
|
239
|
+
# 122 | спорная ситуация
|
105
240
|
#
|
106
|
-
#
|
241
|
+
# @return [Boolean] <tt>nil</tt> is returned before sending SMS. Otherwise the <tt>Boolean</tt> corresponds to whether the API has blocked you.
|
242
|
+
# @example
|
243
|
+
# client.sender_blocked? #=> false
|
244
|
+
# @see #error
|
245
|
+
# @see https://smspilot.ru/apikey.php#err Error codes at the API documentation website
|
107
246
|
#
|
108
247
|
def sender_blocked?
|
109
248
|
[105, 106, 107, 122].include? error_code
|
110
249
|
end
|
111
250
|
|
112
251
|
|
113
|
-
#
|
252
|
+
# The cost of the SMS that has just been sent, in RUB
|
253
|
+
#
|
254
|
+
# @return [nil, Float]
|
255
|
+
# @example
|
256
|
+
# client.sms_cost #=> 2.63
|
257
|
+
#
|
114
258
|
def sms_cost
|
115
259
|
@response_data["cost"] if sms_sent?
|
116
260
|
end
|
117
261
|
|
118
262
|
|
119
|
-
#
|
263
|
+
# Has the SMS transmission been a success.
|
264
|
+
#
|
265
|
+
# @return [Boolean] <tt>nil</tt> is returned before sending SMS. Otherwise the <tt>Boolean</tt> corresponds to the result of SMS transmission.
|
266
|
+
# @see #sms_status
|
267
|
+
# @see #rejected?
|
268
|
+
# @see #error
|
269
|
+
#
|
270
|
+
# @example
|
271
|
+
# client.sms_sent? #=> true
|
272
|
+
#
|
120
273
|
def sms_sent?
|
121
274
|
@response_data["send"] != nil
|
122
275
|
end
|
123
276
|
|
124
277
|
|
125
|
-
#
|
126
|
-
#
|
278
|
+
# SMS delivery status, as returned by the API
|
279
|
+
#
|
280
|
+
# @return [nil, Integer] <tt>nil</tt> is returned before sending SMS or if the request was rejected. Otherwise an <tt>Integer</tt> in the range of [-2..3] is returned.
|
281
|
+
# @see https://smspilot.ru/apikey.php#status List of available statuses at API documentation website
|
282
|
+
#
|
283
|
+
# Code | Name | Final? | Description
|
284
|
+
# ----:|:--------------|:-------|:-------------
|
285
|
+
# -2 | Ошибка | Да | Ошибка, неправильные параметры запроса
|
286
|
+
# -1 | Не доставлено | Да | Сообщение не доставлено (не в сети, заблокирован, не взял трубку), PING — не в сети, HLR — не обслуживается (заблокирован)
|
287
|
+
# 0 | Новое | Нет | Новое сообщение/запрос, ожидает обработки у нас на сервере
|
288
|
+
# 1 | В очереди | Нет | Сообщение или запрос ожидают отправки на сервере оператора
|
289
|
+
# 2 | Доставлено | Да | Доставлено, звонок совершен, PING — в сети, HLR — обслуживается
|
290
|
+
# 3 | Отложено | Нет | Отложенная отправка, отправка сообщения/запроса запланирована на другое время
|
291
|
+
#
|
292
|
+
# @example
|
293
|
+
# client.sms_status #=> 2
|
127
294
|
#
|
128
295
|
def sms_status
|
129
296
|
@response_data.dig("send", 0, "status")&.to_i if sms_sent?
|
130
297
|
end
|
131
298
|
|
299
|
+
# @!endgroup
|
132
300
|
|
133
|
-
private
|
134
301
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
302
|
+
# The URI we will send an HTTP request to
|
303
|
+
#
|
304
|
+
# @private
|
305
|
+
# @return [URI]
|
306
|
+
# @raise [URI::InvalidURIError] but is very unlikely because we provide the URL ourselves
|
307
|
+
#
|
308
|
+
# @example
|
309
|
+
# build_uri("79021234567", "Hello, World!")
|
310
|
+
# #=> #<URI::HTTPS https://smspilot.ru/api.php?apikey=XXX…&format=json&send=Hello%2C+World%21&to=79021234567>
|
311
|
+
#
|
312
|
+
private def build_uri(phone, text)
|
313
|
+
URI.parse(API_ENDPOINT).tap do |uri|
|
314
|
+
uri.query = URI.encode_www_form({ apikey: @api_key, format: :json, send: text, to: phone })
|
315
|
+
end
|
139
316
|
end
|
140
317
|
|
141
|
-
|
318
|
+
|
319
|
+
# Cleans up your phone from anything but digits. Also replaces 8 to 7 if it is the first digit.
|
320
|
+
#
|
321
|
+
# @private
|
322
|
+
# @return [String]
|
323
|
+
#
|
324
|
+
# @example
|
325
|
+
# normalize_phone("8 (902) 123-45-67") #=> 79021234567
|
326
|
+
# normalize_phone("+7-902-123-45-67") #=> 79021234567
|
327
|
+
#
|
328
|
+
private def normalize_phone(phone)
|
142
329
|
phone.gsub(/[^0-9]/, '').sub(/^8/, '7').gsub('+7', '8')
|
143
330
|
end
|
144
331
|
|
332
|
+
|
333
|
+
# Validates phone
|
334
|
+
|
335
|
+
# @private
|
336
|
+
# @return [nil]
|
337
|
+
#
|
338
|
+
# @raise [SmsPilot::InvalidPhoneError] if you pass anythig but a String with the <tt>phone</tt> argument
|
339
|
+
# @raise [SmsPilot::InvalidPhoneError] if your phone is empty
|
340
|
+
# @raise [SmsPilot::InvalidPhoneError] if your phone has no digits
|
341
|
+
#
|
342
|
+
private def validate_phone!(phone)
|
343
|
+
fail SmsPilot::InvalidPhoneError, "phone must be a String, you pass a #{phone.class} (#{phone})" unless phone.is_a? String
|
344
|
+
fail SmsPilot::InvalidPhoneError, "phone cannot be empty" if phone == ""
|
345
|
+
fail SmsPilot::InvalidPhoneError, "phone must contain digits" if phone.scan(/\d/).none?
|
346
|
+
end
|
347
|
+
|
348
|
+
|
349
|
+
# Validates message
|
350
|
+
|
351
|
+
# @private
|
352
|
+
# @return [nil]
|
353
|
+
#
|
354
|
+
# @raise [SmsPilot::InvalidMessageError] if you pass anythig but a String with the <tt>message</tt> argument
|
355
|
+
# @raise [SmsPilot::InvalidMessageError] if your message is empty
|
356
|
+
#
|
357
|
+
private def validate_message!(message)
|
358
|
+
fail SmsPilot::InvalidMessageError, "SMS message must be a String, you pass a #{ message.class} (#{ message})" unless message.is_a? String
|
359
|
+
fail SmsPilot::InvalidMessageError, "SMS message cannot be empty" if message == ""
|
360
|
+
end
|
361
|
+
|
145
362
|
end
|
146
363
|
end
|
data/lib/sms_pilot/errors.rb
CHANGED
data/lib/sms_pilot/version.rb
CHANGED
data/sms-pilot-api-v1.gemspec
CHANGED
@@ -3,20 +3,20 @@
|
|
3
3
|
require_relative "lib/sms_pilot/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "sms-pilot-api-v1"
|
6
7
|
spec.authors = ["Sergey Pedan"]
|
7
8
|
spec.summary = "Simple wrapper around SMS pilot API v1"
|
8
9
|
spec.description = "#{spec.summary}. Version 1 because it returns more data within its standard response"
|
9
10
|
spec.email = ["sergey.pedan@gmail.com"]
|
10
|
-
spec.homepage = "https://github.com/sergeypedan
|
11
|
+
spec.homepage = "https://github.com/sergeypedan/#{spec.name}"
|
11
12
|
spec.license = "MIT"
|
12
|
-
spec.name = "sms-pilot-api-v1"
|
13
13
|
spec.version = SmsPilot::VERSION
|
14
14
|
|
15
15
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
16
16
|
|
17
17
|
spec.metadata = {
|
18
|
-
"changelog_uri" => "#{spec.homepage}/blob/master/
|
19
|
-
"documentation_uri" => "
|
18
|
+
"changelog_uri" => "#{spec.homepage}/blob/master/CHANGELOG.md",
|
19
|
+
"documentation_uri" => "https://rubydoc.info/github/sergeypedan/#{spec.name}/master/",
|
20
20
|
"homepage_uri" => spec.homepage,
|
21
21
|
"source_code_uri" => spec.homepage
|
22
22
|
}
|
@@ -24,12 +24,10 @@ Gem::Specification.new do |spec|
|
|
24
24
|
# Specify which files should be added to the gem when it is released.
|
25
25
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
26
26
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
27
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
27
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features|pkg|doc)/}) }
|
28
28
|
end
|
29
29
|
|
30
30
|
spec.bindir = "bin"
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
|
-
spec.add_runtime_dependency "http", "~> 4"
|
34
|
-
|
35
33
|
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sms-pilot-api-v1
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Pedan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: http
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '4'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '4'
|
11
|
+
date: 2021-05-08 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description: Simple wrapper around SMS pilot API v1. Version 1 because it returns
|
28
14
|
more data within its standard response
|
29
15
|
email:
|
@@ -34,6 +20,7 @@ extra_rdoc_files: []
|
|
34
20
|
files:
|
35
21
|
- ".gitignore"
|
36
22
|
- ".rspec"
|
23
|
+
- ".yardopts"
|
37
24
|
- CHANGELOG.md
|
38
25
|
- Gemfile
|
39
26
|
- Gemfile.lock
|
@@ -45,14 +32,13 @@ files:
|
|
45
32
|
- lib/sms_pilot/client.rb
|
46
33
|
- lib/sms_pilot/errors.rb
|
47
34
|
- lib/sms_pilot/version.rb
|
48
|
-
- sms-pilot-api-v1-0.0.2.gem
|
49
35
|
- sms-pilot-api-v1.gemspec
|
50
36
|
homepage: https://github.com/sergeypedan/sms-pilot-api-v1
|
51
37
|
licenses:
|
52
38
|
- MIT
|
53
39
|
metadata:
|
54
|
-
changelog_uri: https://github.com/sergeypedan/sms-pilot-api-v1/blob/master/
|
55
|
-
documentation_uri: https://
|
40
|
+
changelog_uri: https://github.com/sergeypedan/sms-pilot-api-v1/blob/master/CHANGELOG.md
|
41
|
+
documentation_uri: https://rubydoc.info/github/sergeypedan/sms-pilot-api-v1/master/
|
56
42
|
homepage_uri: https://github.com/sergeypedan/sms-pilot-api-v1
|
57
43
|
source_code_uri: https://github.com/sergeypedan/sms-pilot-api-v1
|
58
44
|
post_install_message:
|
@@ -70,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
56
|
- !ruby/object:Gem::Version
|
71
57
|
version: '0'
|
72
58
|
requirements: []
|
73
|
-
rubygems_version: 3.2.
|
59
|
+
rubygems_version: 3.2.8
|
74
60
|
signing_key:
|
75
61
|
specification_version: 4
|
76
62
|
summary: Simple wrapper around SMS pilot API v1
|
data/sms-pilot-api-v1-0.0.2.gem
DELETED
Binary file
|