luosimao-sms 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/CHANGELOG.md +4 -0
- data/README.md +96 -83
- data/lib/luosimao/sms/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 594494c09ac0b6b45af894d922c67fe08216b0226be0c68bb128a6fb778756b6
|
|
4
|
+
data.tar.gz: 5d1fc0bed22b7bb81f59199e20da97411ee79e070f02ad026be8e443409780ec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 79d6a256e7754ea309eb869d6d61c4895ac5f25d0773d64b0edbac7b321b59a0238cd3c2ac09d2f8eb2b2e038a932e38b0ecf53f7ff49733abd4292aea4b4882
|
|
7
|
+
data.tar.gz: 663a2b0304b508024a6be497d58d702cf82888fa0c02d2705cbb6e81b52057e126205172ee73ea962590cf2589c7b2d2ccb61bb8b3afa7334baf67065badc05d
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.1.1] - 2026-03-29
|
|
6
|
+
### Fixed
|
|
7
|
+
- Corrected `homepage` URL in gemspec to match the actual GitHub repository.
|
|
8
|
+
|
|
5
9
|
## [0.1.0] - 2026-03-29
|
|
6
10
|
### Added
|
|
7
11
|
- Initial release of `luosimao-sms` gem.
|
data/README.md
CHANGED
|
@@ -1,30 +1,27 @@
|
|
|
1
1
|
# Luosimao SMS Ruby SDK
|
|
2
2
|
|
|
3
|
+
[](https://rubygems.org/gems/luosimao-sms)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
A Ruby SDK for sending SMS via the [Luosimao](https://luosimao.com) API. Integrates seamlessly with your Ruby/Rails application.
|
|
7
|
+
|
|
3
8
|
[English](#english) | [中文](#chinese)
|
|
4
9
|
|
|
10
|
+
---
|
|
11
|
+
|
|
5
12
|
<a id="english"></a>
|
|
6
13
|
## English
|
|
7
14
|
|
|
8
|
-
A Ruby SDK for sending SMS via the [Luosimao](https://luosimao.com) API.
|
|
9
|
-
|
|
10
15
|
### Installation
|
|
11
16
|
|
|
12
|
-
Add this line to your application's Gemfile:
|
|
13
|
-
|
|
14
|
-
```ruby
|
|
15
|
-
gem 'luosimao-sms'
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
And then execute:
|
|
19
|
-
|
|
20
17
|
```bash
|
|
21
|
-
|
|
18
|
+
gem install luosimao-sms
|
|
22
19
|
```
|
|
23
20
|
|
|
24
|
-
Or
|
|
21
|
+
Or add to your `Gemfile`:
|
|
25
22
|
|
|
26
|
-
```
|
|
27
|
-
|
|
23
|
+
```ruby
|
|
24
|
+
gem 'luosimao-sms'
|
|
28
25
|
```
|
|
29
26
|
|
|
30
27
|
### Quick Start
|
|
@@ -34,65 +31,77 @@ require 'luosimao-sms'
|
|
|
34
31
|
|
|
35
32
|
client = Luosimao::SMS::Client.new(api_key: 'your_api_key')
|
|
36
33
|
|
|
37
|
-
# Send SMS
|
|
34
|
+
# Send a single SMS
|
|
38
35
|
response = client.send(mobile: '13800138000', message: 'Verification code 123456【Your Company】')
|
|
39
36
|
puts response.success?
|
|
40
37
|
|
|
41
|
-
# Batch
|
|
38
|
+
# Batch send
|
|
42
39
|
response = client.send_batch(
|
|
43
40
|
mobiles: ['13800138000', '13800138001'],
|
|
44
|
-
message: '
|
|
41
|
+
message: 'Notification content【Your Company】'
|
|
45
42
|
)
|
|
46
43
|
|
|
47
|
-
# Check
|
|
44
|
+
# Check balance
|
|
48
45
|
status = client.status
|
|
49
|
-
puts status.deposit
|
|
46
|
+
puts "Balance: #{status.deposit} messages"
|
|
50
47
|
```
|
|
51
48
|
|
|
52
49
|
### Configuration
|
|
53
50
|
|
|
54
|
-
You can configure the client with optional parameters:
|
|
55
|
-
|
|
56
51
|
```ruby
|
|
57
52
|
client = Luosimao::SMS::Client.new(
|
|
58
|
-
api_key: 'your_api_key',
|
|
59
|
-
timeout: 10,
|
|
60
|
-
open_timeout: 5,
|
|
61
|
-
base_url: 'https://sms-api.luosimao.com'
|
|
53
|
+
api_key: 'your_api_key', # Required. Auto-adds 'key-' prefix if omitted.
|
|
54
|
+
timeout: 10, # Read timeout in seconds (default: 30).
|
|
55
|
+
open_timeout: 5, # Connection timeout in seconds (default: 10).
|
|
56
|
+
base_url: 'https://sms-api.luosimao.com' # For testing purposes.
|
|
62
57
|
)
|
|
63
58
|
```
|
|
64
59
|
|
|
65
|
-
The `api_key` can be provided with or without the `key-` prefix.
|
|
66
|
-
|
|
67
60
|
### API Reference
|
|
68
61
|
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
| Method | Description |
|
|
63
|
+
|--------|-------------|
|
|
64
|
+
| `client.send(mobile:, message:)` | Send a single SMS. Returns `Luosimao::SMS::Response`. |
|
|
65
|
+
| `client.send_batch(mobiles:, message:, send_at: nil)` | Batch send. `send_at` accepts a `Time` object for scheduled delivery. |
|
|
66
|
+
| `client.status` | Query account balance. Returns `Luosimao::SMS::StatusResponse`. |
|
|
71
67
|
|
|
72
|
-
|
|
73
|
-
Sends a batch SMS message. Returns `Luosimao::SMS::Response`.
|
|
68
|
+
### Error Handling
|
|
74
69
|
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
| Exception | Description | Helper Methods |
|
|
71
|
+
|-----------|-------------|----------------|
|
|
72
|
+
| `Luosimao::SMS::APIError` | API returned an error code. | `auth_failed?`, `insufficient_balance?`, `sensitive_words?`, `ip_not_allowed?` |
|
|
73
|
+
| `Luosimao::SMS::NetworkError` | Network failure (timeout, connection refused, invalid JSON). | - |
|
|
74
|
+
| `Luosimao::SMS::ArgumentError` | Invalid method arguments. | - |
|
|
77
75
|
|
|
78
|
-
|
|
76
|
+
Example:
|
|
79
77
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
78
|
+
```ruby
|
|
79
|
+
begin
|
|
80
|
+
client.send(mobile: '13800138000', message: 'Verification code 123456【Company】')
|
|
81
|
+
rescue Luosimao::SMS::APIError => e
|
|
82
|
+
puts "API Error [#{e.code}]: #{e.message}"
|
|
83
|
+
puts "Insufficient balance!" if e.insufficient_balance?
|
|
84
|
+
rescue Luosimao::SMS::NetworkError => e
|
|
85
|
+
puts "Network error: #{e.message}"
|
|
86
|
+
end
|
|
87
|
+
```
|
|
84
88
|
|
|
85
89
|
### Development
|
|
86
90
|
|
|
87
|
-
|
|
91
|
+
```bash
|
|
92
|
+
git clone https://github.com/luosimao-oss/luosimao-sms-ruby.git
|
|
93
|
+
cd luosimao-sms
|
|
94
|
+
bundle install
|
|
95
|
+
bundle exec rspec
|
|
96
|
+
```
|
|
88
97
|
|
|
89
98
|
### Contributing
|
|
90
99
|
|
|
91
|
-
|
|
100
|
+
Contributions are welcome! Please feel free to submit a Pull Request.
|
|
92
101
|
|
|
93
102
|
### License
|
|
94
103
|
|
|
95
|
-
|
|
104
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
96
105
|
|
|
97
106
|
---
|
|
98
107
|
|
|
@@ -101,27 +110,19 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
|
101
110
|
|
|
102
111
|
螺丝帽 (Luosimao) 短信服务的 Ruby SDK。
|
|
103
112
|
|
|
104
|
-
###
|
|
105
|
-
|
|
106
|
-
将以下代码添加到你的 `Gemfile`:
|
|
107
|
-
|
|
108
|
-
```ruby
|
|
109
|
-
gem 'luosimao-sms'
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
然后执行:
|
|
113
|
+
### 安装
|
|
113
114
|
|
|
114
115
|
```bash
|
|
115
|
-
|
|
116
|
+
gem install luosimao-sms
|
|
116
117
|
```
|
|
117
118
|
|
|
118
|
-
|
|
119
|
+
或在 `Gemfile` 中添加:
|
|
119
120
|
|
|
120
|
-
```
|
|
121
|
-
|
|
121
|
+
```ruby
|
|
122
|
+
gem 'luosimao-sms'
|
|
122
123
|
```
|
|
123
124
|
|
|
124
|
-
###
|
|
125
|
+
### 快速开始
|
|
125
126
|
|
|
126
127
|
```ruby
|
|
127
128
|
require 'luosimao-sms'
|
|
@@ -140,50 +141,62 @@ response = client.send_batch(
|
|
|
140
141
|
|
|
141
142
|
# 查询余额
|
|
142
143
|
status = client.status
|
|
143
|
-
puts status.deposit
|
|
144
|
+
puts "当前余额:#{status.deposit} 条"
|
|
144
145
|
```
|
|
145
146
|
|
|
146
|
-
###
|
|
147
|
-
|
|
148
|
-
支持以下可选配置参数:
|
|
147
|
+
### 配置参数
|
|
149
148
|
|
|
150
149
|
```ruby
|
|
151
150
|
client = Luosimao::SMS::Client.new(
|
|
152
|
-
api_key: 'your_api_key',
|
|
153
|
-
timeout: 10,
|
|
154
|
-
open_timeout: 5,
|
|
155
|
-
base_url: 'https://sms-api.luosimao.com'
|
|
151
|
+
api_key: 'your_api_key', # 必填。未带 key- 前缀会自动补全。
|
|
152
|
+
timeout: 10, # 读取超时,默认 30 秒。
|
|
153
|
+
open_timeout: 5, # 连接超时,默认 10 秒。
|
|
154
|
+
base_url: 'https://sms-api.luosimao.com' # 可用于测试环境。
|
|
156
155
|
)
|
|
157
156
|
```
|
|
158
157
|
|
|
159
|
-
|
|
158
|
+
### 接口说明
|
|
160
159
|
|
|
161
|
-
|
|
160
|
+
| 方法 | 说明 |
|
|
161
|
+
|------|------|
|
|
162
|
+
| `client.send(mobile:, message:)` | 单发短信。返回 `Luosimao::SMS::Response`。 |
|
|
163
|
+
| `client.send_batch(mobiles:, message:, send_at: nil)` | 批量发送。`send_at` 传入 `Time` 对象可定时发送。 |
|
|
164
|
+
| `client.status` | 查询账户余额。返回 `Luosimao::SMS::StatusResponse`。 |
|
|
162
165
|
|
|
163
|
-
|
|
164
|
-
单发短信。返回 `Luosimao::SMS::Response` 对象。
|
|
166
|
+
### 异常处理
|
|
165
167
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
+
| 异常类 | 说明 | 帮助方法 |
|
|
169
|
+
|--------|------|----------|
|
|
170
|
+
| `Luosimao::SMS::APIError` | API 返回错误码。 | `auth_failed?`, `insufficient_balance?`, `sensitive_words?`, `ip_not_allowed?` |
|
|
171
|
+
| `Luosimao::SMS::NetworkError` | 网络异常(超时、连接拒绝、非法 JSON)。 | - |
|
|
172
|
+
| `Luosimao::SMS::ArgumentError` | 参数错误。 | - |
|
|
168
173
|
|
|
169
|
-
|
|
170
|
-
查询账户余额。返回 `Luosimao::SMS::StatusResponse` 对象。
|
|
174
|
+
使用示例:
|
|
171
175
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
176
|
+
```ruby
|
|
177
|
+
begin
|
|
178
|
+
client.send(mobile: '13800138000', message: '验证码123456【公司名】')
|
|
179
|
+
rescue Luosimao::SMS::APIError => e
|
|
180
|
+
puts "接口错误 [#{e.code}]:#{e.message}"
|
|
181
|
+
puts "余额不足!" if e.insufficient_balance?
|
|
182
|
+
rescue Luosimao::SMS::NetworkError => e
|
|
183
|
+
puts "网络异常:#{e.message}"
|
|
184
|
+
end
|
|
185
|
+
```
|
|
178
186
|
|
|
179
|
-
###
|
|
187
|
+
### 本地开发
|
|
180
188
|
|
|
181
|
-
|
|
189
|
+
```bash
|
|
190
|
+
git clone https://github.com/luosimao-oss/luosimao-sms-ruby.git
|
|
191
|
+
cd luosimao-sms
|
|
192
|
+
bundle install
|
|
193
|
+
bundle exec rspec
|
|
194
|
+
```
|
|
182
195
|
|
|
183
|
-
###
|
|
196
|
+
### 贡献指南
|
|
184
197
|
|
|
185
|
-
欢迎提交 Issue 和 Pull Request
|
|
198
|
+
欢迎提交 Issue 和 Pull Request!
|
|
186
199
|
|
|
187
|
-
###
|
|
200
|
+
### 开源协议
|
|
188
201
|
|
|
189
|
-
|
|
202
|
+
本项目遵循 MIT 协议,详见 [LICENSE](LICENSE)。
|
data/lib/luosimao/sms/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: luosimao-sms
|
|
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
|
- luosimao-oss
|
|
@@ -67,7 +67,7 @@ files:
|
|
|
67
67
|
- lib/luosimao/sms/error.rb
|
|
68
68
|
- lib/luosimao/sms/response.rb
|
|
69
69
|
- lib/luosimao/sms/version.rb
|
|
70
|
-
homepage: https://github.com/luosimao-oss/
|
|
70
|
+
homepage: https://github.com/luosimao-oss/sms-ruby
|
|
71
71
|
licenses:
|
|
72
72
|
- MIT
|
|
73
73
|
metadata: {}
|