kotsms 0.1.2 → 0.2.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/lib/kotsms.rb +26 -12
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5a72facf91e03092bff1cce0699d629717322d4
|
4
|
+
data.tar.gz: a3140f1fa8f454d31b808b917f4fc658c0b28d8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e65bb044376825c6b14f62c5b9875eea8fa6001c37870a2992cec5de9bfd5a32d8231a3999da53566706e73cd16c03809b831d6d20e1c6177886cc5fbbfc4aa
|
7
|
+
data.tar.gz: '094f6680506e44d5a65a2bd469b0564a9d18ff364e4b929866728803b82a331ada4641377888ad527f54001b9d130a3ce9a2d5e767a4d4d5c9a68fbe1f19e862'
|
data/lib/kotsms.rb
CHANGED
@@ -3,10 +3,11 @@ require "uri"
|
|
3
3
|
require "iconv"
|
4
4
|
|
5
5
|
class Kotsms
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
API_HOST = "api.kotsms.com.tw"
|
7
|
+
SMS_ENDPOINT = "/kotsmsapi-1.php"
|
8
|
+
BULK_SMS_ENDPOINT = "/kotsmsapi-2.php"
|
9
|
+
BALANCE_ENDPOOINT = "/memberpoint.php"
|
10
|
+
STATUS_ENDPOOINT = "/msgstatus.php"
|
10
11
|
|
11
12
|
def initialize(username, password)
|
12
13
|
login(username, password)
|
@@ -18,8 +19,18 @@ class Kotsms
|
|
18
19
|
true
|
19
20
|
end
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
# recipient (string) - sms recipient in general format; e.g. '+886912345678'
|
23
|
+
# message (string) - message content
|
24
|
+
# options (hash) - optional config
|
25
|
+
# options.ignore_cert (boolean) - Ignore SSL certificate or not
|
26
|
+
# options.insecure (boolean) - Use plain HTTP or HTTPS
|
27
|
+
# options.mode (string) - delivery mode
|
28
|
+
# 'bit' - instant delivery (default)
|
29
|
+
# 'bulk' - bulk delivery
|
30
|
+
def deliver(recipient, message, options={})
|
31
|
+
protocol = options[:insecure] ? "http" : "https"
|
32
|
+
uri = URI.parse "#{protocol}://#{API_HOST}"
|
33
|
+
uri.path = case (options[:mode].to_sym rescue nil)
|
23
34
|
when nil, :bit
|
24
35
|
SMS_ENDPOINT
|
25
36
|
when :bulk
|
@@ -27,25 +38,28 @@ class Kotsms
|
|
27
38
|
else
|
28
39
|
raise StandardError.new "Bad delivering mode!"
|
29
40
|
end
|
30
|
-
uri = URI.parse(endpoint)
|
31
41
|
|
32
42
|
uri.query = URI.encode_www_form({
|
33
43
|
username: @username,
|
34
44
|
password: @password,
|
35
|
-
dstaddr:
|
36
|
-
smbody: Iconv.new("big5", "utf-8").iconv(
|
45
|
+
dstaddr: recipient,
|
46
|
+
smbody: Iconv.new("big5", "utf-8").iconv(message),
|
37
47
|
dlvtime: (options[:dlvtime] rescue 0),
|
38
48
|
vldtime: (options[:vldtime] rescue nil),
|
39
49
|
response: (options[:response] rescue nil)
|
40
50
|
})
|
41
51
|
|
42
|
-
response = Net::HTTP.
|
52
|
+
response = Net::HTTP.start(uri.host, use_ssl: uri.scheme == 'https') do |http|
|
53
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if options[:ignore_cert]
|
54
|
+
req = Net::HTTP::Get.new uri
|
55
|
+
http.request(req)
|
56
|
+
end
|
43
57
|
|
44
58
|
parse_response(response.body)["kmsgid"].to_i
|
45
59
|
end
|
46
60
|
|
47
|
-
def deliver_bulk(
|
48
|
-
deliver(
|
61
|
+
def deliver_bulk(recipient, message, options={})
|
62
|
+
deliver(recipient, message, options.merge(mode: :bulk))
|
49
63
|
end
|
50
64
|
|
51
65
|
def balance
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kotsms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CrBoy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: iconv
|
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
51
|
version: '0'
|
52
52
|
requirements: []
|
53
53
|
rubyforge_project:
|
54
|
-
rubygems_version: 2.
|
54
|
+
rubygems_version: 2.6.11
|
55
55
|
signing_key:
|
56
56
|
specification_version: 4
|
57
57
|
summary: API wrapper for SMS King (www.kotsms.com.tw)
|