ovh-http2sms 0.1.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 +7 -0
- data/.dockerignore +9 -0
- data/.env.example +12 -0
- data/CHANGELOG.md +50 -0
- data/Dockerfile +25 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +21 -0
- data/README.md +503 -0
- data/Rakefile +12 -0
- data/docker-compose.yml +29 -0
- data/lib/generators/ovh/http2sms/install_generator.rb +42 -0
- data/lib/generators/ovh/http2sms/templates/initializer.rb +52 -0
- data/lib/ovh/http2sms/client.rb +253 -0
- data/lib/ovh/http2sms/configuration.rb +141 -0
- data/lib/ovh/http2sms/errors.rb +148 -0
- data/lib/ovh/http2sms/gsm_encoding.rb +169 -0
- data/lib/ovh/http2sms/phone_number.rb +134 -0
- data/lib/ovh/http2sms/railtie.rb +23 -0
- data/lib/ovh/http2sms/response.rb +259 -0
- data/lib/ovh/http2sms/validators.rb +190 -0
- data/lib/ovh/http2sms/version.rb +7 -0
- data/lib/ovh/http2sms.rb +151 -0
- data/ovh-http2sms.gemspec +47 -0
- data/sig/ovh/http2sms.rbs +6 -0
- metadata +205 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7cab24237194aeab0d46e5b7d5bde5679ddca4018ec7f61c47e4bb01e58c7971
|
|
4
|
+
data.tar.gz: 15ee708e4911827648e2f3f221029b510c2eedf694fd7e4bac34dcd9add7b8ba
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 232378bd0d9f850989b6c608b1c90b0c1399870f920fb2faf5aaad288b92025b1e099d4bf0a73c903f7245c647c465be6b933dbcf12e7b07a054356db01cce75
|
|
7
|
+
data.tar.gz: ad6bc71528908dd2ebf9985efa2d6f7d3d720811f1d52624ab9f50311b23df43f2296d949e1110115be1f7e52cf4b0dc972a8ceb81adeca6598d150a2f786f17
|
data/.dockerignore
ADDED
data/.env.example
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# OVH SMS API credentials
|
|
2
|
+
# Copy this file to .env and fill in your values
|
|
3
|
+
# Get your credentials from OVH Manager: https://www.ovh.com/manager/
|
|
4
|
+
|
|
5
|
+
OVH_SMS_ACCOUNT=sms-xx11111-1
|
|
6
|
+
OVH_SMS_LOGIN=your_login
|
|
7
|
+
OVH_SMS_PASSWORD=your_password
|
|
8
|
+
|
|
9
|
+
# Optional settings
|
|
10
|
+
# OVH_SMS_DEFAULT_SENDER=MyApp
|
|
11
|
+
# OVH_SMS_DEFAULT_COUNTRY_CODE=33
|
|
12
|
+
# OVH_SMS_TIMEOUT=15
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2025-01-28
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Initial release
|
|
15
|
+
- Core SMS sending functionality via OVH http2sms API
|
|
16
|
+
- Support for single and multiple recipients
|
|
17
|
+
- Scheduled (deferred) message sending with Time objects or OVH format
|
|
18
|
+
- GSM 03.38 encoding detection using `gsm_encoder` gem
|
|
19
|
+
- Unicode encoding support with automatic detection
|
|
20
|
+
- Phone number formatting (local to international format)
|
|
21
|
+
- Configurable country codes for international support
|
|
22
|
+
- Commercial SMS handling with STOP clause character limits
|
|
23
|
+
- Reply-enabled SMS (senderForResponse)
|
|
24
|
+
- Response parsing for all formats: JSON, XML, HTML, text/plain
|
|
25
|
+
- Configuration via block, environment variables, or options hash
|
|
26
|
+
- Rails integration with generator (`rails g ovh:http2sms:install`)
|
|
27
|
+
- Rails credentials support
|
|
28
|
+
- Comprehensive error handling with custom exception classes:
|
|
29
|
+
- `ConfigurationError`
|
|
30
|
+
- `AuthenticationError`
|
|
31
|
+
- `MissingParameterError`
|
|
32
|
+
- `InvalidParameterError`
|
|
33
|
+
- `NetworkError`
|
|
34
|
+
- `MessageLengthError`
|
|
35
|
+
- `PhoneNumberError`
|
|
36
|
+
- `ValidationError`
|
|
37
|
+
- Thread-safe client implementation
|
|
38
|
+
- Full YARD documentation
|
|
39
|
+
- RSpec test suite with WebMock
|
|
40
|
+
- Rubocop configuration
|
|
41
|
+
- GitHub Actions CI workflow
|
|
42
|
+
|
|
43
|
+
### Dependencies
|
|
44
|
+
|
|
45
|
+
- Ruby >= 3.0.0
|
|
46
|
+
- Faraday >= 1.0, < 3.0
|
|
47
|
+
- gsm_encoder ~> 0.1.7
|
|
48
|
+
|
|
49
|
+
[Unreleased]: https://github.com/fkiene/ovh-http2sms/compare/v0.1.0...HEAD
|
|
50
|
+
[0.1.0]: https://github.com/fkiene/ovh-http2sms/releases/tag/v0.1.0
|
data/Dockerfile
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
FROM ruby:3.2-slim
|
|
2
|
+
|
|
3
|
+
RUN apt-get update -qq && apt-get install -y \
|
|
4
|
+
build-essential \
|
|
5
|
+
git \
|
|
6
|
+
libyaml-dev \
|
|
7
|
+
&& rm -rf /var/lib/apt/lists/*
|
|
8
|
+
|
|
9
|
+
WORKDIR /gem
|
|
10
|
+
|
|
11
|
+
# Install bundler
|
|
12
|
+
RUN gem install bundler
|
|
13
|
+
|
|
14
|
+
# Copy gemspec and Gemfile first for better caching
|
|
15
|
+
COPY Gemfile ovh-http2sms.gemspec ./
|
|
16
|
+
COPY lib/ovh/http2sms/version.rb lib/ovh/http2sms/
|
|
17
|
+
|
|
18
|
+
# Install dependencies
|
|
19
|
+
RUN bundle install
|
|
20
|
+
|
|
21
|
+
# Copy the rest of the code
|
|
22
|
+
COPY . .
|
|
23
|
+
|
|
24
|
+
# Default command: interactive console
|
|
25
|
+
CMD ["bin/console"]
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 François Kiene
|
|
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,503 @@
|
|
|
1
|
+
# OVH HTTP2SMS
|
|
2
|
+
|
|
3
|
+
[](https://rubygems.org/gems/ovh-http2sms)
|
|
4
|
+
[](https://github.com/fkiene/ovh-http2sms/actions)
|
|
5
|
+
[](https://codecov.io/gh/fkiene/ovh-http2sms)
|
|
6
|
+
|
|
7
|
+
A production-ready Ruby gem to send SMS via OVH's http2sms API. Supports single and bulk sending, scheduled messages, GSM/Unicode encoding detection, phone number formatting, and seamless Rails integration.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Simple API for sending SMS via OVH's http2sms endpoint
|
|
12
|
+
- Support for single and multiple recipients
|
|
13
|
+
- Scheduled (deferred) message sending
|
|
14
|
+
- GSM 03.38 and Unicode encoding detection
|
|
15
|
+
- Automatic phone number formatting (local to international)
|
|
16
|
+
- Configurable country codes for international support
|
|
17
|
+
- Commercial SMS with STOP clause handling
|
|
18
|
+
- Reply-enabled SMS (senderForResponse)
|
|
19
|
+
- All response formats (JSON, XML, HTML, text/plain)
|
|
20
|
+
- Rails generator for easy setup
|
|
21
|
+
- Rails credentials support
|
|
22
|
+
- Thread-safe client
|
|
23
|
+
- Comprehensive error handling
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
Add this line to your application's Gemfile:
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
gem "ovh-http2sms"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
And then execute:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
bundle install
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Or install it yourself:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
gem install ovh-http2sms
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
# Configure credentials
|
|
49
|
+
Ovh::Http2sms.configure do |config|
|
|
50
|
+
config.account = "sms-xx11111-1"
|
|
51
|
+
config.login = "your_login"
|
|
52
|
+
config.password = "your_password"
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Send a simple SMS
|
|
56
|
+
response = Ovh::Http2sms.deliver(to: "33601020304", message: "Hello!")
|
|
57
|
+
|
|
58
|
+
if response.success?
|
|
59
|
+
puts "SMS sent! ID: #{response.sms_ids.first}"
|
|
60
|
+
puts "Credits remaining: #{response.credits_remaining}"
|
|
61
|
+
else
|
|
62
|
+
puts "Error: #{response.error_message}"
|
|
63
|
+
end
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Configuration
|
|
67
|
+
|
|
68
|
+
### Block Configuration
|
|
69
|
+
|
|
70
|
+
```ruby
|
|
71
|
+
Ovh::Http2sms.configure do |config|
|
|
72
|
+
# Required
|
|
73
|
+
config.account = "sms-xx11111-1"
|
|
74
|
+
config.login = "your_login"
|
|
75
|
+
config.password = "your_password"
|
|
76
|
+
|
|
77
|
+
# Optional
|
|
78
|
+
config.default_sender = "MyApp" # Default sender name
|
|
79
|
+
config.default_country_code = "33" # For phone number formatting (default: "33" France)
|
|
80
|
+
config.default_content_type = "application/json" # Response format
|
|
81
|
+
config.timeout = 15 # HTTP timeout in seconds
|
|
82
|
+
config.raise_on_length_error = true # Raise error for very long messages
|
|
83
|
+
config.logger = Logger.new($stdout) # For debugging
|
|
84
|
+
end
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Environment Variables
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
export OVH_SMS_ACCOUNT="sms-xx11111-1"
|
|
91
|
+
export OVH_SMS_LOGIN="your_login"
|
|
92
|
+
export OVH_SMS_PASSWORD="your_password"
|
|
93
|
+
export OVH_SMS_DEFAULT_SENDER="MyApp"
|
|
94
|
+
export OVH_SMS_DEFAULT_COUNTRY_CODE="33"
|
|
95
|
+
export OVH_SMS_TIMEOUT="30"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Rails Credentials
|
|
99
|
+
|
|
100
|
+
For Rails applications, you can use encrypted credentials:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
rails credentials:edit
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Add:
|
|
107
|
+
|
|
108
|
+
```yaml
|
|
109
|
+
ovh_sms:
|
|
110
|
+
account: sms-xx11111-1
|
|
111
|
+
login: your_login
|
|
112
|
+
password: your_password
|
|
113
|
+
default_sender: MyApp
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Then in your initializer:
|
|
117
|
+
|
|
118
|
+
```ruby
|
|
119
|
+
Ovh::Http2sms.configure do |config|
|
|
120
|
+
credentials = Rails.application.credentials.ovh_sms
|
|
121
|
+
config.account = credentials[:account]
|
|
122
|
+
config.login = credentials[:login]
|
|
123
|
+
config.password = credentials[:password]
|
|
124
|
+
config.default_sender = credentials[:default_sender]
|
|
125
|
+
end
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Usage Examples
|
|
129
|
+
|
|
130
|
+
### Basic Send
|
|
131
|
+
|
|
132
|
+
```ruby
|
|
133
|
+
response = Ovh::Http2sms.deliver(
|
|
134
|
+
to: "33601020304",
|
|
135
|
+
message: "Your verification code is 123456"
|
|
136
|
+
)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Send to Multiple Recipients
|
|
140
|
+
|
|
141
|
+
```ruby
|
|
142
|
+
# As array
|
|
143
|
+
response = Ovh::Http2sms.deliver(
|
|
144
|
+
to: ["33601020304", "33602030405", "33603040506"],
|
|
145
|
+
message: "Team meeting at 3pm"
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
# As comma-separated string
|
|
149
|
+
response = Ovh::Http2sms.deliver(
|
|
150
|
+
to: "33601020304,33602030405",
|
|
151
|
+
message: "Team meeting at 3pm"
|
|
152
|
+
)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Scheduled (Deferred) Sending
|
|
156
|
+
|
|
157
|
+
```ruby
|
|
158
|
+
# Using Ruby Time object
|
|
159
|
+
response = Ovh::Http2sms.deliver(
|
|
160
|
+
to: "33601020304",
|
|
161
|
+
message: "Reminder: Meeting tomorrow",
|
|
162
|
+
deferred: Time.now + 3600 # 1 hour from now
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
# Using OVH format (hhmmddMMYYYY)
|
|
166
|
+
response = Ovh::Http2sms.deliver(
|
|
167
|
+
to: "33601020304",
|
|
168
|
+
message: "Happy New Year!",
|
|
169
|
+
deferred: "000001012025" # Midnight on Jan 1, 2025
|
|
170
|
+
)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Custom Sender
|
|
174
|
+
|
|
175
|
+
```ruby
|
|
176
|
+
response = Ovh::Http2sms.deliver(
|
|
177
|
+
to: "33601020304",
|
|
178
|
+
message: "Your order has shipped!",
|
|
179
|
+
sender: "MyShop" # Must be registered with OVH
|
|
180
|
+
)
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Enable Replies (Short Code)
|
|
184
|
+
|
|
185
|
+
```ruby
|
|
186
|
+
response = Ovh::Http2sms.deliver(
|
|
187
|
+
to: "33601020304",
|
|
188
|
+
message: "Reply YES to confirm",
|
|
189
|
+
sender_for_response: true # Enables reply capability
|
|
190
|
+
)
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Non-Commercial SMS (No STOP Clause)
|
|
194
|
+
|
|
195
|
+
```ruby
|
|
196
|
+
response = Ovh::Http2sms.deliver(
|
|
197
|
+
to: "33601020304",
|
|
198
|
+
message: "Your 2FA code is 123456",
|
|
199
|
+
no_stop: true # Removes "STOP au XXXXX" from message
|
|
200
|
+
)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### With Custom Tag for Tracking
|
|
204
|
+
|
|
205
|
+
```ruby
|
|
206
|
+
response = Ovh::Http2sms.deliver(
|
|
207
|
+
to: "33601020304",
|
|
208
|
+
message: "Order #12345 confirmed",
|
|
209
|
+
tag: "order-confirmations" # Max 20 characters
|
|
210
|
+
)
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Force Encoding
|
|
214
|
+
|
|
215
|
+
```ruby
|
|
216
|
+
# Force Unicode encoding
|
|
217
|
+
response = Ovh::Http2sms.deliver(
|
|
218
|
+
to: "33601020304",
|
|
219
|
+
message: "Hello World",
|
|
220
|
+
sms_coding: 2 # 1 = GSM 7-bit, 2 = Unicode
|
|
221
|
+
)
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Phone Number Formatting
|
|
225
|
+
|
|
226
|
+
The gem automatically formats phone numbers to OVH international format (00 prefix):
|
|
227
|
+
|
|
228
|
+
```ruby
|
|
229
|
+
# Local French number
|
|
230
|
+
Ovh::Http2sms.format_phone("0601020304")
|
|
231
|
+
# => "0033601020304"
|
|
232
|
+
|
|
233
|
+
# Already international
|
|
234
|
+
Ovh::Http2sms.format_phone("33601020304")
|
|
235
|
+
# => "0033601020304"
|
|
236
|
+
|
|
237
|
+
# With plus sign
|
|
238
|
+
Ovh::Http2sms.format_phone("+33601020304")
|
|
239
|
+
# => "0033601020304"
|
|
240
|
+
|
|
241
|
+
# With spaces and dashes
|
|
242
|
+
Ovh::Http2sms.format_phone("06 01 02-03-04")
|
|
243
|
+
# => "0033601020304"
|
|
244
|
+
|
|
245
|
+
# Already OVH format (unchanged)
|
|
246
|
+
Ovh::Http2sms.format_phone("0033601020304")
|
|
247
|
+
# => "0033601020304"
|
|
248
|
+
|
|
249
|
+
# UK number with custom country code
|
|
250
|
+
Ovh::Http2sms.format_phone("07911123456", country_code: "44")
|
|
251
|
+
# => "00447911123456"
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## Character Encoding
|
|
255
|
+
|
|
256
|
+
SMS messages use different encodings with different character limits:
|
|
257
|
+
|
|
258
|
+
| Encoding | Single SMS | Concatenated SMS |
|
|
259
|
+
|----------|------------|------------------|
|
|
260
|
+
| GSM 7-bit | 160 chars | 153 chars/part |
|
|
261
|
+
| Unicode | 70 chars | 67 chars/part |
|
|
262
|
+
|
|
263
|
+
For commercial SMS (with STOP clause), limits are reduced:
|
|
264
|
+
|
|
265
|
+
| Encoding | First SMS | Subsequent |
|
|
266
|
+
|----------|-----------|------------|
|
|
267
|
+
| GSM 7-bit | 149 chars | 153 chars |
|
|
268
|
+
| Unicode | 59 chars | 70 chars |
|
|
269
|
+
|
|
270
|
+
### Check Message Info
|
|
271
|
+
|
|
272
|
+
```ruby
|
|
273
|
+
info = Ovh::Http2sms.message_info("Hello World!")
|
|
274
|
+
# => {
|
|
275
|
+
# characters: 12,
|
|
276
|
+
# encoding: :gsm,
|
|
277
|
+
# sms_count: 1,
|
|
278
|
+
# remaining: 137,
|
|
279
|
+
# max_single_sms: 149,
|
|
280
|
+
# non_gsm_chars: []
|
|
281
|
+
# }
|
|
282
|
+
|
|
283
|
+
# With emoji (forces Unicode)
|
|
284
|
+
info = Ovh::Http2sms.message_info("Hello! 👋")
|
|
285
|
+
# => {
|
|
286
|
+
# characters: 9,
|
|
287
|
+
# encoding: :unicode,
|
|
288
|
+
# sms_count: 1,
|
|
289
|
+
# remaining: 50,
|
|
290
|
+
# max_single_sms: 59,
|
|
291
|
+
# non_gsm_chars: ["👋"]
|
|
292
|
+
# }
|
|
293
|
+
|
|
294
|
+
# For non-commercial SMS
|
|
295
|
+
info = Ovh::Http2sms.message_info("Hello!", commercial: false)
|
|
296
|
+
# => { remaining: 154, max_single_sms: 160, ... }
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Check GSM Compatibility
|
|
300
|
+
|
|
301
|
+
```ruby
|
|
302
|
+
Ovh::Http2sms.gsm_compatible?("Hello World!") # => true
|
|
303
|
+
Ovh::Http2sms.gsm_compatible?("Привет мир!") # => false
|
|
304
|
+
Ovh::Http2sms.gsm_compatible?("Price: €100") # => true (€ is GSM extension)
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
### GSM Extension Characters
|
|
308
|
+
|
|
309
|
+
These characters are valid in GSM encoding but count as 2 characters:
|
|
310
|
+
`€`, `|`, `^`, `{`, `}`, `[`, `]`, `~`, `\`
|
|
311
|
+
|
|
312
|
+
## Error Handling
|
|
313
|
+
|
|
314
|
+
```ruby
|
|
315
|
+
begin
|
|
316
|
+
response = Ovh::Http2sms.deliver(to: "33601020304", message: "Hello!")
|
|
317
|
+
rescue Ovh::Http2sms::ConfigurationError => e
|
|
318
|
+
puts "Missing configuration: #{e.message}"
|
|
319
|
+
rescue Ovh::Http2sms::AuthenticationError => e
|
|
320
|
+
puts "IP not authorized: #{e.message}"
|
|
321
|
+
rescue Ovh::Http2sms::MissingParameterError => e
|
|
322
|
+
puts "Missing parameter: #{e.message}"
|
|
323
|
+
rescue Ovh::Http2sms::InvalidParameterError => e
|
|
324
|
+
puts "Invalid parameter: #{e.message}"
|
|
325
|
+
rescue Ovh::Http2sms::SenderNotFoundError => e
|
|
326
|
+
puts "Sender not registered: #{e.message}"
|
|
327
|
+
rescue Ovh::Http2sms::PhoneNumberError => e
|
|
328
|
+
puts "Invalid phone number: #{e.phone_number}"
|
|
329
|
+
rescue Ovh::Http2sms::MessageLengthError => e
|
|
330
|
+
puts "Message too long: #{e.length} chars (#{e.encoding} encoding)"
|
|
331
|
+
rescue Ovh::Http2sms::NetworkError => e
|
|
332
|
+
puts "Network error: #{e.message}"
|
|
333
|
+
rescue Ovh::Http2sms::ResponseParseError => e
|
|
334
|
+
puts "Failed to parse response: #{e.message}"
|
|
335
|
+
rescue Ovh::Http2sms::Error => e
|
|
336
|
+
puts "General error: #{e.message}"
|
|
337
|
+
end
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
## Rails Integration
|
|
341
|
+
|
|
342
|
+
### Generate Initializer
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
rails g ovh:http2sms:install
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
This creates `config/initializers/ovh_http2sms.rb` with configuration options.
|
|
349
|
+
|
|
350
|
+
### Using with ActiveJob
|
|
351
|
+
|
|
352
|
+
Parameters are serializable and work with ActiveJob:
|
|
353
|
+
|
|
354
|
+
```ruby
|
|
355
|
+
class SmsNotificationJob < ApplicationJob
|
|
356
|
+
queue_as :default
|
|
357
|
+
|
|
358
|
+
def perform(phone_number, message, options = {})
|
|
359
|
+
Ovh::Http2sms.deliver(
|
|
360
|
+
to: phone_number,
|
|
361
|
+
message: message,
|
|
362
|
+
**options.symbolize_keys
|
|
363
|
+
)
|
|
364
|
+
end
|
|
365
|
+
end
|
|
366
|
+
|
|
367
|
+
# Enqueue
|
|
368
|
+
SmsNotificationJob.perform_later("0601020304", "Your order shipped!", { tag: "shipping" })
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
### Multiple Accounts
|
|
372
|
+
|
|
373
|
+
Use separate clients for different OVH accounts:
|
|
374
|
+
|
|
375
|
+
```ruby
|
|
376
|
+
marketing_client = Ovh::Http2sms.client(
|
|
377
|
+
account: "sms-marketing-1",
|
|
378
|
+
login: "marketing_user",
|
|
379
|
+
password: "marketing_pass",
|
|
380
|
+
default_sender: "Promo"
|
|
381
|
+
)
|
|
382
|
+
|
|
383
|
+
transactional_client = Ovh::Http2sms.client(
|
|
384
|
+
account: "sms-transact-1",
|
|
385
|
+
login: "transact_user",
|
|
386
|
+
password: "transact_pass",
|
|
387
|
+
default_sender: "Alerts"
|
|
388
|
+
)
|
|
389
|
+
|
|
390
|
+
marketing_client.deliver(to: "33601020304", message: "Special offer!")
|
|
391
|
+
transactional_client.deliver(to: "33601020304", message: "Order confirmed", no_stop: true)
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
## Response Object
|
|
395
|
+
|
|
396
|
+
```ruby
|
|
397
|
+
response = Ovh::Http2sms.deliver(to: "33601020304", message: "Hello!")
|
|
398
|
+
|
|
399
|
+
response.success? # true/false
|
|
400
|
+
response.failure? # opposite of success?
|
|
401
|
+
response.status # API status code (100, 101 = success)
|
|
402
|
+
response.sms_ids # Array of SMS IDs
|
|
403
|
+
response.credits_remaining # Remaining SMS credits
|
|
404
|
+
response.error_message # Error message if failed
|
|
405
|
+
response.error_type # :missing_parameter, :invalid_parameter, :authentication_error
|
|
406
|
+
response.raw_response # Raw API response body
|
|
407
|
+
response.content_type # Response content type
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
## API Reference
|
|
411
|
+
|
|
412
|
+
### OVH Response Codes
|
|
413
|
+
|
|
414
|
+
| Code | Meaning |
|
|
415
|
+
|------|---------|
|
|
416
|
+
| 100, 101 | Success |
|
|
417
|
+
| 201 | Missing parameter |
|
|
418
|
+
| 202 | Invalid parameter |
|
|
419
|
+
| 241 | Sender not found |
|
|
420
|
+
| 401 | IP not authorized |
|
|
421
|
+
|
|
422
|
+
### SMS Classes
|
|
423
|
+
|
|
424
|
+
| Class | Description |
|
|
425
|
+
|-------|-------------|
|
|
426
|
+
| 0 | Flash SMS (displayed immediately, not stored) |
|
|
427
|
+
| 1 | Stored in phone memory (default) |
|
|
428
|
+
| 2 | Stored on SIM card |
|
|
429
|
+
| 3 | Transferred to external device |
|
|
430
|
+
|
|
431
|
+
## Development
|
|
432
|
+
|
|
433
|
+
### With Docker (recommended)
|
|
434
|
+
|
|
435
|
+
```bash
|
|
436
|
+
# Interactive console
|
|
437
|
+
docker compose run --rm dev
|
|
438
|
+
|
|
439
|
+
# Run tests
|
|
440
|
+
docker compose run --rm test
|
|
441
|
+
|
|
442
|
+
# Run linter
|
|
443
|
+
docker compose run --rm lint
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
To test with real credentials:
|
|
447
|
+
|
|
448
|
+
```bash
|
|
449
|
+
cp .env.example .env
|
|
450
|
+
# Edit .env with your OVH credentials
|
|
451
|
+
docker compose run --rm dev
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
### Without Docker
|
|
455
|
+
|
|
456
|
+
After checking out the repo, run:
|
|
457
|
+
|
|
458
|
+
```bash
|
|
459
|
+
bin/setup
|
|
460
|
+
bundle exec rake spec
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
To install locally:
|
|
464
|
+
|
|
465
|
+
```bash
|
|
466
|
+
bundle exec rake install
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
### Running Tests
|
|
470
|
+
|
|
471
|
+
```bash
|
|
472
|
+
bundle exec rspec
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
### Code Style
|
|
476
|
+
|
|
477
|
+
```bash
|
|
478
|
+
bundle exec rubocop
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
## Contributing
|
|
482
|
+
|
|
483
|
+
1. Fork it
|
|
484
|
+
2. Create your feature branch (`git checkout -b feature/my-feature`)
|
|
485
|
+
3. Commit your changes (`git commit -am 'Add my feature'`)
|
|
486
|
+
4. Push to the branch (`git push origin feature/my-feature`)
|
|
487
|
+
5. Create a Pull Request
|
|
488
|
+
|
|
489
|
+
Please ensure:
|
|
490
|
+
- All tests pass
|
|
491
|
+
- Code follows Ruby style guide (Rubocop)
|
|
492
|
+
- New features have tests
|
|
493
|
+
- Documentation is updated
|
|
494
|
+
|
|
495
|
+
## License
|
|
496
|
+
|
|
497
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
498
|
+
|
|
499
|
+
## Links
|
|
500
|
+
|
|
501
|
+
- [OVH SMS Documentation](https://help.ovhcloud.com/csm/fr-sms-sending-via-url-http2sms)
|
|
502
|
+
- [RubyGems](https://rubygems.org/gems/ovh-http2sms)
|
|
503
|
+
- [API Documentation](https://rubydoc.info/gems/ovh-http2sms)
|
data/Rakefile
ADDED
data/docker-compose.yml
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
services:
|
|
2
|
+
dev:
|
|
3
|
+
build: .
|
|
4
|
+
volumes:
|
|
5
|
+
- .:/gem
|
|
6
|
+
- bundle_cache:/usr/local/bundle
|
|
7
|
+
environment:
|
|
8
|
+
- OVH_SMS_ACCOUNT=${OVH_SMS_ACCOUNT}
|
|
9
|
+
- OVH_SMS_LOGIN=${OVH_SMS_LOGIN}
|
|
10
|
+
- OVH_SMS_PASSWORD=${OVH_SMS_PASSWORD}
|
|
11
|
+
stdin_open: true
|
|
12
|
+
tty: true
|
|
13
|
+
|
|
14
|
+
test:
|
|
15
|
+
build: .
|
|
16
|
+
volumes:
|
|
17
|
+
- .:/gem
|
|
18
|
+
- bundle_cache:/usr/local/bundle
|
|
19
|
+
command: bundle exec rspec
|
|
20
|
+
|
|
21
|
+
lint:
|
|
22
|
+
build: .
|
|
23
|
+
volumes:
|
|
24
|
+
- .:/gem
|
|
25
|
+
- bundle_cache:/usr/local/bundle
|
|
26
|
+
command: bundle exec rubocop
|
|
27
|
+
|
|
28
|
+
volumes:
|
|
29
|
+
bundle_cache:
|