Class: TWSMS

Inherits:
Object
  • Object
show all
Defined in:
lib/twsms.rb

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ TWSMS

Returns a new instance of TWSMS.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/twsms.rb', line 16

def initialize(username, password)
  @uname, @upwd = username, password
  # Before renamed, its name is: @send_options
  @send_options = {
    :type => "now",
    :popup => "",
    :mo => "Y".upcase,
    :vldtime => "86400",
    :modate => "",
    :dlvtime => "",
    :wapurl => "",
    :encoding => "big5"
  }
  
  @query_options = {
    :type => "now",
    :msgid => "",
    :monumber => "",
    :sdate => "",
    :edate => ""
  }
  
  # Before renamed, its name is: @@errors
  @@send_errors = {
    -1.to_s.to_sym => "Send failed",
    -2.to_s.to_sym => "Username or password is invalid",
    -3.to_s.to_sym => "Popup tag error",
    -4.to_s.to_sym => "Mo tag error",
    -5.to_s.to_sym => "Encoding tag error",
    -6.to_s.to_sym => "Mobile tag error",
    -7.to_s.to_sym => "Message tag error",
    -8.to_s.to_sym => "vldtime tag error",
    -9.to_s.to_sym => "dlvtime tag error",
    -10.to_s.to_sym => "You have no point",
    -11.to_s.to_sym => "Your account has been blocked",
    -12.to_s.to_sym => "Type tag error",
    -13.to_s.to_sym => "You can't send SMS message by dlvtime tag if you use wap push",
    -14.to_s.to_sym => "Source IP has no permission",
    -99.to_s.to_sym => "System error!! Please contact the administrator, thanks!!"
  }
  
  @@query_errors = {
    0.to_s.to_sym => "Message already been sent or reserving message has been deleted",
    -1.to_s.to_sym => "Could not find the message id or ",
    -2.to_s.to_sym => "Username or password is invalid",
    -3.to_s.to_sym => "The reserving message does send yet",
    -4.to_s.to_sym => "Type tag error",
    -5.to_s.to_sym => "The target mobile did not callback",
    -6.to_s.to_sym => "Failed on sent message to the operator",
    -7.to_s.to_sym => "No short code",
    -8.to_s.to_sym => "No return message",
    -9.to_s.to_sym => "sdate or edate setting error",
    -10.to_s.to_sym => "No record of ",
    -11.to_s.to_sym => "Your account has been blocked",
    -12.to_s.to_sym => "Your message maybe invalid",
  }
end

Instance Method Details

#querySMSObject



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/twsms.rb', line 84

def querySMS()
  url ||= QUERY_URL + "username=" + @uname + "&password=" + @upwd
  url += "&type=" + @query_options[:type].to_s
  url += "&msgid=" + @query_options[:msgid].to_s
  url += "&monumber=" + @query_options[:monumber].to_s
  url += "&sdate=" + @query_options[:sdate].to_s
  url += "&edate=" + @query_options[:edate].to_s
  (raise "dlvtime is invalid";exit) unless self.check_date("sdate")
  (raise "dlvtime is invalid";exit) unless self.check_date("edate")
  return self.check_query_resp(Net::HTTP.get(URI.parse(url)))
end

#sendSMS(mobile, message, opt = {}) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/twsms.rb', line 74

def sendSMS(mobile, message, opt={})
  args = []
  @send_options[:mobile], @send_options[:message] = mobile, message
  @send_options.merge!(opt).each{|k, v| args << k.to_s + "=" + CGI::escape(v.to_s)}
  url = SEND_URL + "username=" + @uname + "&password=" + @upwd + "&" + args.join("&")
  self.check_send_val
  (raise "dlvtime is invalid";exit) unless self.check_date("dlvtime")
  return self.check_send_resp(Net::HTTP.get(URI.parse(url)))
end

#setMessageId(msgid) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/twsms.rb', line 96

def setMessageId(msgid)
  # @query_options[:msgid] = msgid unless msgid.nil?
  # (puts "You did not give me the message id!!!";exit) if msgid.nil?
  if msgid.nil?
    puts "You did not give me the message id!!!"
    exit
  else
    @query_options[:msgid] = msgid
  end
  return nil
end