TWSMS 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/docs/ChangeLog ADDED
@@ -0,0 +1,19 @@
1
+ ChangeLog:
2
+
3
+ * 0.2.1 / 2007-06-18:
4
+ * NEW: Check vldtime, sdate and edate. Check mobile format.
5
+ * FIX: Some syntax fixed.
6
+
7
+ * 0.2.0 / 2007-06-17:
8
+ * NEW: Query SMS Status has been added.
9
+ * querySMS()
10
+ * setMessageId(msgid)
11
+ * FIX: Some syntax fixed.
12
+
13
+ * 0.1.1 / 2007-06-16:
14
+ * Just fix some syntax:
15
+ * Instance variable: @errors change to class variable: @@errors
16
+ * At chk_val function:
17
+ @options[:mo] = @options[:mo].upcase
18
+ * 0.1.0 / 2007-06-15:
19
+ * Program skeleton.
data/docs/EXAMPLES ADDED
@@ -0,0 +1,31 @@
1
+ = TWSMS examples
2
+
3
+ == Send a SMS Message
4
+ require 'rubygems'
5
+ require 'twsms'
6
+
7
+ sms = SMS.new("username", "password")
8
+ msg = %q|This is a message|
9
+ sms.sendSMS("0987654321", msg)
10
+ sms.sendSMS("0987-654321", msg)
11
+ sms.sendSMS("0987-654-321", msg)
12
+
13
+ == Send a SMS Message and do a query about the message we sent.
14
+
15
+ require 'rubygems'
16
+ require 'twsms'
17
+
18
+ sms = SMS.new("username", "password")
19
+ msg = %q|This is a message|
20
+ sms.sendSMS("0987654321", msg)
21
+ sms.querySMS
22
+
23
+ == Query a SMS Message ( Before this, you must have a message id to query )
24
+
25
+ require 'rubygems'
26
+ require 'twsms'
27
+
28
+ sms = TWSMS.new("username", "password")
29
+ sms.setMessageId("65432")
30
+ sms.querySMS
31
+
data/docs/LICENSE ADDED
@@ -0,0 +1,70 @@
1
+ Apache License
2
+
3
+ Version 2.0, January 2004
4
+
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
16
+
17
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
18
+
19
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
20
+
21
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
22
+
23
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
24
+
25
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
26
+
27
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
28
+
29
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
30
+
31
+ 2. Grant of Copyright License.
32
+
33
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
34
+
35
+ 3. Grant of Patent License.
36
+
37
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
38
+
39
+ 4. Redistribution.
40
+
41
+ You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
42
+
43
+ 1. You must give any other recipients of the Work or Derivative Works a copy of this License; and
44
+ 2. You must cause any modified files to carry prominent notices stating that You changed the files; and
45
+ 3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
46
+ 4. If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
47
+
48
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
49
+
50
+ 5. Submission of Contributions.
51
+
52
+ Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
53
+
54
+ 6. Trademarks.
55
+
56
+ This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
57
+
58
+ 7. Disclaimer of Warranty.
59
+
60
+ Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
61
+
62
+ 8. Limitation of Liability.
63
+
64
+ In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
65
+
66
+ 9. Accepting Warranty or Additional Liability.
67
+
68
+ While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
69
+
70
+ END OF TERMS AND CONDITIONS
File without changes
data/lib/twsms.rb CHANGED
@@ -3,12 +3,12 @@
3
3
  == Information ==
4
4
  === Copyright: Apache 2.0
5
5
  === Author: CFC < zusocfc@gmail.com >
6
- === Prog. Name: TWSMS lib
7
- === Version: 0.2.0
6
+ === Library Name: TWSMS lib
7
+ === Version: 0.2.1
8
8
  === Please read README file to get more information.
9
9
  =end
10
10
 
11
- %w|uri cgi net/http|.each{|r| require r}
11
+ %w|date uri cgi net/http|.each{|r| require r}
12
12
  SEND_URL = "http://api.twsms.com/send_sms.php?"
13
13
  QUERY_URL = "http://api.twsms.com/query_sms.php?"
14
14
 
@@ -69,8 +69,6 @@ class TWSMS
69
69
  -11.to_s.to_sym => "Your account has been blocked",
70
70
  -12.to_s.to_sym => "Your message maybe invalid",
71
71
  }
72
-
73
- @other_values = {}
74
72
  end
75
73
 
76
74
  def sendSMS(mobile, message, opt={})
@@ -79,7 +77,8 @@ class TWSMS
79
77
  @send_options.merge!(opt).each{|k, v| args << k.to_s + "=" + CGI::escape(v.to_s)}
80
78
  url = SEND_URL + "username=" + @uname + "&password=" + @upwd + "&" + args.join("&")
81
79
  self.check_send_val
82
- self.check_send_resp(Net::HTTP.get(URI.parse(url)))
80
+ (raise "dlvtime is invalid";exit) unless self.check_date("dlvtime")
81
+ return self.check_send_resp(Net::HTTP.get(URI.parse(url)))
83
82
  end
