mitake_sms 1.5.3 → 2.0.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 +14 -0
- data/README.md +7 -6
- data/lib/mitake_sms/client.rb +25 -10
- data/lib/mitake_sms/version.rb +1 -1
- data/lib/mitake_sms.rb +3 -10
- 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: 39775d8249e44177aa4d89da4716abc178ccd834e6c653549389a419f305d08c
|
4
|
+
data.tar.gz: c47d00857751465b785cfe5da97b858b7c78722a8f65fd81d6e965de06541730
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04bea4cc56b8294f4e5ecc6667a6378ed49bc13221c4766e6b3102421ad598b118d0793bdf7cf900340013fcfe83484f6b64b75d55c1f2e508330c7aef26c49c
|
7
|
+
data.tar.gz: df170765544707a1b51ee0240811f4b379211f146725504d5b496c41792be713f13cf86ed4565689d51f2d09510f1b0a6df72a43512753bdc901fdb632402a38
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [2.0.0] - 2025-05-26
|
11
|
+
### Changed
|
12
|
+
- Modified `send_batch` method to use the advanced format with $$ separators
|
13
|
+
- Updated batch SMS request to place data in the request body with 'text/plain' content type
|
14
|
+
- Updated tests to verify the new batch SMS request format
|
15
|
+
|
16
|
+
### Removed
|
17
|
+
- Removed `advanced_batch_send_with_limit` method to simplify the API surface
|
18
|
+
|
19
|
+
## [1.6.0] - 2025-05-25
|
20
|
+
### Added
|
21
|
+
- Added `destname` parameter to `send_sms` method for recipient name or system integration key value
|
22
|
+
- Added tests for the new `destname` parameter
|
23
|
+
|
10
24
|
## [1.5.3] - 2025-05-25
|
11
25
|
### Changed
|
12
26
|
- Updated the default API URL to `https://smsapi.mitake.com.tw/api/mtk/`
|
data/README.md
CHANGED
@@ -68,6 +68,7 @@ end
|
|
68
68
|
response = MitakeSms.send_sms(
|
69
69
|
to: '0912345678',
|
70
70
|
text: 'Hello with options!',
|
71
|
+
destname: 'John Doe', # Recipient name or integration key value
|
71
72
|
response_url: 'https://your-callback-url.com/delivery-reports',
|
72
73
|
client_id: 'your-client-reference-id',
|
73
74
|
charset: 'BIG5' # Override the default UTF-8 encoding if needed
|
@@ -140,9 +141,9 @@ responses.each_with_index do |batch_response, index|
|
|
140
141
|
end
|
141
142
|
```
|
142
143
|
|
143
|
-
### Sending Advanced Format
|
144
|
+
### Sending Batch SMS with Advanced Format
|
144
145
|
|
145
|
-
The advanced format
|
146
|
+
The batch_send method now uses the advanced format by default, which provides more control over each message in the batch, including scheduled delivery, validity period, recipient name, and more:
|
146
147
|
|
147
148
|
```ruby
|
148
149
|
# Create messages with advanced options
|
@@ -152,8 +153,8 @@ messages = [
|
|
152
153
|
to: '0912345678', # Required recipient phone number
|
153
154
|
dlvtime: '20250526120000', # Optional delivery time (YYYYMMDDhhmmss)
|
154
155
|
vldtime: '20250527120000', # Optional validity period (YYYYMMDDhhmmss)
|
155
|
-
|
156
|
-
|
156
|
+
destname: '大寶', # Optional recipient name
|
157
|
+
response_url: 'https://callback.url', # Optional callback URL
|
157
158
|
text: '這是一則測試簡訊' # Required message content
|
158
159
|
},
|
159
160
|
{
|
@@ -177,8 +178,8 @@ messages = [
|
|
177
178
|
# - Long messages will be automatically split into multiple SMS messages if your account doesn't
|
178
179
|
# have long message permissions
|
179
180
|
|
180
|
-
# Send using
|
181
|
-
response = MitakeSms.
|
181
|
+
# Send using batch_send (automatically handles the advanced format)
|
182
|
+
response = MitakeSms.batch_send(messages)
|
182
183
|
|
183
184
|
# Process response similar to regular batch sending
|
184
185
|
if response.is_a?(MitakeSms::Response) && response.success?
|
data/lib/mitake_sms/client.rb
CHANGED
@@ -22,16 +22,18 @@ 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 destname [String] recipient name or key value for system integration (optional)
|
25
26
|
# @param response_url [String] callback URL for delivery reports (optional)
|
26
27
|
# @param client_id [String] client reference ID (optional)
|
27
28
|
# @param charset [String] character encoding, defaults to 'UTF8' (optional)
|
28
29
|
# @param options [Hash] additional options (optional)
|
29
30
|
# @return [MitakeSms::Response] response object
|
30
|
-
def send_sms(to:, text:, response_url: nil, client_id: nil, charset: 'UTF8', **options)
|
31
|
+
def send_sms(to:, text:, destname: nil, response_url: nil, client_id: nil, charset: 'UTF8', **options)
|
31
32
|
require 'uri'
|
32
33
|
|
33
34
|
# Create options hash with only non-nil values
|
34
35
|
param_options = {}
|
36
|
+
param_options[:destname] = destname if destname
|
35
37
|
param_options[:response_url] = response_url if response_url
|
36
38
|
param_options[:client_id] = client_id if client_id
|
37
39
|
|
@@ -153,29 +155,42 @@ module MitakeSms
|
|
153
155
|
def send_batch(batch, charset = 'UTF8', options = {})
|
154
156
|
require 'uri'
|
155
157
|
|
156
|
-
#
|
157
|
-
|
158
|
+
# Format each message according to the advanced format
|
159
|
+
# ClientID $$ dstaddr $$ dlvtime $$ vldtime $$ destname $$ response $$ smbody
|
160
|
+
data = batch.map do |msg|
|
161
|
+
# ClientID is required and must be unique
|
162
|
+
# If not provided, generate a unique ID
|
163
|
+
client_id = msg[:client_id]
|
164
|
+
if client_id.nil? || client_id.empty?
|
165
|
+
client_id = generate_unique_client_id
|
166
|
+
end
|
167
|
+
|
158
168
|
to = msg[:to]
|
169
|
+
dlvtime = msg[:dlvtime] || ''
|
170
|
+
vldtime = msg[:vldtime] || ''
|
171
|
+
dest_name = msg[:destname] || ''
|
172
|
+
response_url = msg[:response_url] || ''
|
159
173
|
|
160
|
-
# Replace any newline characters with ASCII code 6 (ACK)
|
161
|
-
# This is required by the Mitake API to represent line breaks
|
174
|
+
# Replace any newline characters in the message text with ASCII code 6 (ACK)
|
175
|
+
# This is required by the Mitake API to represent line breaks within message content
|
162
176
|
processed_text = msg[:text].to_s.gsub("\n", 6.chr)
|
163
177
|
|
164
|
-
|
178
|
+
# Format according to API documentation: ClientID $$ dstaddr $$ dlvtime $$ vldtime $$ destname $$ response $$ smbody
|
179
|
+
[client_id, to, dlvtime, vldtime, dest_name, response_url, processed_text].join('$$')
|
165
180
|
end.join("\n")
|
166
181
|
|
167
|
-
#
|
182
|
+
# Parameters for the request
|
168
183
|
query_params = {
|
169
184
|
username: @config.username,
|
170
185
|
password: @config.password,
|
171
|
-
smbody: smbody,
|
172
186
|
Encoding_PostIn: charset
|
173
187
|
}
|
174
188
|
|
175
|
-
#
|
189
|
+
# According to the API documentation, the data should be in the request body
|
176
190
|
response = @connection.post('SmBulkSend') do |req|
|
177
191
|
req.params = query_params
|
178
|
-
req.body =
|
192
|
+
req.body = data
|
193
|
+
req.headers['Content-Type'] = 'text/plain'
|
179
194
|
end
|
180
195
|
|
181
196
|
handle_response(response)
|
data/lib/mitake_sms/version.rb
CHANGED
data/lib/mitake_sms.rb
CHANGED
@@ -38,16 +38,18 @@ 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 destname [String] recipient name or key value for system integration (optional)
|
41
42
|
# @param response_url [String] callback URL for delivery reports (optional)
|
42
43
|
# @param client_id [String] client reference ID (optional)
|
43
44
|
# @param charset [String] character encoding, defaults to 'UTF8' (optional)
|
44
45
|
# @param options [Hash] additional options (optional)
|
45
46
|
# @return [MitakeSms::Response] response object
|
46
|
-
def send_sms(to:, text:, response_url: nil, client_id: nil, charset: 'UTF8', **options)
|
47
|
+
def send_sms(to:, text:, destname: nil, response_url: nil, client_id: nil, charset: 'UTF8', **options)
|
47
48
|
# Forward all parameters to the client method using named parameters
|
48
49
|
client.send_sms(
|
49
50
|
to: to,
|
50
51
|
text: text,
|
52
|
+
destname: destname,
|
51
53
|
response_url: response_url,
|
52
54
|
client_id: client_id,
|
53
55
|
charset: charset,
|
@@ -98,15 +100,6 @@ module MitakeSms
|
|
98
100
|
client.advanced_batch_send(messages, options)
|
99
101
|
end
|
100
102
|
|
101
|
-
# Send multiple SMS messages in a single request with a limit per request using advanced format
|
102
|
-
# @param messages [Array<Hash>] array of message hashes with advanced options
|
103
|
-
# @param limit [Integer] maximum number of messages per request (default: 500)
|
104
|
-
# @param options [Hash] additional options
|
105
|
-
# @option options [String] :charset character encoding, defaults to 'UTF8'
|
106
103
|
|
107
|
-
# @return [MitakeSms::Response, Array<MitakeSms::Response>] response object or array of response objects if batch was split
|
108
|
-
def advanced_batch_send_with_limit(messages, limit = 500, options = {})
|
109
|
-
client.advanced_batch_send_with_limit(messages, limit, options)
|
110
|
-
end
|
111
104
|
end
|
112
105
|
end
|