Ruby4Skype 0.2.2 → 0.2.3
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/lib/skypeapi/application.rb +12 -7
- data/lib/skypeapi/call.rb +60 -45
- data/lib/skypeapi/chat.rb +38 -37
- data/lib/skypeapi/chatmember.rb +2 -2
- data/lib/skypeapi/chatmessage.rb +17 -11
- data/lib/skypeapi/event.rb +7 -3
- data/lib/skypeapi/group.rb +8 -8
- data/lib/skypeapi/menuitem.rb +15 -9
- data/lib/skypeapi/message.rb +10 -10
- data/lib/skypeapi/object.rb +10 -9
- data/lib/skypeapi/os/etc.rb +132 -0
- data/lib/skypeapi/os/linux.rb +110 -0
- data/lib/skypeapi/os/mac.rb +10 -0
- data/lib/skypeapi/os/timer.rb +108 -0
- data/lib/skypeapi/os/windows.rb +369 -0
- data/lib/skypeapi/profile.rb +35 -27
- data/lib/skypeapi/sharefunctions.rb +38 -19
- data/lib/skypeapi/sms.rb +8 -8
- data/lib/skypeapi/user.rb +18 -19
- data/lib/skypeapi/version.rb +6 -2
- data/lib/skypeapi/voicemail.rb +10 -10
- data/lib/skypeapi.rb +66 -57
- metadata +47 -35
- data/lib/skypeapi/os.rb +0 -439
@@ -0,0 +1,369 @@
|
|
1
|
+
require 'swin'
|
2
|
+
require 'Win32API'
|
3
|
+
|
4
|
+
module SkypeAPI
|
5
|
+
module OS
|
6
|
+
class Windows < Abstruct
|
7
|
+
require 'skypeapi/os/timer'
|
8
|
+
|
9
|
+
WAIT_CMD_LIMIT = 10.0 #sec
|
10
|
+
PING_CYCLE = 5.0 #sec
|
11
|
+
PING_LIMIT = 3.0 # < PING_CYCLE
|
12
|
+
SLEEP_INTERVAL = 0.001
|
13
|
+
|
14
|
+
HWND_BROADCAST = 0xFFFF
|
15
|
+
WM_COPYDATA = 0x004A
|
16
|
+
WM_USER = 0x0400
|
17
|
+
WM_USER_MSG = WM_USER + 1
|
18
|
+
SKYPECONTROLAPI_ATTACH_SUCCESS=0
|
19
|
+
SKYPECONTROLAPI_ATTACH_PENDING_AUTHORIZATION=1
|
20
|
+
SKYPECONTROLAPI_ATTACH_REFUSED=2
|
21
|
+
SKYPECONTROLAPI_ATTACH_NOT_AVAILABLE=3
|
22
|
+
SKYPECONTROLAPI_ATTACH_API_AVAILABLE=0x8001
|
23
|
+
|
24
|
+
RegisterWindowMessage = Win32API.new('user32','RegisterWindowMessageA', 'P', 'L')
|
25
|
+
SendMessage = Win32API.new("user32", "SendMessageA", ['L']*4, 'L')
|
26
|
+
PostMessage = Win32API.new("user32", "PostMessageA", 'LLLP', 'L')
|
27
|
+
|
28
|
+
def initialize
|
29
|
+
@send_count = 0
|
30
|
+
@queue = Array.new
|
31
|
+
@callback = Hash.new
|
32
|
+
@notify = Hash.new
|
33
|
+
@event = Hash.new do |h,k|
|
34
|
+
h[k] = Array.new
|
35
|
+
end
|
36
|
+
@attached = false
|
37
|
+
@first_attached = true
|
38
|
+
@raise_when_detached = false
|
39
|
+
|
40
|
+
@invoke_mutex = Mutex.new
|
41
|
+
@invoke_block_mutex = Mutex.new
|
42
|
+
|
43
|
+
add_event :available do
|
44
|
+
SkypeAPI.attach
|
45
|
+
end
|
46
|
+
|
47
|
+
Timer.interval PING_CYCLE do
|
48
|
+
invoke_callback('PING'){} if @attached
|
49
|
+
end
|
50
|
+
|
51
|
+
@reattach_mutex = Mutex.new
|
52
|
+
|
53
|
+
@wmBuffer = Hash.new
|
54
|
+
@wmHandler = SWin::LWFactory.new(SWin::Application.hInstance).newwindow nil
|
55
|
+
@wmHandler.create
|
56
|
+
@wmHandler.addEvent(WM_COPYDATA)
|
57
|
+
@wmHandler.addEvent(WM_USER_MSG)
|
58
|
+
@wmHandler.instance_variable_set :@skypeAPI,self
|
59
|
+
@wmHandler.instance_variable_set :@wmBuffer,@wmBuffer
|
60
|
+
@wmHandler.instance_variable_set :@queue,@queue
|
61
|
+
|
62
|
+
class << @wmHandler
|
63
|
+
attr_reader :hSkypeAPIWindowHandle
|
64
|
+
|
65
|
+
def msghandler(sMsg)
|
66
|
+
case sMsg.msg
|
67
|
+
when @dwAttachMsg
|
68
|
+
case sMsg.lParam
|
69
|
+
when SKYPECONTROLAPI_ATTACH_SUCCESS
|
70
|
+
@hSkypeAPIWindowHandle = sMsg.wParam
|
71
|
+
@queue.push Proc.new{@skypeAPI.invoke_callback("PROTOCOL 9999"){}}
|
72
|
+
|
73
|
+
@queue.push Proc.new{@skypeAPI.do_event(:attach,:success)}
|
74
|
+
unless @skypeAPI.attached
|
75
|
+
if @skypeAPI.first_attached
|
76
|
+
@queue.push Proc.new{@skypeAPI.do_event(:attached)}
|
77
|
+
else
|
78
|
+
@queue.push Proc.new{@skypeAPI.do_event(:reattached)}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
@skypeAPI.attached = true
|
82
|
+
@skypeAPI.first_attached = false
|
83
|
+
when SKYPECONTROLAPI_ATTACH_PENDING_AUTHORIZATION
|
84
|
+
@queue.push Proc.new{@skypeAPI.do_event(:attach,:authorize)}
|
85
|
+
@queue.push Proc.new{@skypeAPI.do_event(:authorize)}
|
86
|
+
when SKYPECONTROLAPI_ATTACH_REFUSED
|
87
|
+
@queue.push Proc.new{@skypeAPI.do_event(:attach,:refused)}
|
88
|
+
@queue.push Proc.new{@skypeAPI.do_event(:refused)}
|
89
|
+
@skypeAPI.attached = false
|
90
|
+
when SKYPECONTROLAPI_ATTACH_NOT_AVAILABLE
|
91
|
+
@queue.push Proc.new{@skypeAPI.do_event(:attach, :not_available)}
|
92
|
+
@queue.push Proc.new{@skypeAPI.do_event(:not_available)}
|
93
|
+
@skypeAPI.attached = false
|
94
|
+
when SKYPECONTROLAPI_ATTACH_API_AVAILABLE
|
95
|
+
@queue.push Proc.new{@skypeAPI.do_event(:attach, :available)}
|
96
|
+
@queue.push Proc.new{@skypeAPI.do_event(:available)}
|
97
|
+
else
|
98
|
+
@queue.push Proc.new{@skypeAPI.do_event(:attach,:unkown)}
|
99
|
+
@queue.push Proc.new{@skypeAPI.do_event(:unkown)}
|
100
|
+
end
|
101
|
+
sMsg.retval = 1
|
102
|
+
#return true
|
103
|
+
when WM_COPYDATA
|
104
|
+
if sMsg.wParam == @hSkypeAPIWindowHandle
|
105
|
+
retval = application.cstruct2array(sMsg.lParam,"LLL")
|
106
|
+
cmd = application.pointer2string(retval[2],retval[1])
|
107
|
+
@skypeAPI.push_queue cmd
|
108
|
+
sMsg.retval = 1
|
109
|
+
return true
|
110
|
+
end
|
111
|
+
when WM_USER_MSG
|
112
|
+
unless SendMessage.call(sMsg.wParam, WM_COPYDATA, sMsg.hWnd, sMsg.lParam)
|
113
|
+
raise SkypeAPIError::Connect,"Skype not ready"
|
114
|
+
end
|
115
|
+
sMsg.retval = true
|
116
|
+
return true
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
@wmHandler.create unless @wmHandler.alive?
|
122
|
+
@dwDiscoverMsg = RegisterWindowMessage.call("SkypeControlAPIDiscover");
|
123
|
+
raise SkypeAPIError::Attach,"SkypeControlAPIDiscover nothing" unless @dwDiscoverMsg
|
124
|
+
@dwAttachMsg = RegisterWindowMessage.call("SkypeControlAPIAttach")
|
125
|
+
raise SkypeAPIError::Attach,"SkypeControlAPIAttach nothing" unless @dwAttachMsg
|
126
|
+
@wmHandler.instance_variable_set :@dwAttachMsg, @dwAttachMsg
|
127
|
+
@wmHandler.addEvent @dwAttachMsg
|
128
|
+
end
|
129
|
+
|
130
|
+
attr_accessor :attached, :first_attached#,:received,:sent
|
131
|
+
|
132
|
+
def attach name = nil #,&block)
|
133
|
+
#post?
|
134
|
+
unless PostMessage.call(HWND_BROADCAST, @dwDiscoverMsg, @wmHandler.hWnd, 0)
|
135
|
+
raise SkypeAPIError::Attach,"SkypeControlAPIDiscover broadcast fail"
|
136
|
+
end
|
137
|
+
return true
|
138
|
+
end
|
139
|
+
|
140
|
+
def attach_wait name = nil
|
141
|
+
flag = true
|
142
|
+
add_event :attached do
|
143
|
+
flag = false
|
144
|
+
end
|
145
|
+
attach name
|
146
|
+
while flag
|
147
|
+
polling
|
148
|
+
sleep SLEEP_INTERVAL
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
def invoke_prototype num, cmd
|
153
|
+
unless @wmHandler.hSkypeAPIWindowHandle
|
154
|
+
raise SkypeAPIError::Attach,"NullPointerException SendSkype!"
|
155
|
+
return false
|
156
|
+
end
|
157
|
+
|
158
|
+
cmd = '#' + num.to_s + ' ' + cmd + "\0"
|
159
|
+
pCopyData = @wmHandler.application.arg2cstructStr("LLS",0,cmd.length+1,cmd)
|
160
|
+
unless PostMessage.call(@wmHandler.hWnd, WM_USER_MSG, @wmHandler.hSkypeAPIWindowHandle, pCopyData)
|
161
|
+
@wmHandler.instance_variable_set :@hSkypeAPIWindowHandle,nil
|
162
|
+
raise SkypeAPIError::Attach,"Skype not ready"
|
163
|
+
end
|
164
|
+
@queue.push(proc{do_event(:sent, cmd)}) if exist_event? :sent
|
165
|
+
return true
|
166
|
+
end
|
167
|
+
|
168
|
+
def invoke_callback cmd,cb=Proc.new
|
169
|
+
send_count = nil
|
170
|
+
@invoke_mutex.synchronize do
|
171
|
+
send_count = @send_count
|
172
|
+
@send_count += 1
|
173
|
+
end
|
174
|
+
|
175
|
+
@callback[send_count] = cb
|
176
|
+
begin
|
177
|
+
invoke_prototype send_count, cmd
|
178
|
+
rescue => e
|
179
|
+
@callback.delete(send_count)
|
180
|
+
raise e
|
181
|
+
end
|
182
|
+
return true
|
183
|
+
end
|
184
|
+
=begin
|
185
|
+
def invoke_block cmd, waitLimit=nil
|
186
|
+
@invoke_block_mutex.synchronize do
|
187
|
+
res_val = nil
|
188
|
+
current_thread = Thread.current
|
189
|
+
invoke_callback cmd do |res|
|
190
|
+
res_val = res
|
191
|
+
current_thread.run
|
192
|
+
end
|
193
|
+
begin
|
194
|
+
timeout 10 do
|
195
|
+
sleep
|
196
|
+
end
|
197
|
+
rescue TimeoutError
|
198
|
+
if ping
|
199
|
+
retry
|
200
|
+
else
|
201
|
+
reattach
|
202
|
+
return invoke_block(cmd)
|
203
|
+
end
|
204
|
+
else
|
205
|
+
return res_val
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def reattach
|
211
|
+
@attached = false
|
212
|
+
@queue.push(proc{do_event(:detached)})
|
213
|
+
if @raise_when_detached
|
214
|
+
raise SkypeAPI::Error::Attach
|
215
|
+
else
|
216
|
+
SkypeAPI.attach
|
217
|
+
loop do
|
218
|
+
if @attached
|
219
|
+
break
|
220
|
+
end
|
221
|
+
sleep SLEEP_INTERVAL
|
222
|
+
end
|
223
|
+
p 'reattached'
|
224
|
+
end
|
225
|
+
end
|
226
|
+
=end
|
227
|
+
#=begin
|
228
|
+
def invoke_block cmd, waitLimit = WAIT_CMD_LIMIT
|
229
|
+
resVal = nil
|
230
|
+
invoke_callback cmd do |res|
|
231
|
+
resVal = res
|
232
|
+
end
|
233
|
+
startTime = Time.now
|
234
|
+
loop do
|
235
|
+
polling
|
236
|
+
if resVal
|
237
|
+
return resVal
|
238
|
+
end
|
239
|
+
|
240
|
+
if Time.now - startTime > waitLimit
|
241
|
+
if ping
|
242
|
+
startTime = Time.now
|
243
|
+
else
|
244
|
+
if @attached
|
245
|
+
@attached = false
|
246
|
+
@queue.push(proc{do_event(:detached)})
|
247
|
+
SkypeAPI.attach
|
248
|
+
end
|
249
|
+
|
250
|
+
if @raise_when_detached
|
251
|
+
raise SkypeAPI::Error::Attach
|
252
|
+
else
|
253
|
+
loop do
|
254
|
+
polling
|
255
|
+
if @attached
|
256
|
+
break
|
257
|
+
end
|
258
|
+
sleep SLEEP_INTERVAL
|
259
|
+
end
|
260
|
+
ret = invoke_block(cmd, waitLimit)
|
261
|
+
return ret
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
#Thread.pass
|
267
|
+
sleep SLEEP_INTERVAL
|
268
|
+
end
|
269
|
+
end
|
270
|
+
#=end
|
271
|
+
def wait someAction=nil
|
272
|
+
if someAction.class == Proc
|
273
|
+
@wmHandler.application.messageloop do
|
274
|
+
queue_process
|
275
|
+
Timer.polling
|
276
|
+
someAction.call
|
277
|
+
end
|
278
|
+
elsif block_given?
|
279
|
+
@wmHandler.application.messageloop do
|
280
|
+
queue_process
|
281
|
+
Timer.polling
|
282
|
+
yield
|
283
|
+
end
|
284
|
+
else
|
285
|
+
@wmHandler.application.messageloop do
|
286
|
+
queue_process
|
287
|
+
Timer.polling
|
288
|
+
end
|
289
|
+
end
|
290
|
+
end
|
291
|
+
|
292
|
+
def polling
|
293
|
+
@wmHandler.application.doevents
|
294
|
+
Thread.pass
|
295
|
+
queue_process
|
296
|
+
Timer.polling
|
297
|
+
end
|
298
|
+
|
299
|
+
def close
|
300
|
+
@wmHandler.close
|
301
|
+
end
|
302
|
+
|
303
|
+
def push_queue res
|
304
|
+
@queue.push(proc{do_event(:received, res.chop)})
|
305
|
+
if res =~ /^(#(\d+?) )?(.+?)\000$/m
|
306
|
+
if $2
|
307
|
+
if @callback[$2.to_i]
|
308
|
+
cb = @callback[$2.to_i]
|
309
|
+
val = $3
|
310
|
+
@callback.delete($2.to_i)
|
311
|
+
#@queue.push(proc{cb.call val})
|
312
|
+
cb.call val
|
313
|
+
end
|
314
|
+
else
|
315
|
+
cmd = $3
|
316
|
+
|
317
|
+
if cmd == 'CONNSTATUS LOGGEDOUT'
|
318
|
+
@attached = false
|
319
|
+
@queue.push(proc{do_event(:detached)})
|
320
|
+
SkypeAPI.attach
|
321
|
+
end
|
322
|
+
|
323
|
+
flag = false
|
324
|
+
@notify.each do |reg,action|
|
325
|
+
if cmd =~ reg
|
326
|
+
tmp = $1
|
327
|
+
@queue.push(proc{action.call(tmp)})
|
328
|
+
flag = true
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
unless flag
|
333
|
+
action = @notify[nil]
|
334
|
+
@queue.push(proc{action.call(cmd)})
|
335
|
+
end
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
private
|
341
|
+
def queue_process
|
342
|
+
while callback = @queue.shift
|
343
|
+
#Thread.new do
|
344
|
+
callback.call
|
345
|
+
#end
|
346
|
+
end
|
347
|
+
end
|
348
|
+
#=begin
|
349
|
+
def ping
|
350
|
+
resVal = nil
|
351
|
+
invoke_callback 'PING' do |res|
|
352
|
+
resVal = res
|
353
|
+
end
|
354
|
+
startTime = Time.now
|
355
|
+
loop do
|
356
|
+
polling##
|
357
|
+
if resVal
|
358
|
+
return resVal
|
359
|
+
end
|
360
|
+
if Time.now - startTime > PING_LIMIT
|
361
|
+
return false
|
362
|
+
end
|
363
|
+
sleep SLEEP_INTERVAL
|
364
|
+
end
|
365
|
+
end
|
366
|
+
#=end
|
367
|
+
end
|
368
|
+
end
|
369
|
+
end
|
data/lib/skypeapi/profile.rb
CHANGED
@@ -7,12 +7,16 @@ module SkypeAPI
|
|
7
7
|
super nil
|
8
8
|
end
|
9
9
|
|
10
|
+
def self.new
|
11
|
+
super nil
|
12
|
+
end
|
13
|
+
|
10
14
|
def self.notified msg
|
11
15
|
if msg =~ /^([^ ]+) (.*)$/m
|
12
16
|
property = P2M[$1]
|
13
17
|
value = V2O[property] ? V2O[property].call($2) : $2
|
14
|
-
instance = new
|
15
|
-
instance.notified property,value #if @@instance[self][id]
|
18
|
+
instance = new
|
19
|
+
instance.notified instance, property,value #if @@instance[self][id]
|
16
20
|
|
17
21
|
#p [property,value,instance,@notify]
|
18
22
|
#if @notify[nil]
|
@@ -39,7 +43,7 @@ module SkypeAPI
|
|
39
43
|
str.split(' ')
|
40
44
|
end
|
41
45
|
getter :Country, 'COUNTRY' do |str|
|
42
|
-
str.empty? ?
|
46
|
+
str.empty? ? str : str.split(' ', 2)[0]
|
43
47
|
end
|
44
48
|
getter :IPCountry, 'IPCOUNTRY'
|
45
49
|
getter :Province, 'PROVINCE'
|
@@ -75,44 +79,48 @@ module SkypeAPI
|
|
75
79
|
str.split(', ')
|
76
80
|
end
|
77
81
|
|
78
|
-
def setFullname(name)
|
79
|
-
def setBirthday(dateOrYear, month=nil, day=nil)
|
80
|
-
|
81
|
-
|
82
|
+
def setFullname(name) invoke_set('FULLNAME', name); end
|
83
|
+
def setBirthday(dateOrYear=nil, month=nil, day=nil)
|
84
|
+
if dateOrYear.nil?
|
85
|
+
val = ''
|
86
|
+
else
|
87
|
+
val = dateOrYear.class == Date ? dateOrYear.strftime('%Y%m%d') : sprintf("%04d%02d%02d",dateOrYear,month,day)
|
88
|
+
end
|
89
|
+
invoke_set('BIRTHDAY', val)
|
82
90
|
end
|
83
|
-
def setSex(sex)
|
91
|
+
def setSex(sex) invoke_set('SEX', sex); end
|
84
92
|
def setLanguages(*langs)
|
85
|
-
|
86
|
-
end
|
87
|
-
def setCountry(iso)
|
88
|
-
#def setIpcountry(val)
|
89
|
-
def setProvince(province)
|
90
|
-
def setCity(city)
|
91
|
-
def setPhoneHome(numbers)
|
92
|
-
def setPhoneOffice(numbers)
|
93
|
-
def setPhoneMobile(numbers)
|
94
|
-
def setHomepage(url)
|
95
|
-
def setAbout(text)
|
96
|
-
def setMoodText(text)
|
97
|
-
def setRichMoodText(text)
|
98
|
-
def setTimezone(timezone)
|
93
|
+
invoke_set('LANGUAGES', langs.join(' '))
|
94
|
+
end
|
95
|
+
def setCountry(iso) invoke_set('COUNTRY', iso); end
|
96
|
+
#def setIpcountry(val) invoke_set('IPCOUNTRY', val); end
|
97
|
+
def setProvince(province) invoke_set('PROVINCE', province); end
|
98
|
+
def setCity(city) invoke_set('CITY', city); end
|
99
|
+
def setPhoneHome(numbers) invoke_set('PHONE_HOME', numbers); end
|
100
|
+
def setPhoneOffice(numbers) invoke_set('PHONE_OFFICE', numbers); end
|
101
|
+
def setPhoneMobile(numbers) invoke_set('PHONE_MOBILE', numbers); end
|
102
|
+
def setHomepage(url) invoke_set('HOMEPAGE', url); end
|
103
|
+
def setAbout(text) invoke_set('ABOUT', text); end
|
104
|
+
def setMoodText(text) invoke_set('MOOD_TEXT', text); end
|
105
|
+
def setRichMoodText(text) invoke_set('RICH_MOOD_TEXT', text); end
|
106
|
+
def setTimezone(timezone) invoke_set('TIMEZONE', timezone); end
|
99
107
|
def setCallApplyCF(flag)
|
100
|
-
|
108
|
+
invoke_set('CALL_APPLY_CF', flag._str)
|
101
109
|
end
|
102
|
-
def setCallNoanswerTimeout(sec)
|
110
|
+
def setCallNoanswerTimeout(sec) invoke_set('CALL_NOANSWER_TIMEOUT', sec); end
|
103
111
|
def setCallForwardRules(*rules)
|
104
112
|
if rules[0] == nil
|
105
|
-
|
113
|
+
invoke_set('CALL_FORWARD_RULES', '')
|
106
114
|
else
|
107
115
|
rules.map! do |rule|
|
108
116
|
rule.join ','
|
109
117
|
end
|
110
118
|
rules = rules.join ' '
|
111
|
-
|
119
|
+
invoke_set('CALL_FORWARD_RULES', rules)
|
112
120
|
end
|
113
121
|
end
|
114
122
|
def setCallSendToVM(flag)
|
115
|
-
|
123
|
+
invoke_set('CALL_SEND_TO_VM', flag._str)
|
116
124
|
end
|
117
125
|
end
|
118
126
|
end
|
@@ -63,39 +63,54 @@ module SkypeAPI
|
|
63
63
|
#private
|
64
64
|
|
65
65
|
#ex
|
66
|
-
#
|
66
|
+
#invoke_echo "CREATE APPLICATION #{@appName}"
|
67
67
|
#CREATE APPLICATION #{@appName} -> CREATE APPLICATION #{@appName}
|
68
|
-
def
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
def invoke_echo cmd
|
69
|
+
begin
|
70
|
+
invoke(cmd) == cmd
|
71
|
+
rescue SkypeAPIError
|
72
|
+
raise $!, caller(1)
|
73
|
+
end
|
74
|
+
end
|
72
75
|
#ex
|
73
|
-
#
|
76
|
+
#invoke_one "GET CHATMESSAGE #{@id} BODY","CHATMESSAGE #{@id} BODY"
|
74
77
|
#GET CHATMESSAGE #{@id} BODY -> CHATMESSAGE #{@id} BODY (.+)
|
75
|
-
def
|
78
|
+
def invoke_one cmd, regExp=cmd
|
76
79
|
regExp.gsub!(/[\^$.\\\[\]*+{}?|()]/) do |char|
|
77
80
|
"\\" + char
|
78
81
|
end
|
79
|
-
|
80
|
-
|
82
|
+
begin
|
83
|
+
invoke(cmd) =~ /^#{regExp} (.*)$/m
|
84
|
+
return $1
|
85
|
+
rescue SkypeAPIError => e
|
86
|
+
raise $!, caller
|
87
|
+
end
|
81
88
|
end
|
82
89
|
|
83
90
|
#ex
|
84
|
-
#
|
91
|
+
#invoke_get("GET USER #{@handle} SkypeOut")
|
85
92
|
#GET USER #{@handle} SkypeOut -> USER #{@handle} SkypeOut (.+)
|
86
|
-
def
|
93
|
+
def invoke_get prop, value=nil
|
87
94
|
cmd = "GET #{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{@id ? @id.to_s+' ' : ''}#{prop}#{value ? ' ' + value : ''}"
|
88
95
|
reg = "#{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{@id ? @id.to_s+' ' : ''}#{prop}#{value ? ' ' + value : ''}".gsub(/[\^$.\\\[\]*+{}?|()]/) do |char|
|
89
96
|
"\\" + char
|
90
97
|
end
|
91
|
-
|
92
|
-
|
98
|
+
begin
|
99
|
+
invoke(cmd) =~ /^#{reg} (.*)$/m
|
100
|
+
return $1
|
101
|
+
rescue SkypeAPIError
|
102
|
+
raise $!, caller
|
103
|
+
end
|
93
104
|
end
|
94
105
|
|
95
|
-
def
|
106
|
+
def invoke_set prop,value=nil
|
96
107
|
cmd = "SET #{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{@id ? @id.to_s + ' ' : ''}#{prop}#{value ? ' '+value.to_s : '' }"
|
97
108
|
reg = "#{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{@id ? @id.to_s + ' ' : ''}#{prop}"
|
98
|
-
|
109
|
+
begin
|
110
|
+
str = invoke_one cmd, reg
|
111
|
+
rescue SkypeAPIError
|
112
|
+
raise $!, caller
|
113
|
+
end
|
99
114
|
if self.class == Module
|
100
115
|
self::V2O[prop] ? self::V2O[prop].call(str) : str
|
101
116
|
else
|
@@ -103,20 +118,24 @@ module SkypeAPI
|
|
103
118
|
end
|
104
119
|
end
|
105
120
|
|
106
|
-
#true�����Ԃ��Ȃ��B������ςȂ��B����ȊO�̕Ԃ茌������悤�Ȃ̂͂�
|
107
|
-
def
|
121
|
+
#true�����Ԃ��Ȃ��B������ςȂ��B����ȊO�̕Ԃ茌������悤�Ȃ̂͂�invoke�Ŏ�������B
|
122
|
+
def invoke_alter prop, value=nil
|
108
123
|
cmd = "ALTER #{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{@id ? @id.to_s + ' ' : ''}#{prop}#{value ? ' '+value.to_s : '' }"
|
109
124
|
#res = "ALTER #{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{@id ? @id.to_s + ' ' : ''}#{prop}"
|
110
125
|
#reg.gsub!(/[\^$.\\\[\]*+{}?|()]/) do |char|
|
111
126
|
# "\\" + char
|
112
127
|
#end
|
113
128
|
#res = "ALTER #{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{prop}"
|
114
|
-
|
129
|
+
begin
|
130
|
+
invoke(cmd)# == res
|
131
|
+
rescue SkypeAPIError
|
132
|
+
raise $!, caller
|
133
|
+
end
|
115
134
|
true
|
116
135
|
end
|
117
136
|
|
118
137
|
#def sendAlterWithID prop, value=nil
|
119
|
-
# str =
|
138
|
+
# str = invoke_one "ALTER #{self.class::OBJECT_NAME} #{@id} #{prop}#{value ? ' '+value.to_s : '' }","ALTER #{self.class::OBJECT_NAME} #{@id} #{prop}"
|
120
139
|
# self.class::V2O[self.class::P2M[prop]] ? self.class::V2O[self.class::P2M[prop]].call(str) : str
|
121
140
|
#end
|
122
141
|
end
|
data/lib/skypeapi/sms.rb
CHANGED
@@ -4,7 +4,7 @@ module SkypeAPI
|
|
4
4
|
OBJECT_NAME = "SMS"
|
5
5
|
|
6
6
|
def self.create target, type="OUTGOING"
|
7
|
-
res = @@skypeApi.
|
7
|
+
res = @@skypeApi.invoke "CREATE SMS #{type} #{target}"
|
8
8
|
res =~ /^SMS (\d+) STATUS (.+)$/
|
9
9
|
id, status = $1, $2
|
10
10
|
return id, status
|
@@ -19,7 +19,7 @@ module SkypeAPI
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def self.delete id
|
22
|
-
@@skypeApi.
|
22
|
+
@@skypeApi.invoke_echo "DELETE SMS #{id}"
|
23
23
|
end
|
24
24
|
|
25
25
|
getter :Body, 'BODY'
|
@@ -56,28 +56,28 @@ module SkypeAPI
|
|
56
56
|
end
|
57
57
|
|
58
58
|
def setBody text
|
59
|
-
|
59
|
+
invoke_set "BODY", text
|
60
60
|
end
|
61
61
|
|
62
62
|
def send
|
63
|
-
|
63
|
+
invoke_alter "SEND"
|
64
64
|
end
|
65
65
|
|
66
66
|
def delete
|
67
|
-
|
67
|
+
invoke_echo "DLETE SMS #{@id}"
|
68
68
|
end
|
69
69
|
|
70
70
|
def setTargetNumber *nums
|
71
71
|
nums = nums[0] if nums[0].class == Array
|
72
|
-
|
72
|
+
invoke_set "TARGET_NUMBERS", nums.join(', ')
|
73
73
|
end
|
74
74
|
|
75
75
|
def setSeen
|
76
|
-
|
76
|
+
invoke_set "SEEN"
|
77
77
|
end
|
78
78
|
|
79
79
|
def setReplyToNumber pstn
|
80
|
-
|
80
|
+
invoke_set "REPLY_TO_NUMBER", pstn
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|