mitake_sms 1.3.0 → 1.5.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 +4 -4
- data/CHANGELOG.md +20 -0
- data/README.md +5 -4
- data/lib/mitake_sms/client.rb +57 -30
- data/lib/mitake_sms/configuration.rb +11 -11
- data/lib/mitake_sms/version.rb +1 -1
- data/lib/mitake_sms.rb +14 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b8e4f3f9a2745fa7633cb7df508a09c1c639d1d55935ae9b5b77b5102535f70
|
4
|
+
data.tar.gz: 10e11540186c4f9a52f0f178c516dfe94ae407d752f97779596f650403638462
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f49f9b77f286f86c21e0439bd0f78799d788e8abab1ddfe3c6b3f52679cd0e978e25a3344a22d55a262b46767864af0969ae4569e6a3789e4ebcb119149bf45f
|
7
|
+
data.tar.gz: 624ffd3d41a925bc2a6ee287f0e4ca5f00cc9e5ba0f30e3cb6d98c4fd2ec26b260066620884642e92cb22e756c07f78126d7c8006828af01b54705edd67d138c
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [1.5.0] - 2025-05-25
|
11
|
+
### Added
|
12
|
+
- Added named parameters (keyword arguments) to `send_sms` method for improved readability and flexibility
|
13
|
+
|
14
|
+
### Changed
|
15
|
+
- Updated `send_sms` method to use named parameters instead of positional parameters
|
16
|
+
- Removed `from` parameter from `send_sms` method
|
17
|
+
- Updated tests to use named parameters for `send_sms` method
|
18
|
+
|
19
|
+
## [1.4.0] - 2025-05-25
|
20
|
+
### Changed
|
21
|
+
- Modified all batch SMS parameters to be sent as query string parameters instead of in the POST body
|
22
|
+
- Updated `send_batch` and `send_advanced_batch` methods to use query string parameters
|
23
|
+
- Modified tests to verify query string parameter handling for batch SMS
|
24
|
+
|
25
|
+
## [1.3.1] - 2025-05-25
|
26
|
+
### Changed
|
27
|
+
- Modified `CharsetURL` parameter to be sent as a query string parameter instead of a form parameter
|
28
|
+
- Updated tests to verify query string parameter handling
|
29
|
+
|
10
30
|
## [1.3.0] - 2025-05-25
|
11
31
|
### Changed
|
12
32
|
- Removed automatic URL encoding of message content
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# MitakeSms
|
2
2
|
|
3
3
|
[](https://codecov.io/gh/7a6163/mitake_sms)
|
4
|
+

|
5
|
+
|
4
6
|
|
5
7
|
A Ruby client for the Mitake SMS API, providing a simple and efficient way to send SMS messages through the Mitake SMS service.
|
6
8
|
|
@@ -53,7 +55,7 @@ end
|
|
53
55
|
|
54
56
|
```ruby
|
55
57
|
# Send a simple SMS (uses UTF-8 encoding by default)
|
56
|
-
response = MitakeSms.send_sms('0912345678', 'Hello, this is a test message!')
|
58
|
+
response = MitakeSms.send_sms(to: '0912345678', text: 'Hello, this is a test message!')
|
57
59
|
|
58
60
|
if response.success?
|
59
61
|
puts "Message sent successfully! Message ID: #{response.message_id}"
|
@@ -64,9 +66,8 @@ end
|
|
64
66
|
|
65
67
|
# With additional options
|
66
68
|
response = MitakeSms.send_sms(
|
67
|
-
'0912345678',
|
68
|
-
'Hello with options!',
|
69
|
-
from: 'YourBrand',
|
69
|
+
to: '0912345678',
|
70
|
+
text: 'Hello with options!',
|
70
71
|
response_url: 'https://your-callback-url.com/delivery-reports',
|
71
72
|
client_id: 'your-client-reference-id',
|
72
73
|
charset: 'BIG5' # Override the default UTF-8 encoding if needed
|
data/lib/mitake_sms/client.rb
CHANGED
@@ -22,29 +22,41 @@ module MitakeSms
|
|
22
22
|
# Send a single SMS
|
23
23
|
# @param to [String] recipient phone number
|
24
24
|
# @param text [String] message content
|
25
|
-
# @param
|
26
|
-
# @
|
27
|
-
# @
|
28
|
-
# @
|
29
|
-
# @option options [String] :charset character encoding, defaults to 'UTF8'
|
25
|
+
# @param response_url [String] callback URL for delivery reports (optional)
|
26
|
+
# @param client_id [String] client reference ID (optional)
|
27
|
+
# @param charset [String] character encoding, defaults to 'UTF8' (optional)
|
28
|
+
# @param options [Hash] additional options (optional)
|
30
29
|
# @return [MitakeSms::Response] response object
|
31
|
-
def send_sms(to
|
30
|
+
def send_sms(to:, text:, response_url: nil, client_id: nil, charset: 'UTF8', **options)
|
32
31
|
require 'uri'
|
33
|
-
|
32
|
+
|
33
|
+
# Create options hash with only non-nil values
|
34
|
+
param_options = {}
|
35
|
+
param_options[:response_url] = response_url if response_url
|
36
|
+
param_options[:client_id] = client_id if client_id
|
34
37
|
|
35
38
|
# Replace any newline characters with ASCII code 6 (ACK)
|
36
39
|
# This is required by the Mitake API to represent line breaks
|
37
40
|
processed_text = text.to_s.gsub("\n", 6.chr)
|
38
41
|
|
39
|
-
|
42
|
+
# Prepare query parameters - all parameters are now sent as query parameters
|
43
|
+
query_params = {
|
40
44
|
username: @config.username,
|
41
45
|
password: @config.password,
|
42
46
|
dstaddr: to,
|
43
47
|
smbody: processed_text,
|
44
48
|
CharsetURL: charset
|
45
|
-
}.merge(
|
46
|
-
|
47
|
-
|
49
|
+
}.merge(param_options).merge(options)
|
50
|
+
|
51
|
+
# Construct the endpoint URL
|
52
|
+
endpoint = "SmSend"
|
53
|
+
|
54
|
+
response = @connection.post(endpoint) do |req|
|
55
|
+
req.params = query_params
|
56
|
+
# Empty body since all parameters are in the query string
|
57
|
+
req.body = {}
|
58
|
+
end
|
59
|
+
|
48
60
|
handle_response(response)
|
49
61
|
end
|
50
62
|
|
@@ -137,23 +149,32 @@ module MitakeSms
|
|
137
149
|
# @return [MitakeSms::Response] response object
|
138
150
|
def send_batch(batch, charset = 'UTF8', options = {})
|
139
151
|
require 'uri'
|
152
|
+
|
153
|
+
# Prepare the batch message content
|
154
|
+
smbody = batch.map do |msg|
|
155
|
+
to = msg[:to]
|
156
|
+
|
157
|
+
# Replace any newline characters with ASCII code 6 (ACK)
|
158
|
+
# This is required by the Mitake API to represent line breaks
|
159
|
+
processed_text = msg[:text].to_s.gsub("\n", 6.chr)
|
140
160
|
|
141
|
-
|
161
|
+
"#{to}:#{processed_text}"
|
162
|
+
end.join("\n")
|
163
|
+
|
164
|
+
# All parameters should be sent as query string parameters
|
165
|
+
query_params = {
|
142
166
|
username: @config.username,
|
143
167
|
password: @config.password,
|
144
|
-
smbody:
|
145
|
-
to = msg[:to]
|
146
|
-
|
147
|
-
# Replace any newline characters with ASCII code 6 (ACK)
|
148
|
-
# This is required by the Mitake API to represent line breaks
|
149
|
-
processed_text = msg[:text].to_s.gsub("\n", 6.chr)
|
150
|
-
|
151
|
-
"#{to}:#{processed_text}"
|
152
|
-
end.join("\n"),
|
168
|
+
smbody: smbody,
|
153
169
|
Encoding_PostIn: charset
|
154
170
|
}
|
155
|
-
|
156
|
-
|
171
|
+
|
172
|
+
# Use empty body with all parameters in query string
|
173
|
+
response = @connection.post('SmBulkSend') do |req|
|
174
|
+
req.params = query_params
|
175
|
+
req.body = {}
|
176
|
+
end
|
177
|
+
|
157
178
|
handle_response(response)
|
158
179
|
end
|
159
180
|
|
@@ -164,10 +185,10 @@ module MitakeSms
|
|
164
185
|
# @return [MitakeSms::Response] response object
|
165
186
|
def send_advanced_batch(batch, charset = 'UTF8', options = {})
|
166
187
|
require 'uri'
|
167
|
-
|
188
|
+
|
168
189
|
# Format each message according to the advanced format
|
169
190
|
# ClientID $$ dstaddr $$ dlvtime $$ vldtime $$ destname $$ response $$ smbody
|
170
|
-
|
191
|
+
data = batch.map do |msg|
|
171
192
|
# ClientID is required and must be unique
|
172
193
|
# If not provided, generate a unique ID
|
173
194
|
client_id = msg[:client_id]
|
@@ -180,22 +201,28 @@ module MitakeSms
|
|
180
201
|
vldtime = msg[:vldtime] || ''
|
181
202
|
dest_name = msg[:dest_name] || ''
|
182
203
|
response_url = msg[:response] || ''
|
183
|
-
|
204
|
+
|
184
205
|
# Replace any newline characters in the message text with ASCII code 6 (ACK)
|
185
206
|
# This is required by the Mitake API to represent line breaks within message content
|
186
207
|
processed_text = msg[:text].to_s.gsub("\n", 6.chr)
|
187
|
-
|
208
|
+
|
188
209
|
[client_id, to, dlvtime, vldtime, dest_name, response_url, processed_text].join('$$')
|
189
210
|
end.join("\n")
|
190
211
|
|
191
|
-
|
212
|
+
# All parameters should be sent as query string parameters
|
213
|
+
query_params = {
|
192
214
|
username: @config.username,
|
193
215
|
password: @config.password,
|
194
|
-
data:
|
216
|
+
data: data,
|
195
217
|
Encoding_PostIn: charset
|
196
218
|
}
|
197
219
|
|
198
|
-
|
220
|
+
# Use empty body with all parameters in query string
|
221
|
+
response = @connection.post('SmPost') do |req|
|
222
|
+
req.params = query_params
|
223
|
+
req.body = {}
|
224
|
+
end
|
225
|
+
|
199
226
|
handle_response(response)
|
200
227
|
end
|
201
228
|
|
@@ -8,48 +8,48 @@ module MitakeSms
|
|
8
8
|
|
9
9
|
setting :username, default: ENV['MITAKE_USERNAME']
|
10
10
|
setting :password, default: ENV['MITAKE_PASSWORD']
|
11
|
-
setting :api_url, default: 'https://smsapi.mitake.com.tw/
|
11
|
+
setting :api_url, default: 'https://smsapi.mitake.com.tw/b2c/mtk/'
|
12
12
|
setting :timeout, default: 30
|
13
13
|
setting :open_timeout, default: 5
|
14
|
-
|
14
|
+
|
15
15
|
# Provide direct access to configuration values at the class level
|
16
16
|
class << self
|
17
17
|
def username
|
18
18
|
config.username
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
def username=(value)
|
22
22
|
config.username = value
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def password
|
26
26
|
config.password
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def password=(value)
|
30
30
|
config.password = value
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def api_url
|
34
34
|
config.api_url
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
def api_url=(value)
|
38
38
|
config.api_url = value
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def timeout
|
42
42
|
config.timeout
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def timeout=(value)
|
46
46
|
config.timeout = value
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def open_timeout
|
50
50
|
config.open_timeout
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
def open_timeout=(value)
|
54
54
|
config.open_timeout = value
|
55
55
|
end
|
data/lib/mitake_sms/version.rb
CHANGED
data/lib/mitake_sms.rb
CHANGED
@@ -38,15 +38,21 @@ module MitakeSms
|
|
38
38
|
# Send a single SMS message
|
39
39
|
# @param to [String] recipient phone number
|
40
40
|
# @param text [String] message content
|
41
|
-
# @param
|
42
|
-
# @
|
43
|
-
# @
|
44
|
-
# @
|
45
|
-
# @option options [String] :charset character encoding, defaults to 'UTF8'
|
46
|
-
|
41
|
+
# @param response_url [String] callback URL for delivery reports (optional)
|
42
|
+
# @param client_id [String] client reference ID (optional)
|
43
|
+
# @param charset [String] character encoding, defaults to 'UTF8' (optional)
|
44
|
+
# @param options [Hash] additional options (optional)
|
47
45
|
# @return [MitakeSms::Response] response object
|
48
|
-
def send_sms(to
|
49
|
-
|
46
|
+
def send_sms(to:, text:, response_url: nil, client_id: nil, charset: 'UTF8', **options)
|
47
|
+
# Forward all parameters to the client method using named parameters
|
48
|
+
client.send_sms(
|
49
|
+
to: to,
|
50
|
+
text: text,
|
51
|
+
response_url: response_url,
|
52
|
+
client_id: client_id,
|
53
|
+
charset: charset,
|
54
|
+
**options
|
55
|
+
)
|
50
56
|
end
|
51
57
|
|
52
58
|
# Send multiple SMS messages in a single request
|