TWSMS 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +29 -0
- data/lib/twsms.rb +127 -0
- metadata +47 -0
data/README
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
= TWSMS
|
2
|
+
|
3
|
+
http://rubyforge.org/projects/smsender/
|
4
|
+
|
5
|
+
== Description
|
6
|
+
|
7
|
+
The TWSMS library is used for send SMS messages.
|
8
|
+
But, before you use, you must have an account of TWSMS.
|
9
|
+
The link of TWSMS: http://www.twsms.com
|
10
|
+
|
11
|
+
== Dependencies
|
12
|
+
|
13
|
+
* ruby 1.8.2
|
14
|
+
* cgi
|
15
|
+
* net/http
|
16
|
+
|
17
|
+
== Examples
|
18
|
+
|
19
|
+
Please read the file named: Example
|
20
|
+
|
21
|
+
== Authors
|
22
|
+
|
23
|
+
Copyright (c) 2007 by Hsu Shih Chung (zusocfc@gmail.com)
|
24
|
+
|
25
|
+
This library coded with Ruby!!
|
26
|
+
|
27
|
+
== License
|
28
|
+
|
29
|
+
This library is distributed under the Apache 2.0. Please read the LICENSE file.
|
data/lib/twsms.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
# Rename to TWSMSender
|
2
|
+
=begin
|
3
|
+
== Information ==
|
4
|
+
=== Copyright: Apache 2.0
|
5
|
+
=== Author: CFC < zusocfc@gmail.com >
|
6
|
+
=== Prog. Name: TWSMS lib
|
7
|
+
=== Version: 0.2.0
|
8
|
+
=== Please read README file to get more information.
|
9
|
+
=end
|
10
|
+
|
11
|
+
%w|uri cgi net/http|.each{|r| require r}
|
12
|
+
SEND_URL = "http://api.twsms.com/send_sms.php?"
|
13
|
+
QUERY_URL = "http://api.twsms.com/query_sms.php?"
|
14
|
+
|
15
|
+
class TWSMS
|
16
|
+
def initialize(username, password)
|
17
|
+
@uname, @upwd = username, password
|
18
|
+
# Before renamed, its name is: @send_options
|
19
|
+
@send_options = {
|
20
|
+
:type => "now",
|
21
|
+
:popup => "",
|
22
|
+
:mo => "Y".upcase,
|
23
|
+
:vldtime => "86400",
|
24
|
+
:modate => "",
|
25
|
+
:dlvtime => "",
|
26
|
+
:wapurl => "",
|
27
|
+
:encoding => "big5"
|
28
|
+
}
|
29
|
+
|
30
|
+
@query_options = {
|
31
|
+
:type => "now",
|
32
|
+
:msgid => "",
|
33
|
+
:monumber => "",
|
34
|
+
:sdate => "",
|
35
|
+
:edate => ""
|
36
|
+
}
|
37
|
+
|
38
|
+
# Before renamed, its name is: @@errors
|
39
|
+
@@send_errors = {
|
40
|
+
-1.to_s.to_sym => "Send failed",
|
41
|
+
-2.to_s.to_sym => "Username or password is invalid",
|
42
|
+
-3.to_s.to_sym => "Popup tag error",
|
43
|
+
-4.to_s.to_sym => "Mo tag error",
|
44
|
+
-5.to_s.to_sym => "Encoding tag error",
|
45
|
+
-6.to_s.to_sym => "Mobile tag error",
|
46
|
+
-7.to_s.to_sym => "Message tag error",
|
47
|
+
-8.to_s.to_sym => "vldtime tag error",
|
48
|
+
-9.to_s.to_sym => "dlvtime tag error",
|
49
|
+
-10.to_s.to_sym => "You have no point",
|
50
|
+
-11.to_s.to_sym => "Your account has been blocked",
|
51
|
+
-12.to_s.to_sym => "Type tag error",
|
52
|
+
-13.to_s.to_sym => "You can't send SMS message by dlvtime tag if you use wap push",
|
53
|
+
-14.to_s.to_sym => "Source IP has no permission",
|
54
|
+
-99.to_s.to_sym => "System error!! Please contact the administrator, thanks!!"
|
55
|
+
}
|
56
|
+
|
57
|
+
@@query_errors = {
|
58
|
+
0.to_s.to_sym => "Message already been sent or reserving message has been deleted",
|
59
|
+
-1.to_s.to_sym => "Could not find the message id or ",
|
60
|
+
-2.to_s.to_sym => "Username or password is invalid",
|
61
|
+
-3.to_s.to_sym => "The reserving message does send yet",
|
62
|
+
-4.to_s.to_sym => "Type tag error",
|
63
|
+
-5.to_s.to_sym => "The target mobile did not callback",
|
64
|
+
-6.to_s.to_sym => "Failed on sent message to the operator",
|
65
|
+
-7.to_s.to_sym => "No short code",
|
66
|
+
-8.to_s.to_sym => "No return message",
|
67
|
+
-9.to_s.to_sym => "sdate or edate setting error",
|
68
|
+
-10.to_s.to_sym => "No record of ",
|
69
|
+
-11.to_s.to_sym => "Your account has been blocked",
|
70
|
+
-12.to_s.to_sym => "Your message maybe invalid",
|
71
|
+
}
|
72
|
+
|
73
|
+
@other_values = {}
|
74
|
+
end
|
75
|
+
|
76
|
+
def sendSMS(mobile, message, opt={})
|
77
|
+
args = []
|
78
|
+
@send_options[:mobile], @send_options[:message] = mobile, message
|
79
|
+
@send_options.merge!(opt).each{|k, v| args << k.to_s + "=" + CGI::escape(v.to_s)}
|
80
|
+
url = SEND_URL + "username=" + @uname + "&password=" + @upwd + "&" + args.join("&")
|
81
|
+
self.check_send_val
|
82
|
+
self.check_send_resp(Net::HTTP.get(URI.parse(url)))
|
83
|
+
end
|
84
|
+
|
85
|
+
def querySMS()
|
86
|
+
url ||= QUERY_URL + "username=" + @uname + "&password=" + @upwd
|
87
|
+
url += "&type=" + @query_options[:type].to_s
|
88
|
+
url += "&msgid=" + @query_options[:msgid].to_s
|
89
|
+
url += "&monumber=" + @query_options[:monumber].to_s
|
90
|
+
url += "&sdate=" + @query_options[:sdate].to_s
|
91
|
+
url += "&edate=" + @query_options[:edate].to_s
|
92
|
+
self.check_query_resp(Net::HTTP.get(URI.parse(url)))
|
93
|
+
end
|
94
|
+
|
95
|
+
def setMessageId(msgid)
|
96
|
+
@query_options[:msgid] = msgid unless msgid.nil?
|
97
|
+
(puts "You did not give me the message id!!!";exit) if msgid.nil?
|
98
|
+
end
|
99
|
+
|
100
|
+
def check_query_resp(resp)
|
101
|
+
resp = resp.split("=")[1].split(",")[0]
|
102
|
+
if resp.to_s == "0"
|
103
|
+
puts "==========", "Query succeed! The result: " + @@query_errors[resp.to_s.to_sym]
|
104
|
+
else
|
105
|
+
puts "==========", "Error!! Message: ", @@query_errors[resp.to_s.to_sym]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def check_send_resp(resp)
|
110
|
+
# Before rename, its name is chk_errors
|
111
|
+
resp = resp.split("=")[1].split(",")[0]
|
112
|
+
if @@send_errors.has_key?(resp.to_s.to_sym)
|
113
|
+
puts "==========", "Error!! Message: ", @@send_errors[resp.to_s.to_sym]
|
114
|
+
else
|
115
|
+
puts "==========", "Message has been send! Your message id is: " + resp.to_s
|
116
|
+
@query_options[:msgid] = resp.to_s
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def check_send_val
|
121
|
+
@send_options[:dlvtime] = "" unless @send_options[:type] == "dlv"
|
122
|
+
@send_options[:wapurl] = "" if @send_options[:type] != ("push" && "upush")
|
123
|
+
@send_options[:mo] = @send_options[:mo].upcase
|
124
|
+
end
|
125
|
+
|
126
|
+
protected :check_send_val, :check_send_resp, :check_query_resp
|
127
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.2
|
3
|
+
specification_version: 1
|
4
|
+
name: TWSMS
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.2.0
|
7
|
+
date: 2007-06-18 00:00:00 +08:00
|
8
|
+
summary: "\xB4\xA3\xA8\xD1\xA4@\xAD\xD3\xA4\xE2\xBE\xF7\xC2\xB2\xB0T\xB5o\xB0e\xAA\xBA\xA8\xE7\xA6\xA1\xAEw(TWSMS\xAA\xA9\xA5\xBB)"
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: zusocfc@gmail.com
|
12
|
+
homepage: http://zusocfc.blogspot.com
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- CFC
|
31
|
+
files:
|
32
|
+
- lib/twsms.rb
|
33
|
+
- README
|
34
|
+
test_files: []
|
35
|
+
|
36
|
+
rdoc_options: []
|
37
|
+
|
38
|
+
extra_rdoc_files:
|
39
|
+
- README
|
40
|
+
executables: []
|
41
|
+
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
requirements: []
|
45
|
+
|
46
|
+
dependencies: []
|
47
|
+
|