jeffrafter-win32-sms 0.2.0 → 0.3.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.
- data/VERSION.yml +1 -1
- data/lib/win32/sms.rb +26 -11
- metadata +2 -2
data/VERSION.yml
CHANGED
data/lib/win32/sms.rb
CHANGED
@@ -18,7 +18,7 @@ module Win32
|
|
18
18
|
|
19
19
|
class Sms
|
20
20
|
|
21
|
-
attr_accessor :messages
|
21
|
+
attr_accessor :messages, :ignore_unknown_errors
|
22
22
|
|
23
23
|
def initialize(port)
|
24
24
|
@read_buffer = ""
|
@@ -103,18 +103,18 @@ module Win32
|
|
103
103
|
end
|
104
104
|
|
105
105
|
def sms(number, text)
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
106
|
+
# initiate the sms, and wait for either the text prompt or an error
|
107
|
+
command "AT+CMGS=\"#{number}\"", ["\r\n", "> "]
|
108
|
+
begin
|
109
|
+
# send the sms, and wait until it is accepted or rejected
|
110
110
|
text = encode(text)
|
111
|
-
|
112
|
-
|
111
|
+
write "#{text}#{26.chr}"
|
112
|
+
response = wait
|
113
113
|
rescue
|
114
114
|
# Escape entry mode
|
115
|
-
|
116
|
-
|
117
|
-
|
115
|
+
write 27.chr
|
116
|
+
raise
|
117
|
+
end
|
118
118
|
response
|
119
119
|
end
|
120
120
|
|
@@ -129,6 +129,19 @@ module Win32
|
|
129
129
|
@messages = []
|
130
130
|
fetch_and_delete_stored_messages
|
131
131
|
end
|
132
|
+
|
133
|
+
def pin?
|
134
|
+
not command("AT+CPIN?").include?("+CPIN: READY")
|
135
|
+
end
|
136
|
+
|
137
|
+
def pin=(pin)
|
138
|
+
return unless pin?
|
139
|
+
command "AT+CPIN=#{pin}"
|
140
|
+
end
|
141
|
+
|
142
|
+
def signal?
|
143
|
+
query("AT+CSQ")
|
144
|
+
end
|
132
145
|
|
133
146
|
protected
|
134
147
|
|
@@ -142,6 +155,8 @@ module Win32
|
|
142
155
|
|
143
156
|
# Check for formatted error
|
144
157
|
if m = buffer.match(/^\+(CM[ES]) ERROR: (\d+)$/)
|
158
|
+
number = m.captures[1].to_i rescue 0
|
159
|
+
return response if number == 500 && @ignore_unknown_errors
|
145
160
|
raise SmsError.new(buffer)
|
146
161
|
end
|
147
162
|
|
@@ -151,7 +166,7 @@ module Win32
|
|
151
166
|
end
|
152
167
|
|
153
168
|
# Check for 'OK' or prompt
|
154
|
-
if (buffer == "OK") or (buffer == ">")
|
169
|
+
if (buffer == "OK") or (buffer == ">") or (buffer =~ /^\+CPIN: (.+)$/
|
155
170
|
return response
|
156
171
|
end
|
157
172
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jeffrafter-win32-sms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Rafter
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-27 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|