twsms2 1.0.1 → 1.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 +4 -4
- data/.travis.yml +1 -0
- data/README.md +54 -19
- data/lib/twsms2/formatter.rb +12 -0
- data/lib/twsms2/version.rb +1 -1
- data/lib/twsms2.rb +3 -2
- data/twsms2.gemspec +3 -2
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 548eb03c93dd04ba44a85593a17e14a6d77c85da
|
4
|
+
data.tar.gz: 0eb4402e4e51a566c8476b88d84a43a9c5b40993
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38bd3975a7334dddb430b45269e3f6204ebfd4b6407fe669486b13927c467585342f125be252f41886dae0f06e036d0745d7acfedc03ca03d6a323b682583bd6
|
7
|
+
data.tar.gz: f9b5043d50a38004a9d8f8948202dc7054f0b0e8c12a8477d45fae48c94e954c09b1a2660c356a0e16250cac265db0da19939fd829be5327b5afcf9d12befb6c
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,13 +1,18 @@
|
|
1
|
-
Twsms2 ( 2016 台灣簡訊 TwSMS API
|
2
|
-
|
1
|
+
Twsms2 ( 2016 新版 台灣簡訊 TwSMS API Ruby 版套件 )
|
2
|
+
=================================================
|
3
3
|
|
4
4
|
[](https://badge.fury.io/rb/twsms2) [](https://travis-ci.org/guanting112/twsms2)
|
5
5
|
|
6
6
|

|
7
7
|
|
8
|
-
此為針對 [台灣簡訊][twsms_homepage] TwSMS API
|
8
|
+
此為針對 [台灣簡訊][twsms_homepage] TwSMS API 開發的專屬套件
|
9
9
|
|
10
|
-
|
10
|
+
您可以透過該套件來實作台灣簡訊的一般、預約簡訊發送 與 簡訊餘額查詢 的程式
|
11
|
+
|
12
|
+
適用於
|
13
|
+
--------
|
14
|
+
|
15
|
+
Ruby 2 以上的版本,也可在 Ruby On Rails 專案引入
|
11
16
|
|
12
17
|
安裝方式
|
13
18
|
--------
|
@@ -15,7 +20,7 @@ Twsms2 ( 2016 台灣簡訊 TwSMS API 套件 )
|
|
15
20
|
請在您的 Ruby 或 Rails 專案裡的 Gemfile 加入以下指令
|
16
21
|
|
17
22
|
```ruby
|
18
|
-
gem 'twsms2', '~> 1.
|
23
|
+
gem 'twsms2', '~> 1.1.0'
|
19
24
|
```
|
20
25
|
|
21
26
|
然後執行 bundle install 更新套件組
|
@@ -37,7 +42,7 @@ gem 'twsms2', '~> 1.0.0'
|
|
37
42
|
require 'twsms2'
|
38
43
|
|
39
44
|
# Twsms2 是走 https 的方式進行系統操作
|
40
|
-
sms_client = Twsms2::Client.new(username: '
|
45
|
+
sms_client = Twsms2::Client.new(username: '會員帳號', password: '會員密碼', agent: "Mozilla/5.0 (可自訂 user-agent)")
|
41
46
|
```
|
42
47
|
|
43
48
|
使用範例
|
@@ -55,41 +60,69 @@ sms_client.account_is_available
|
|
55
60
|
|
56
61
|
### 發送簡訊
|
57
62
|
|
58
|
-
|
63
|
+
#### 一般使用
|
59
64
|
|
60
|
-
|
65
|
+
手機號碼格式 0911222333 ( 台灣手機 )、886911222333 ( 國碼 + 手機號碼 )
|
66
|
+
|
67
|
+
根據台灣簡訊說明,台灣門號每則扣 1 通,國際門號每則扣 3 通
|
61
68
|
|
62
69
|
```ruby
|
63
|
-
sms_client.send_message to: '手機號碼', content: "
|
70
|
+
sms_client.send_message to: '手機號碼', content: "簡訊內容.."
|
64
71
|
```
|
65
72
|
|
66
|
-
|
73
|
+
#### 預約發送
|
74
|
+
|
75
|
+
若要使用預約發送,可以指定 at 參數給 send_message 方法
|
76
|
+
|
77
|
+
同時程式會自動轉換時區 至 台灣簡訊 適用的時區 ( +08:00 )
|
67
78
|
|
68
79
|
```ruby
|
69
|
-
|
80
|
+
# 純 Ruby 請用加秒數的方式
|
81
|
+
sms_client.send_message to: '手機號碼', content: "預約簡訊測試: #{Time.now}", at: Time.now + 120
|
82
|
+
|
83
|
+
# 在 Ruby On Rails 專案則可以用 Rails 專用的方法
|
84
|
+
sms_client.send_message to: '手機號碼', content: "預約簡訊測試: #{Time.now}", at: Time.now + 2.days
|
70
85
|
```
|
71
86
|
|
72
|
-
|
87
|
+
#### 強制直接顯示簡訊內容
|
73
88
|
|
74
|
-
|
89
|
+
可以加入 popup 參數,讓簡訊在收訊人的手機裝置直接顯示在上面 ( 可能不會被手機儲存 )
|
75
90
|
|
76
91
|
```ruby
|
77
|
-
sms_client.send_message to: '手機號碼', content: "
|
92
|
+
sms_client.send_message to: '手機號碼', content: "簡訊內容..", popup: true
|
78
93
|
```
|
79
94
|
|
80
|
-
|
95
|
+
#### 關閉長簡訊支援
|
96
|
+
|
97
|
+
一般發送簡訊時,預設為長簡訊發送
|
98
|
+
|
99
|
+
因此,若超 SMS 短信字元長度,將會以第二封起開始計算
|
100
|
+
|
101
|
+
加入 long 參數,若指定為 false 則不會使用長簡訊格式
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
sms_client.send_message to: '手機號碼', content: "簡訊內容..", long: false
|
105
|
+
```
|
81
106
|
|
82
107
|
### 發送簡訊 的 回傳結果
|
83
108
|
|
109
|
+
#### 發送成功
|
110
|
+
|
84
111
|
當你執行完成後,send_message 方法會回傳一組 hash 型態的結果
|
85
112
|
|
86
|
-
只要 access_success 的值為 true
|
113
|
+
只要 access_success 的值為 true 就一定代表發送成功
|
114
|
+
|
115
|
+
系統會另外回傳一組 message_id 用來讓你追蹤簡訊
|
87
116
|
|
88
117
|
```ruby
|
89
118
|
{:access_success=>true, :message_id=>"217620029", :error=>nil}
|
90
119
|
```
|
91
120
|
|
92
|
-
|
121
|
+
#### 發生錯誤時
|
122
|
+
|
123
|
+
若 access_success 為 false 則表示過程有出現錯誤
|
124
|
+
|
125
|
+
以下範例為帳號密碼的錯誤,error 參數則是台灣簡訊的 error code
|
93
126
|
|
94
127
|
error code 的部分,請以 台灣簡訊 API 文件的定義為主,本套件不處理相關結果
|
95
128
|
|
@@ -107,10 +140,10 @@ error code 的部分,請以 台灣簡訊 API 文件的定義為主,本套件
|
|
107
140
|
sms_client.get_balance
|
108
141
|
```
|
109
142
|
|
110
|
-
----
|
111
|
-
|
112
143
|
### 查詢簡訊餘額 的 回傳結果
|
113
144
|
|
145
|
+
#### 得到簡訊餘額
|
146
|
+
|
114
147
|
當你執行完成後,get_balance 方法會回傳一組 hash 型態的結果
|
115
148
|
|
116
149
|
只要 access_success 的值為 true 就一定代表系統有成功取得資料
|
@@ -122,6 +155,8 @@ message_quota 則是簡訊餘額,代表你還剩幾封可以用,若為 0 就
|
|
122
155
|
{:access_success=>true, :message_quota=>77, :error=>nil}
|
123
156
|
```
|
124
157
|
|
158
|
+
#### 發生錯誤
|
159
|
+
|
125
160
|
若 access_success 為 false 則表示過程有出現錯誤,同時 message_quota 會為 0
|
126
161
|
|
127
162
|
```ruby
|
data/lib/twsms2/formatter.rb
CHANGED
@@ -5,6 +5,18 @@ module Twsms2
|
|
5
5
|
match_data.nil? ? nil : match_data[1]
|
6
6
|
end
|
7
7
|
|
8
|
+
def format_time_string(time)
|
9
|
+
return nil if time.nil?
|
10
|
+
new_time = to_asia_taipei_timezone(time)
|
11
|
+
new_time.strftime('%Y%m%d%H%M')
|
12
|
+
end
|
13
|
+
|
14
|
+
def to_asia_taipei_timezone(time)
|
15
|
+
utc_time = time.utc? ? time.dup : time.dup.utc
|
16
|
+
asia_taipei_time = utc_time.getlocal('+08:00')
|
17
|
+
asia_taipei_time
|
18
|
+
end
|
19
|
+
|
8
20
|
def format_send_message_info(original_info)
|
9
21
|
new_info = {
|
10
22
|
access_success: false,
|
data/lib/twsms2/version.rb
CHANGED
data/lib/twsms2.rb
CHANGED
@@ -9,7 +9,7 @@ module Twsms2
|
|
9
9
|
include Twsms2::Formatter
|
10
10
|
|
11
11
|
def initialize(options={})
|
12
|
-
@user_agent = "twsms2/#{VERSION}"
|
12
|
+
@user_agent = options.fetch(:agent) { "twsms2/#{VERSION}" }
|
13
13
|
@api_host = options.fetch(:host) { 'api.twsms.com' }
|
14
14
|
@username = options.fetch(:username) { ENV.fetch('TWSMS_USERNAME') }
|
15
15
|
@password = options.fetch(:password) { ENV.fetch('TWSMS_PASSWORD') }
|
@@ -24,10 +24,11 @@ module Twsms2
|
|
24
24
|
def send_message(options={})
|
25
25
|
options[:to] ||= nil
|
26
26
|
options[:content] ||= nil
|
27
|
+
options[:at] = format_time_string(options[:at])
|
27
28
|
options[:long] = options[:long] || options[:long].nil? ? :Y : :N
|
28
29
|
options[:popup] = options[:popup] ? :Y : :N
|
29
30
|
|
30
|
-
response = get(@api_host, '/smsSend.php', popup: options[:popup], mo: :N, longsms: options[:long], mobile: options[:to], message: options[:content], drurl: '')
|
31
|
+
response = get(@api_host, '/smsSend.php', popup: options[:popup], mo: :N, longsms: options[:long], mobile: options[:to], message: options[:content], drurl: '', sendtime: options[:at])
|
31
32
|
|
32
33
|
format_send_message_info(response)
|
33
34
|
end
|
data/twsms2.gemspec
CHANGED
@@ -10,9 +10,10 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["cgt886@gmail.com"]
|
11
11
|
spec.license = "MIT"
|
12
12
|
spec.platform = Gem::Platform::RUBY
|
13
|
-
spec.summary = %q{2016 台灣簡訊 TwSMS API (
|
14
|
-
spec.description = %q{2016 台灣簡訊 TwSMS API (
|
13
|
+
spec.summary = %q{2016 新版 台灣簡訊 TwSMS API ( 純 Ruby / Rails 專案適用 )}
|
14
|
+
spec.description = %q{2016 新版 台灣簡訊 TwSMS API ( 純 Ruby / Rails 專案適用 )}
|
15
15
|
spec.homepage = "https://github.com/guanting112/twsms2"
|
16
|
+
spec.required_ruby_version = '~> 2'
|
16
17
|
|
17
18
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
19
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twsms2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guanting Chen
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '5.0'
|
55
|
-
description: 2016 台灣簡訊 TwSMS API (
|
55
|
+
description: 2016 新版 台灣簡訊 TwSMS API ( 純 Ruby / Rails 專案適用 )
|
56
56
|
email:
|
57
57
|
- cgt886@gmail.com
|
58
58
|
executables: []
|
@@ -84,9 +84,9 @@ require_paths:
|
|
84
84
|
- lib
|
85
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '2'
|
90
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
91
|
requirements:
|
92
92
|
- - ">="
|
@@ -94,8 +94,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.6.4
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
|
-
summary: 2016 台灣簡訊 TwSMS API (
|
100
|
+
summary: 2016 新版 台灣簡訊 TwSMS API ( 純 Ruby / Rails 專案適用 )
|
101
101
|
test_files: []
|