84
83
 
85
84
  def querySMS()
@@ -89,39 +88,74 @@ class TWSMS
89
88
  url += "&monumber=" + @query_options[:monumber].to_s
90
89
  url += "&sdate=" + @query_options[:sdate].to_s
91
90
  url += "&edate=" + @query_options[:edate].to_s
92
- self.check_query_resp(Net::HTTP.get(URI.parse(url)))
91
+ (raise "dlvtime is invalid";exit) unless self.check_date("sdate")
92
+ (raise "dlvtime is invalid";exit) unless self.check_date("edate")
93
+ return self.check_query_resp(Net::HTTP.get(URI.parse(url)))
93
94
  end
94
95
 
95
96
  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?
97
+ # @query_options[:msgid] = msgid unless msgid.nil?
98
+ # (puts "You did not give me the message id!!!";exit) if msgid.nil?
99
+ if msgid.nil?
100
+ puts "You did not give me the message id!!!"
101
+ exit
102
+ else
103
+ @query_options[:msgid] = msgid
104
+ end
105
+ return nil
98
106
  end
99
107
 
100
108
  def check_query_resp(resp)
101
109
  resp = resp.split("=")[1].split(",")[0]
110
+ =begin
102
111
  if resp.to_s == "0"
103
112
  puts "==========", "Query succeed! The result: " + @@query_errors[resp.to_s.to_sym]
104
113
  else
105
114
  puts "==========", "Error!! Message: ", @@query_errors[resp.to_s.to_sym]
106
115
  end
116
+ =end
117
+ return @@query_errors[resp.to_s.to_sym]
107
118
  end
108
119
 
109
120
  def check_send_resp(resp)
110
121
  # Before rename, its name is chk_errors
111
122
  resp = resp.split("=")[1].split(",")[0]
112
123
  if @@send_errors.has_key?(resp.to_s.to_sym)
113
- puts "==========", "Error!! Message: ", @@send_errors[resp.to_s.to_sym]
124
+ # puts "==========", "Error!! Message: ", @@send_errors[resp.to_s.to_sym]
125
+ return @@send_errors[resp.to_s.to_sym]
114
126
  else
115
- puts "==========", "Message has been send! Your message id is: " + resp.to_s
127
+ # puts "==========", "Message has been send! Your message id is: " + resp.to_s
116
128
  @query_options[:msgid] = resp.to_s
129
+ return resp.to_s
117
130
  end
118
131
  end
119
132
 
120
- def check_send_val
133
+ def check_send_val()
134
+ @send_options[:type] = "now" unless @send_options[:type] == ("now" || "dlv") # 0.2.1 -- Make sure the type is valid
121
135
  @send_options[:dlvtime] = "" unless @send_options[:type] == "dlv"
122
- @send_options[:wapurl] = "" if @send_options[:type] != ("push" && "upush")
136
+ @send_options[:wapurl] = "" unless @send_options[:type] == ("push" && "upush")
123
137
  @send_options[:mo] = @send_options[:mo].upcase
138
+ @send_options[:mobile].gsub(/-/, "") # 0.2.1 -- Check the mobile format
139
+ return nil
140
+ end
141
+
142
+ def check_date(type="dlvtime")
143
+ # For dlvtime, sdate, edate
144
+ # 0.2.1 -- Make sure the date is valid
145
+ case type
146
+ when "dlvtime"
147
+ d = DateTime.parse(@send_options[:dlvtime])
148
+ vc = Date.valid_civil?(d.year, d.month, d.day)
149
+ vt = Date.valid_time?(d.hour, d.min, d.sec)
150
+ return true if vc == vt
151
+ when "sdate"
152
+ d = DateTime.parse(@query_options[:sdate])
153
+ return true if Date.valid_civil?(d.year, d.month, d.day)
154
+ when "edate"
155
+ d = DateTime.parse(@query_options[:edate])
156
+ return true if Date.valid_civil?(d.year, d.month, d.day)
157
+ end
124
158
  end
125
159
 
126
- protected :check_send_val, :check_send_resp, :check_query_resp
160
+ protected :check_send_val, :check_date, :check_send_resp, :check_query_resp
127
161
  end
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: TWSMS
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
6
+ version: 0.2.1
7
7
  date: 2007-06-18 00:00:00 +08:00
8
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
9
  require_paths:
@@ -30,13 +30,16 @@ authors:
30
30
  - CFC
31
31
  files:
32
32
  - lib/twsms.rb
33
- - README
33
+ - docs/ChangeLog
34
+ - docs/EXAMPLES
35
+ - docs/LICENSE
36
+ - docs/README
34
37
  test_files: []
35
38
 
36
39
  rdoc_options: []
37
40
 
38
41
  extra_rdoc_files:
39
- - README
42
+ - docs/README
40
43
  executables: []
41
44
 
42
45
  extensions: []