Ruby4Skype 0.2.1
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 +415 -0
- data/lib/skypeapi/call.rb +220 -0
- data/lib/skypeapi/chat.rb +186 -0
- data/lib/skypeapi/chatmember.rb +33 -0
- data/lib/skypeapi/chatmessage.rb +64 -0
- data/lib/skypeapi/event.rb +46 -0
- data/lib/skypeapi/filetransfer.rb +31 -0
- data/lib/skypeapi/group.rb +81 -0
- data/lib/skypeapi/menuitem.rb +64 -0
- data/lib/skypeapi/message.rb +46 -0
- data/lib/skypeapi/object.rb +122 -0
- data/lib/skypeapi/os.rb +423 -0
- data/lib/skypeapi/profile.rb +124 -0
- data/lib/skypeapi/sharefunctions.rb +123 -0
- data/lib/skypeapi/sms.rb +84 -0
- data/lib/skypeapi/user.rb +110 -0
- data/lib/skypeapi/voicemail.rb +60 -0
- data/lib/skypeapi.rb +569 -0
- metadata +64 -0
data/lib/skypeapi/os.rb
ADDED
@@ -0,0 +1,423 @@
|
|
1
|
+
module SkypeAPI
|
2
|
+
module OS
|
3
|
+
module Share
|
4
|
+
WAIT_CMD_LIMIT = 15.0 #sec
|
5
|
+
PING_CYCLE = 30.0 #sec
|
6
|
+
PING_LIMIT = 10.0 # < PING_CYCLE
|
7
|
+
|
8
|
+
def sendCMD cmd,method=nil,&block
|
9
|
+
if method
|
10
|
+
sendCallBack cmd do |res|
|
11
|
+
check res,cmd
|
12
|
+
method.call res
|
13
|
+
end
|
14
|
+
return true
|
15
|
+
elsif block_given?
|
16
|
+
sendCallBack cmd do |res|
|
17
|
+
check res,cmd
|
18
|
+
block.call res
|
19
|
+
end
|
20
|
+
return true
|
21
|
+
else
|
22
|
+
return check(sendBlock(cmd),cmd)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def check res,cmd
|
27
|
+
if res =~ /^ERROR /m
|
28
|
+
raise SkypeAPIError::API,res,cmd
|
29
|
+
else
|
30
|
+
return res
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def sendCallBack cmd,cb=Proc.new
|
35
|
+
@callBack[@sendCount] = cb
|
36
|
+
begin
|
37
|
+
sendMSG cmd
|
38
|
+
rescue => e
|
39
|
+
@callBack.delete(@sendCount)
|
40
|
+
raise e
|
41
|
+
end
|
42
|
+
return true
|
43
|
+
end
|
44
|
+
|
45
|
+
def sendBlock cmd, waitLimit = WAIT_CMD_LIMIT
|
46
|
+
resVal = nil
|
47
|
+
sendCallBack cmd do |res|
|
48
|
+
resVal = res
|
49
|
+
end
|
50
|
+
startTime = Time.now
|
51
|
+
loop do
|
52
|
+
polling
|
53
|
+
if resVal
|
54
|
+
return resVal
|
55
|
+
end
|
56
|
+
if Time.now - startTime > waitLimit
|
57
|
+
unless existEvent? :reconnect
|
58
|
+
raise SkypeAPIError::TimeOut,"TimeOut #{cmd} {(Time.now - startTime).to_i}"
|
59
|
+
else
|
60
|
+
doEvent :reconnect
|
61
|
+
return sendBlock(cmd, waitLimit)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
#Thread.pass
|
65
|
+
sleep 0.00123
|
66
|
+
#sleep 0.000001
|
67
|
+
#sleep 0.01
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def attachWait
|
72
|
+
flag = true
|
73
|
+
attach do |state|
|
74
|
+
flag = false if state == :success
|
75
|
+
end
|
76
|
+
while flag
|
77
|
+
polling
|
78
|
+
#sleep 0.0123
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
#����reg==nil�ŁA���̑��ƌ���㩁B
|
83
|
+
def addNotify reg, block=Proc.new
|
84
|
+
@notify[reg] = block
|
85
|
+
end
|
86
|
+
|
87
|
+
def delNotify reg
|
88
|
+
@notify.delete reg
|
89
|
+
end
|
90
|
+
|
91
|
+
def addEvent sym, block=Proc.new
|
92
|
+
@event[sym].push block
|
93
|
+
block
|
94
|
+
end
|
95
|
+
|
96
|
+
def setEvent sym, block=Proc.new
|
97
|
+
@event[sym] = Array.new
|
98
|
+
addEvent sym, block
|
99
|
+
end
|
100
|
+
|
101
|
+
def delEvent sym, block=nil
|
102
|
+
unless block
|
103
|
+
@event[sym] = Array.new
|
104
|
+
else
|
105
|
+
@event[sym].delete block
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def replaceEvent sym,block=Proc.new
|
110
|
+
tmp = @event[sym].dup
|
111
|
+
if defined?(block.each)
|
112
|
+
block.each do |e|
|
113
|
+
addEvent sym, e
|
114
|
+
end
|
115
|
+
else
|
116
|
+
setEvent sym,block
|
117
|
+
end
|
118
|
+
return tmp
|
119
|
+
end
|
120
|
+
|
121
|
+
def existEvent? sym
|
122
|
+
if @event[sym].length > 0
|
123
|
+
return true
|
124
|
+
else
|
125
|
+
return false
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def getEvent sym
|
130
|
+
@event[sym]
|
131
|
+
end
|
132
|
+
|
133
|
+
def doEvent sym,*args
|
134
|
+
@event[sym].each do |e|
|
135
|
+
if e.arity == 1
|
136
|
+
e.call args[0]
|
137
|
+
else
|
138
|
+
e.call args
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def pushQueue res
|
144
|
+
if res =~ /^(#(\d+?) )?(.+?)\000$/m
|
145
|
+
if $2
|
146
|
+
if @callBack[$2.to_i]
|
147
|
+
cb = @callBack[$2.to_i]
|
148
|
+
val = $3
|
149
|
+
@queue.push(proc{cb.call val})
|
150
|
+
@callBack.delete($2.to_i)
|
151
|
+
end
|
152
|
+
cmd = "#" + $2 + " " + $3
|
153
|
+
else
|
154
|
+
cmd = $3
|
155
|
+
flag = false
|
156
|
+
@notify.each do |reg,action|
|
157
|
+
if cmd =~ reg
|
158
|
+
res = $1
|
159
|
+
@queue.push(proc{action.call(res)})
|
160
|
+
flag = true
|
161
|
+
end
|
162
|
+
end
|
163
|
+
unless flag
|
164
|
+
action = @notify[nil]
|
165
|
+
@queue.push(proc{action.call(cmd)})
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
@queue.push(proc{doEvent(:received, cmd)}) if existEvent? :received
|
171
|
+
end
|
172
|
+
|
173
|
+
def queueProcess
|
174
|
+
@pingTime = Time.now unless @pingTime
|
175
|
+
if Time.now - @pingTime > PING_CYCLE
|
176
|
+
@queue.push method(:checkConnection)
|
177
|
+
@pingTime = Time.now
|
178
|
+
end
|
179
|
+
|
180
|
+
while e = @queue.shift
|
181
|
+
e.call
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def checkConnection
|
186
|
+
begin
|
187
|
+
resVal = nil
|
188
|
+
sendCallBack 'PING' do |res|
|
189
|
+
resVal = res
|
190
|
+
end
|
191
|
+
startTime = Time.now
|
192
|
+
i = 0
|
193
|
+
loop do
|
194
|
+
polling
|
195
|
+
if resVal
|
196
|
+
unless resVal == "PONG"
|
197
|
+
raise SkypeAPIError::Reconnect
|
198
|
+
else
|
199
|
+
break
|
200
|
+
end
|
201
|
+
end
|
202
|
+
if Time.now - startTime > PING_LIMIT and i > 3
|
203
|
+
raise SkypeAPIError::TimeOut
|
204
|
+
end
|
205
|
+
i+=1
|
206
|
+
sleep 0.001
|
207
|
+
end
|
208
|
+
rescue SkypeAPIError::Reconnect,SkypeAPIError::TimeOut
|
209
|
+
unless existEvent? :reconnect
|
210
|
+
raise SkypeAPIError::Reconnect
|
211
|
+
else
|
212
|
+
doEvent :reconnect
|
213
|
+
end
|
214
|
+
end
|
215
|
+
return true
|
216
|
+
end
|
217
|
+
|
218
|
+
end
|
219
|
+
|
220
|
+
class Windows
|
221
|
+
begin
|
222
|
+
require 'rubygems'
|
223
|
+
gem 'swin'
|
224
|
+
rescue LoadError
|
225
|
+
end
|
226
|
+
require "swin"
|
227
|
+
require 'Win32API'
|
228
|
+
include Share
|
229
|
+
|
230
|
+
HWND_BROADCAST = 0xFFFF
|
231
|
+
WM_COPYDATA = 0x004A
|
232
|
+
WM_USER = 0x0400
|
233
|
+
WM_USER_MSG = WM_USER + 1
|
234
|
+
SKYPECONTROLAPI_ATTACH_SUCCESS=0
|
235
|
+
SKYPECONTROLAPI_ATTACH_PENDING_AUTHORIZATION=1
|
236
|
+
SKYPECONTROLAPI_ATTACH_REFUSED=2
|
237
|
+
SKYPECONTROLAPI_ATTACH_NOT_AVAILABLE=3
|
238
|
+
SKYPECONTROLAPI_ATTACH_API_AVAILABLE=0x8001
|
239
|
+
|
240
|
+
RegisterWindowMessage = Win32API.new('user32','RegisterWindowMessageA', 'P', 'L')
|
241
|
+
SendMessage = Win32API.new("user32", "SendMessageA", ['L']*4, 'L')
|
242
|
+
PostMessage = Win32API.new("user32", "PostMessageA", 'LLLP', 'L')
|
243
|
+
|
244
|
+
def initialize
|
245
|
+
@sendCount = 0
|
246
|
+
@queue = Array.new
|
247
|
+
@callBack = Hash.new
|
248
|
+
@notify = Hash.new
|
249
|
+
@event = Hash.new do |h,k|
|
250
|
+
h[k] = Array.new
|
251
|
+
end
|
252
|
+
|
253
|
+
addEvent :reconnect do
|
254
|
+
flag = true
|
255
|
+
attachEvent = replaceEvent :attached do
|
256
|
+
flag = false
|
257
|
+
end
|
258
|
+
attach
|
259
|
+
while flag
|
260
|
+
polling
|
261
|
+
sleep 0.123
|
262
|
+
end
|
263
|
+
replaceEvent :attach, attachEvent
|
264
|
+
end
|
265
|
+
|
266
|
+
@wmBuffer = Hash.new
|
267
|
+
@wmHandler = SWin::LWFactory.new(SWin::Application.hInstance).newwindow nil
|
268
|
+
@wmHandler.create
|
269
|
+
@wmHandler.addEvent(WM_COPYDATA)
|
270
|
+
@wmHandler.addEvent(WM_USER_MSG)
|
271
|
+
@wmHandler.instance_variable_set :@skypeAPI,self
|
272
|
+
@wmHandler.instance_variable_set :@wmBuffer,@wmBuffer
|
273
|
+
@wmHandler.instance_variable_set :@queue,@queue
|
274
|
+
|
275
|
+
class << @wmHandler
|
276
|
+
attr_reader :hSkypeAPIWindowHandle
|
277
|
+
|
278
|
+
def msghandler(sMsg)
|
279
|
+
case sMsg.msg
|
280
|
+
when @dwAttachMsg
|
281
|
+
case sMsg.lParam
|
282
|
+
when SKYPECONTROLAPI_ATTACH_SUCCESS
|
283
|
+
@hSkypeAPIWindowHandle = sMsg.wParam
|
284
|
+
@queue.push Proc.new{@skypeAPI.sendCMD "PROTOCOL 9999"}
|
285
|
+
@queue.push Proc.new{@skypeAPI.doEvent(:attach,:success)}
|
286
|
+
@queue.push Proc.new{@skypeAPI.doEvent(:attached)}
|
287
|
+
sMsg.retval = 1
|
288
|
+
when SKYPECONTROLAPI_ATTACH_PENDING_AUTHORIZATION:
|
289
|
+
@queue.push Proc.new{@skypeAPI.doEvent(:attach,:authorize)}
|
290
|
+
@queue.push Proc.new{@skypeAPI.doEvent(:pendingAuthorization)}
|
291
|
+
sMsg.retval = 1
|
292
|
+
when SKYPECONTROLAPI_ATTACH_REFUSED:
|
293
|
+
unless @skypeAPI.existEvent? :attach
|
294
|
+
raise SkypeAPIError::Attach,"Refused"
|
295
|
+
else
|
296
|
+
@queue.push Proc.new{@skypeAPI.doEvent(:attach,:refused)}
|
297
|
+
end
|
298
|
+
sMsg.retval = 1
|
299
|
+
when SKYPECONTROLAPI_ATTACH_NOT_AVAILABLE:
|
300
|
+
unless @skypeAPI.existEvent? :attach
|
301
|
+
raise SkypeAPIError::Attach,"Not available."
|
302
|
+
else
|
303
|
+
@queue.push Proc.new{@skypeAPI.doEvent(:attach,:notAvailable)}
|
304
|
+
end
|
305
|
+
sMsg.retval = 1
|
306
|
+
when SKYPECONTROLAPI_ATTACH_API_AVAILABLE:
|
307
|
+
@queue.push Proc.new{@skypeAPI.doEvent(:apiAvailable)}
|
308
|
+
sMsg.retval = 1
|
309
|
+
else
|
310
|
+
unless @skypeAPI.existEvent? :attach
|
311
|
+
raise SkypeAPIError::Attach,"Skype API attach unknown message"
|
312
|
+
else
|
313
|
+
@queue.push Proc.new{@skypeAPI.doEvent(:attach,:unkown)}
|
314
|
+
end
|
315
|
+
end
|
316
|
+
#return true
|
317
|
+
when WM_COPYDATA
|
318
|
+
if sMsg.wParam == @hSkypeAPIWindowHandle
|
319
|
+
retval = application.cstruct2array(sMsg.lParam,"LLL")
|
320
|
+
cmd = application.pointer2string(retval[2],retval[1])
|
321
|
+
@wmBuffer.delete($1.to_i) if cmd =~ /^#(\d+) /
|
322
|
+
@skypeAPI.pushQueue cmd
|
323
|
+
sMsg.retval = 1
|
324
|
+
return true
|
325
|
+
end
|
326
|
+
when WM_USER_MSG
|
327
|
+
unless SendMessage.call(sMsg.wParam, WM_COPYDATA, sMsg.hWnd, sMsg.lParam)
|
328
|
+
raise SkypeAPIError::Connect,"Skype not ready"
|
329
|
+
end
|
330
|
+
sMsg.retval = true
|
331
|
+
return true
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
#attr_accessor :attached,:received,:sent
|
338
|
+
|
339
|
+
def attach &block
|
340
|
+
if block
|
341
|
+
if block.arity == 1
|
342
|
+
addEvent :attach, block
|
343
|
+
else
|
344
|
+
addEvent :attached, block
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
@wmHandler.create unless @wmHandler.alive?
|
349
|
+
dwDiscoverMsg = RegisterWindowMessage.call("SkypeControlAPIDiscover");
|
350
|
+
raise SkypeAPIError::Attach,"SkypeControlAPIDiscover nothing" unless dwDiscoverMsg
|
351
|
+
dwAttachMsg = RegisterWindowMessage.call("SkypeControlAPIAttach")
|
352
|
+
raise SkypeAPIError::Attach,"SkypeControlAPIAttach nothing" unless dwAttachMsg
|
353
|
+
@wmHandler.instance_variable_set :@dwAttachMsg, dwAttachMsg
|
354
|
+
@wmHandler.addEvent dwAttachMsg
|
355
|
+
#post?
|
356
|
+
unless PostMessage.call(HWND_BROADCAST, dwDiscoverMsg, @wmHandler.hWnd, 0)
|
357
|
+
raise SkypeAPIError::Attach,"SkypeControlAPIDiscover broadcast fail"
|
358
|
+
end
|
359
|
+
return true
|
360
|
+
end
|
361
|
+
|
362
|
+
def sendMSG cmd
|
363
|
+
unless @wmHandler.hSkypeAPIWindowHandle
|
364
|
+
raise SkypeAPIErorr::Connect,"NullPointerException SendSkype!"
|
365
|
+
return false
|
366
|
+
end
|
367
|
+
|
368
|
+
cmd = '#' + @sendCount.to_s + ' ' + cmd
|
369
|
+
@wmBuffer[@sendCount] = cmd
|
370
|
+
pCopyData = @wmHandler.application.arg2cstructStr("LLS",0,@wmBuffer[@sendCount].length+1,@wmBuffer[@sendCount])
|
371
|
+
unless PostMessage.call(@wmHandler.hWnd, WM_USER_MSG, @wmHandler.hSkypeAPIWindowHandle, pCopyData)
|
372
|
+
@wmHandler.instance_variable_set :@hSkypeAPIWindowHandle,nil
|
373
|
+
raise SkypeAPIError::Connect,"Skype not ready"
|
374
|
+
return false;
|
375
|
+
end
|
376
|
+
@queue.push(proc{doEvent(:sent, cmd)}) if existEvent? :sent
|
377
|
+
@sendCount+=1
|
378
|
+
return true
|
379
|
+
end
|
380
|
+
|
381
|
+
|
382
|
+
def wait someAction=nil
|
383
|
+
if someAction.class == Proc
|
384
|
+
@wmHandler.application.messageloop do
|
385
|
+
queueProcess
|
386
|
+
someAction.call
|
387
|
+
end
|
388
|
+
elsif block_given?
|
389
|
+
@wmHandler.application.messageloop do
|
390
|
+
queueProcess
|
391
|
+
yield
|
392
|
+
end
|
393
|
+
else
|
394
|
+
@wmHandler.application.messageloop{queueProcess}
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
def polling
|
399
|
+
@wmHandler.application.doevents
|
400
|
+
queueProcess
|
401
|
+
end
|
402
|
+
|
403
|
+
def close
|
404
|
+
@wmHandler.close
|
405
|
+
end
|
406
|
+
end
|
407
|
+
|
408
|
+
class Mac
|
409
|
+
#wiki like
|
410
|
+
def initialize
|
411
|
+
raise SkypeAPIError::NotImplement
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
class Linux
|
416
|
+
#plz write it
|
417
|
+
def initialize
|
418
|
+
raise SkypeAPIError::NotImplement
|
419
|
+
end
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module SkypeAPI
|
2
|
+
module Object
|
3
|
+
class Profile < AbstractObject
|
4
|
+
OBJECT_NAME = "PROFILE"
|
5
|
+
|
6
|
+
#def initialize(id); end
|
7
|
+
|
8
|
+
def self.notified msg
|
9
|
+
if msg =~ /^([^ ]+) (.*)$/m
|
10
|
+
property = P2M[$1]
|
11
|
+
value = V2O[property] ? V2O[property].call($2) : $2
|
12
|
+
instance = new nil
|
13
|
+
instance.notified property,value #if @@instance[self][id]
|
14
|
+
|
15
|
+
#p [property,value,instance,@notify]
|
16
|
+
#if @notify[nil]
|
17
|
+
# @notify[nil][nil].call instance, property, value if @notify[nil][nil]
|
18
|
+
# @notify[nil][value].call instance, property if @notify[nil][value]
|
19
|
+
#end
|
20
|
+
#if @notify[property]
|
21
|
+
# @notify[property][nil].call instance, value if @notify[property][nil]
|
22
|
+
# @notify[property][value].call instance if @notify[property][value]
|
23
|
+
#end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
getter :PSTNBalance, 'PSTN_BALANCE' do |str|
|
28
|
+
str._int
|
29
|
+
end
|
30
|
+
getter :PSTNBalanceCurrency, 'PSTN_BALANCE_CURRENCY'
|
31
|
+
getter :Fullname, 'FULLNAME'
|
32
|
+
getter :Birthday, 'BIRTHDAY' do |yyyymmdd|
|
33
|
+
(yyyymmdd =~ /(\d\d\d\d)(\d\d)(\d\d)/) ? Date.new($1.to_i,$2.to_i,$3.to_i) : nil
|
34
|
+
end
|
35
|
+
getter :Sex, 'SEX'
|
36
|
+
getter :Languages, 'LANGUAGES' do |str|
|
37
|
+
str.split(' ')
|
38
|
+
end
|
39
|
+
getter :Country, 'COUNTRY' do |str|
|
40
|
+
str.empty? ? ['',''] : str.split(' ', 2)
|
41
|
+
end
|
42
|
+
getter :IPCountry, 'IPCOUNTRY'
|
43
|
+
getter :Province, 'PROVINCE'
|
44
|
+
getter :City, 'CITY'
|
45
|
+
getter :PhoneHome, 'PHONE_HOME'
|
46
|
+
getter :PhoneOffice, 'PHONE_OFFICE'
|
47
|
+
getter :PhoneMobile, 'PHONE_MOBILE'
|
48
|
+
getter :Homepage, 'HOMEPAGE'
|
49
|
+
getter :About, 'ABOUT'
|
50
|
+
getter :MoodText, 'MOOD_TEXT'
|
51
|
+
getter :RichMoodText, 'RICH_MOOD_TEXT'
|
52
|
+
getter :Timezone, 'TIMEZONE' do |str|
|
53
|
+
str._int
|
54
|
+
end
|
55
|
+
getter :CallApplyCF, 'CALL_APPLY_CF' do |str|
|
56
|
+
str._flag
|
57
|
+
end
|
58
|
+
getter :CallNoanswerTimeout, 'CALL_NOANSWER_TIMEOUT' do |str|
|
59
|
+
str._int
|
60
|
+
end
|
61
|
+
getter :CallForwardRules, 'CALL_FORWARD_RULES' do |str|
|
62
|
+
cfs = str.split ' '
|
63
|
+
cfs = cfs.map do |cf|
|
64
|
+
cf = cf.split ','
|
65
|
+
cf[2] = @@skypeApi.user(cf[2]) unless cf[2] =~ /^\+/
|
66
|
+
[cf[0].to_i, cf[1].to_i, (cf[2] =~ /^\+/ ? cf[2] : @@skypeApi.user(cf[2]))]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
getter :CallSendToVM, 'CALL_SEND_TO_VM' do |str|
|
70
|
+
str._flag
|
71
|
+
end
|
72
|
+
getter :SMSValidatedNumbers, 'SMS_VALIDATED_NUMBERS' do |str|
|
73
|
+
str.split(', ')
|
74
|
+
end
|
75
|
+
|
76
|
+
def setFullname(val) sendSet('FULLNAME', val); end
|
77
|
+
def setBirthday(*val)
|
78
|
+
val = val[0].class == Date ? val[0].strftime('%Y%m%d') : sprintf("%04d%02d%02d",val[0],val[1],val[2])
|
79
|
+
sendSet('BIRTHDAY', val)
|
80
|
+
end
|
81
|
+
def setSex(val) sendSet('SEX', val); end
|
82
|
+
def setLanguages(*val)
|
83
|
+
if val[0].class == Array
|
84
|
+
val = val[0].join(' ')
|
85
|
+
else
|
86
|
+
val = val.join(' ')
|
87
|
+
end
|
88
|
+
sendSet('LANGUAGES', val)
|
89
|
+
end
|
90
|
+
def setCountry(val) sendSet('COUNTRY', val); end
|
91
|
+
#def setIpcountry(val) sendSet('IPCOUNTRY', val); end
|
92
|
+
def setProvince (val) sendSet('PROVINCE', val); end
|
93
|
+
def setCity (val) sendSet('CITY', val); end
|
94
|
+
def setPhoneHome (val) sendSet('PHONE_HOME', val); end
|
95
|
+
def setPhoneOffice (val) sendSet('PHONE_OFFICE', val); end
|
96
|
+
def setPhoneMobile (val) sendSet('PHONE_MOBILE', val); end
|
97
|
+
def setHomepage (val) sendSet('HOMEPAGE', val); end
|
98
|
+
def setAbout (val) sendSet('ABOUT', val); end
|
99
|
+
def setMoodText (val) sendSet('MOOD_TEXT', val); end
|
100
|
+
def setRichMoodText (val) sendSet('RICH_MOOD_TEXT', val); end
|
101
|
+
def setTimezone (val) sendSet('TIMEZONE', val); end
|
102
|
+
def setCallApplyCF (val)
|
103
|
+
sendSet('CALL_APPLY_CF', val._str)
|
104
|
+
end
|
105
|
+
def setCallNoanswerTimeout (val) sendSet('CALL_NOANSWER_TIMEOUT', val); end
|
106
|
+
def setCallForwardRules(*val)
|
107
|
+
unless val[0] == nil
|
108
|
+
val = val[0] if val.length == 1
|
109
|
+
val = [val] unless val[0].class == Array
|
110
|
+
val.map! do |rule|
|
111
|
+
rule.join ','
|
112
|
+
end
|
113
|
+
val = val.join ' '
|
114
|
+
sendSet('CALL_FORWARD_RULES', val)
|
115
|
+
else
|
116
|
+
sendSet('CALL_FORWARD_RULES', '')
|
117
|
+
end
|
118
|
+
end
|
119
|
+
def setCallSendToVM (val)
|
120
|
+
sendSet('CALL_SEND_TO_VM', val._str)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
class NilClass
|
2
|
+
def _flag
|
3
|
+
nil
|
4
|
+
end
|
5
|
+
|
6
|
+
def _swi
|
7
|
+
nil
|
8
|
+
end
|
9
|
+
|
10
|
+
def _str
|
11
|
+
""
|
12
|
+
end
|
13
|
+
|
14
|
+
def _int
|
15
|
+
nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class String
|
20
|
+
def _flag
|
21
|
+
case self
|
22
|
+
when /^(TRUE)|(ON)$/i
|
23
|
+
return true
|
24
|
+
when /^(FALSE)|(OFF)$/i
|
25
|
+
return false
|
26
|
+
else
|
27
|
+
self
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def _int
|
32
|
+
self.empty? ? nil : self.to_i
|
33
|
+
end
|
34
|
+
|
35
|
+
def _str
|
36
|
+
self
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
class TrueClass
|
41
|
+
def _swi
|
42
|
+
"ON"
|
43
|
+
end
|
44
|
+
|
45
|
+
def _str
|
46
|
+
"TRUE"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class FalseClass
|
51
|
+
def _swi
|
52
|
+
"OFF"
|
53
|
+
end
|
54
|
+
|
55
|
+
def _str
|
56
|
+
"FALSE"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
module SkypeAPI
|
61
|
+
|
62
|
+
module ShareFunctions
|
63
|
+
#private
|
64
|
+
|
65
|
+
#ex
|
66
|
+
#sendEcho "CREATE APPLICATION #{@appName}"
|
67
|
+
#CREATE APPLICATION #{@appName} -> CREATE APPLICATION #{@appName}
|
68
|
+
def sendEcho cmd
|
69
|
+
sendCMD(cmd) == cmd
|
70
|
+
end
|
71
|
+
|
72
|
+
#ex
|
73
|
+
#sendOne "GET CHATMESSAGE #{@id} BODY","CHATMESSAGE #{@id} BODY"
|
74
|
+
#GET CHATMESSAGE #{@id} BODY -> CHATMESSAGE #{@id} BODY (.+)
|
75
|
+
def sendOne cmd, regExp=cmd
|
76
|
+
regExp.gsub!(/[\^$.\\\[\]*+{}?|()]/) do |char|
|
77
|
+
"\\" + char
|
78
|
+
end
|
79
|
+
sendCMD(cmd) =~ /^#{regExp} (.*)$/m
|
80
|
+
$1
|
81
|
+
end
|
82
|
+
|
83
|
+
#ex
|
84
|
+
#sendGet("GET USER #{@handle} SkypeOut")
|
85
|
+
#GET USER #{@handle} SkypeOut -> USER #{@handle} SkypeOut (.+)
|
86
|
+
def sendGet prop, value=nil
|
87
|
+
cmd = "GET #{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{@id ? @id.to_s+' ' : ''}#{prop}#{value ? ' ' + value : ''}"
|
88
|
+
reg = "#{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{@id ? @id.to_s+' ' : ''}#{prop}#{value ? ' ' + value : ''}".gsub(/[\^$.\\\[\]*+{}?|()]/) do |char|
|
89
|
+
"\\" + char
|
90
|
+
end
|
91
|
+
sendCMD(cmd) =~ /^#{reg} (.*)$/m
|
92
|
+
$1
|
93
|
+
end
|
94
|
+
|
95
|
+
def sendSet prop,value=nil
|
96
|
+
cmd = "SET #{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{@id ? @id.to_s + ' ' : ''}#{prop}#{value ? ' '+value.to_s : '' }"
|
97
|
+
reg = "#{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{@id ? @id.to_s + ' ' : ''}#{prop}"
|
98
|
+
str = sendOne cmd, reg
|
99
|
+
if self.class == Module
|
100
|
+
self::V2O[prop] ? self::V2O[prop].call(str) : str
|
101
|
+
else
|
102
|
+
self.class::V2O[prop] ? self.class::V2O[prop].call(str) : str
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
#true�����Ԃ��Ȃ��B������ςȂ��B����ȊO�̕Ԃ茌������悤�Ȃ̂͂�sendCMD�Ŏ�������B
|
107
|
+
def sendAlter prop, value=nil
|
108
|
+
cmd = "ALTER #{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{@id ? @id.to_s + ' ' : ''}#{prop}#{value ? ' '+value.to_s : '' }"
|
109
|
+
#res = "ALTER #{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{@id ? @id.to_s + ' ' : ''}#{prop}"
|
110
|
+
#reg.gsub!(/[\^$.\\\[\]*+{}?|()]/) do |char|
|
111
|
+
# "\\" + char
|
112
|
+
#end
|
113
|
+
#res = "ALTER #{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{prop}"
|
114
|
+
sendCMD(cmd)# == res
|
115
|
+
true
|
116
|
+
end
|
117
|
+
|
118
|
+
#def sendAlterWithID prop, value=nil
|
119
|
+
# str = sendOne "ALTER #{self.class::OBJECT_NAME} #{@id} #{prop}#{value ? ' '+value.to_s : '' }","ALTER #{self.class::OBJECT_NAME} #{@id} #{prop}"
|
120
|
+
# self.class::V2O[self.class::P2M[prop]] ? self.class::V2O[self.class::P2M[prop]].call(str) : str
|
121
|
+
#end
|
122
|
+
end
|
123
|
+
end
|