Ruby4Skype 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/skypeapi.rb ADDED
@@ -0,0 +1,569 @@
1
+ require "forwardable.rb"
2
+ require "skypeApi/os.rb"
3
+ require "skypeApi/shareFunctions.rb"
4
+ require "skypeApi/object.rb"
5
+
6
+ require "skypeApi/user.rb"
7
+ require "skypeApi/profile.rb"
8
+ require "skypeApi/call.rb"
9
+ require "skypeApi/message.rb"
10
+ require "skypeApi/chat.rb"
11
+ require "skypeApi/chatmessage.rb"
12
+ require "skypeApi/chatmember.rb"
13
+ require "skypeApi/voicemail.rb"
14
+ require "skypeApi/sms.rb"
15
+ require "skypeApi/application.rb"
16
+ require "skypeApi/group.rb"
17
+ require "skypeApi/filetransfer.rb"
18
+ require "skypeApi/event.rb"
19
+ require "skypeApi/menuitem.rb"
20
+
21
+ class SkypeAPIError < StandardError
22
+ class Attach < SkypeAPIError; end
23
+ class Connct < SkypeAPIError; end
24
+ class Reconnect < SkypeAPIError; end
25
+ class TimeOut < SkypeAPIError; end
26
+ class API < SkypeAPIError; end
27
+ class NotImprement < SkypeAPIError; end
28
+ end
29
+
30
+ module SkypeAPI
31
+ VERSION = "0.2.1"
32
+
33
+ include SkypeAPI::Object
34
+ extend Notify
35
+ extend Get
36
+ extend SkypeAPI::ShareFunctions
37
+
38
+ P2M = Hash.new{|hash,key| hash[key] = key}
39
+ V2O = Hash.new
40
+
41
+ def self.init os=RUBY_PLATFORM.downcase
42
+ unless @inited
43
+ case os
44
+ when /mswin(?!ce)|mingw|cygwin|bccwin/
45
+ @os = SkypeAPI::OS::Windows.new
46
+ when /(mac)/
47
+ @os = SkypeAPI::OS::Mac.new
48
+ when /(linux)/
49
+ @os = SkypeAPI::OS::Linux.new
50
+ else
51
+ raise SkypeAPIError::NotImplementError,"#{os} is unknown or not support OS"
52
+ end
53
+
54
+ #SkypeAPI�̓��W���[���̂��߂ɁA�f���Q�[�^�[�ŃN���X���\�b�h�Ƃ��Ē�`�B
55
+ #SkypeAPI�����̃��\�b�h�͑S�ăN���X���\�b�h�Ȃ̂ŃA�N�Z�X�”\.
56
+ self.class.extend Forwardable
57
+ self.class.def_delegators(:@os,
58
+ :sendCMD,
59
+ :setEvent,
60
+ :addEvent,
61
+ :delEvent,
62
+ :replaceEvent,
63
+ :getEventm,
64
+ :existEvent?,
65
+ :attach,
66
+ :attachWait,
67
+ :polling,
68
+ :wait,
69
+ :close
70
+ )
71
+
72
+ #�O���p�B
73
+ self.class.__send__(:define_method, :os, Proc.new{@os})
74
+
75
+ @notify = Hash.new
76
+ @os.addNotify nil, method(:notified)
77
+ objectsInit
78
+
79
+ @inited = true
80
+ else
81
+ raise SkypeAPIErrorm,'init at onece'
82
+ end
83
+ end
84
+
85
+ def self.new
86
+ init
87
+ self
88
+ end
89
+
90
+ def self.notified msg
91
+ skypeProperty = nil
92
+ propertyReg = '(?:' + [
93
+ 'CONTACTS FOCUSED',
94
+ 'RINGTONE 1 STATUS',
95
+ 'RINGTONE 1',
96
+ '[^ ]+'
97
+ ].join(')|(?:') + ')'
98
+
99
+ if msg =~ /^(#{propertyReg}) (.+)$/m
100
+ skypeProperty = $1; value = $2
101
+ property = self::P2M[skypeProperty].to_s.downcase.to_sym if self::P2M[skypeProperty].class == Symbol
102
+ value = self::V2O[skypeProperty].call value if self::V2O[skypeProperty]
103
+
104
+ if @notify[nil]
105
+ @notify[nil][nil].call property, value if @notify[nil][nil]
106
+ @notify[nil][value].call property if @notify[nil][value]
107
+ end
108
+ if @notify[property]
109
+ @notify[property][nil].call value if @notify[property][nil]
110
+ @notify[property][value].call if @notify[property][value]
111
+ end
112
+ end
113
+ end
114
+
115
+ def self.objectsInit
116
+ [User,Profile,Call,Message,Chat,ChatMessage,ChatMember,VoiceMail,SMS,Application,Group,FileTransfer,Event,MenuItem].each do |klass|
117
+ @os.addNotify /^#{klass::OBJECT_NAME} (.+)$/m, klass.method(:notified)
118
+ end
119
+ end
120
+
121
+ def self.User() User ;end
122
+
123
+ def self.user(id) User.new(id) ; end
124
+
125
+ def self.Call() Call ; end
126
+
127
+ def self.call(id) Call.new(id) ; end
128
+
129
+ def self.Profile() Profile.new nil ; end
130
+
131
+ def self.profile() Profile.new nil ; end
132
+
133
+ def self.Chat() Chat ; end
134
+
135
+ def self.chat(id) Chat.new(id) ; end
136
+
137
+ def self.ChatMessage() ChatMessage ; end
138
+
139
+ def self.chatMessage(id) ChatMessage.new(id) ; end
140
+
141
+ def self.ChatMember() ChatMember ; end
142
+
143
+ def self.chatMember(id) ChatMember.new(id) ; end
144
+
145
+ def self.Message() Message ; end
146
+
147
+ def self.message(id) Message.new(id) ; end
148
+
149
+ def self.VoiceMail() VoiceMail ; end
150
+
151
+ def self.voiceMail(id)VoiceMail.new(id) ; end
152
+
153
+ def self.SMS() SMS ; end
154
+
155
+ def self.sms(id) SMS.new(id) ; end
156
+
157
+ def self.Application() Application ; end
158
+
159
+ def self.application(id) Application.new(id) ; end
160
+
161
+ def self.Group() Group ; end
162
+
163
+ def self.group(id) Group.new(id) ; end
164
+
165
+ def self.FileTransfer() FileTransfer ; end
166
+
167
+ def self.fileTransfer(id) FileTransfer.new(id) ; end
168
+
169
+ def self.Event() Event ; end
170
+
171
+ def self.event(id) Event.new(id) ; end
172
+
173
+ def self.MenuItem() MenuItem ; end
174
+
175
+ def self.menuItem(id) MenuItem.new(id) ; end
176
+
177
+ #General
178
+
179
+ getter :SkypeVersion, 'SKYPEVERSION'
180
+
181
+ getter :CurrentUserHandle, 'CURRENTUSERHANDLE'
182
+
183
+ getter :UserStatus, 'USERSTATUS'
184
+
185
+ def self.setUserStatus(status) sendSet "USERSTATUS", status ; end
186
+
187
+ def self.getPrivilege(privilege) sendGet("PRIVILEGE #{privilege}")._flag ; end
188
+ notice :Privilege, 'PRIVILEGE'
189
+ # privilege SkypeOut | SkypeIn | VoiceMail
190
+
191
+ getter :PredictiveDialerCountry, 'PREDICTIVE_DIALER_COUNTRY'
192
+
193
+ getter :Connstatus, 'CONNSTATUS'
194
+
195
+ getter :AudioIn, 'AUDIO_IN'
196
+
197
+ def self.setAudioIn(device) sendSet "AUDIO_IN", device ; end
198
+
199
+ getter :AudioOut, 'AUDIO_OUT'
200
+
201
+ def self.setAudioOut(device) sendSet "AUDIO_OUT", device ; end
202
+
203
+ getter :Ringer, 'RINGER'
204
+
205
+ def self.setRinger(device) sendSet("RINGER", device) ; end
206
+
207
+ getter :Mute, 'MUTE' do |str|
208
+ str._flag
209
+ end
210
+
211
+ def self.setMute(flag) sendSet("MUTE", flag._swi) ; end
212
+
213
+ def self.getAvatar(file, num=1) sendGet("AVATAR #{num} #{file}") ; end
214
+ notice :Avator, 'AVATOR'
215
+ #?
216
+
217
+ def self.setAvatar(file, idx="", num=1)
218
+ sendSet("AVATAR", "#{num} #{file}#{idx.empty? ? '' : ':'+idx.to_s}").split(' ')[1]
219
+ end
220
+
221
+ def self.getRingtone(id=1) sendGet("RINGTONE #{id}") ; end
222
+
223
+ def self.setRingtone(file, idx="", id=1) sendSet("RINGTONE","#{id} #{file}:#{idx}") ; end
224
+
225
+ notice :Ringtone, "RINGTONE 1" do |str|
226
+ num, file = str.split(' ',2)
227
+ return num.to_i, file
228
+ end
229
+ #?
230
+
231
+ def self.getRingtoneStatus(id=1)
232
+ sendCMD("GET RINGTONE #{id} STATUS") =~ /RINGTONE #{id} ((ON)|(OFF))/
233
+ $2._flag
234
+ end
235
+
236
+ notice :RingtoneStatus, "RINGTONE 1 STATUS" do |str|
237
+ str._flag
238
+ end
239
+ #?
240
+
241
+ def self.setRingtoneStatus(flag, id=1)
242
+ sendCMD("SET RINGTONE #{id} STATUS #{flag._swi}") =~ /RINGTONE #{id} ((ON)|(OFF))/
243
+ $2._flag
244
+ end
245
+
246
+ getter :PCSpeaker, 'PCSPEAKER' do |str|
247
+ str._flag
248
+ end
249
+
250
+ def self.setPCSpeaker(flag) sendSet("PCSPEAKER", flag._swi) ; end
251
+
252
+ getter :AGC, 'AGC' do |str|
253
+ str._flag
254
+ end
255
+
256
+ def self.setAGC(flag) sendSet("AGC", flag._swi) ; end
257
+
258
+ getter :AEC, 'AEC' do |str|
259
+ str._flag
260
+ end
261
+
262
+ def self.setAEC(flag) sendSet("AEC", flag._swi) ; end
263
+
264
+ def self.resetIdleTimer() sendCMD("RESETIDLETIMER") == "RESETIDLETIMER" ; end
265
+ notice :ResetIdleTimer, 'RESETIDLETIMER' #?
266
+
267
+ getter :AutoAway ,'AUTOAWAY' do |str|
268
+ str._flag
269
+ end
270
+
271
+ def self.setAutoAway(flag) sendSet('AUTOAWAY', flag._swi) ; end
272
+
273
+ getter :VideoIn, 'VIDEO_IN'
274
+
275
+ def self.setVideoIn(device) sendSet("VIDEO_IN", device) ; end
276
+
277
+ def self.ping waitLimit=nil
278
+ if waitLimit
279
+ sendBlock "PING", waitLimit
280
+ else
281
+ sendCMD("PING") == "PONG"
282
+ end
283
+ end
284
+
285
+ #UserInterFace
286
+ def self.focus() sendCMD('FOCUS') == 'FOCUS' ; end
287
+
288
+ def self.minimize() sendCMD('MINIMIZE') == 'MINIMIZE' ; end
289
+
290
+ getter :WindowState, 'WINDOWSTATE'
291
+
292
+ def self.setWindowState(state) sendSet("WINDOWSTATE", state); end
293
+
294
+ def self.open prop, *value
295
+ "OPEN #{prop} #{value.join(' ')}".rstrip == sendCMD("OPEN #{prop} #{value.join(' ')}")
296
+ end
297
+
298
+ def self.openVideoTest id=''
299
+ open 'VIDEOTEST', id
300
+ end
301
+
302
+ def self.openVoiceMail id
303
+ open 'VOICEMAIL', id
304
+ end
305
+
306
+ def self.openAddAFriend user=''
307
+ open 'ADDAFRIEND', user.to_s
308
+ end
309
+
310
+ def self.openIM user, msg=''
311
+ open 'IM', user.to_s, msg
312
+ end
313
+
314
+ def self.openChat chat
315
+ open 'CHAT', chat
316
+ end
317
+
318
+ def self.openFileTransfer users, path=nil
319
+ open 'FILETRANSFER', "#{users.join(', ')}",path ? "IN #{path}" : ''
320
+ end
321
+
322
+ def self.openLiveTab
323
+ open 'LIVETAB'
324
+ end
325
+
326
+ def self.openProfile
327
+ open 'PROFILE'
328
+ end
329
+
330
+ def self.openUserInfo user
331
+ open 'USERINFO', user.to_s
332
+ end
333
+
334
+ def self.openConference
335
+ open 'CONFERENCE'
336
+ end
337
+
338
+ def self.openSearch
339
+ open 'SEARCH'
340
+ end
341
+
342
+ def self.openOptions page=''
343
+ open 'OPTIONS', page
344
+ end
345
+
346
+ def self.openCallHistory
347
+ open 'CALLHISTORY'
348
+ end
349
+
350
+ def self.openContacts
351
+ open 'CONTACTS'
352
+ end
353
+
354
+ def self.openDialPad
355
+ open 'DIALPAD'
356
+ end
357
+
358
+ def self.openSendContacts *users
359
+ open 'SENDCONTACTS', users.join(' ')
360
+ end
361
+
362
+ def self.openBlockedUsers
363
+ open 'BLOCKEDUSERS'
364
+ end
365
+
366
+ def self.openImportContacts
367
+ open 'IMPORTCONTACTS'
368
+ end
369
+
370
+ def self.openGettingStarted
371
+ open 'GETTINGSTARTED'
372
+ end
373
+
374
+ def self.openAuthorization handle
375
+ open 'AUTHORIZATION', handle
376
+ end
377
+
378
+ def self.BTNPressed key
379
+ sendEcho "BTN_PRESSED #{key}"
380
+ end
381
+
382
+ def self.BTNReleased key
383
+ sendEcho "BTN_RELEASED #{key}"
384
+ end
385
+
386
+ getter :ContactsFocused, 'CONTACTS FOCUSED' do |str|
387
+ user str
388
+ end
389
+ #nitify?
390
+
391
+ getter :UILanguage, 'UI_LANGUAGE'
392
+
393
+ def self.setUILanguage(lang) sendSet("UI_LANGUAGE", lang); end
394
+
395
+ getter :WallPaper, 'WALLPAPER'
396
+
397
+ def self.setWallPaper(file) sendSet('WALLPAPER', file) ; end
398
+
399
+ def self.setSilentMode(flag) sendSet('SILENT_MODE', flag._swi)._flag ; end
400
+
401
+ #Search
402
+
403
+ def self.search prop, preffix=prop, val=''
404
+ ret = sendCMD "SEARCH #{prop} #{val}"
405
+ ret =~ /^#{preffix} (.+)$/
406
+ if $1
407
+ $1.split(', ')
408
+ else
409
+ []
410
+ end
411
+ end
412
+
413
+ def self.searchFriends
414
+ search('FRIENDS','USERS').map do |handle|
415
+ user(handle)
416
+ end
417
+ end
418
+
419
+ def self.searchUsers target
420
+ search('USERS','USERS',target).map do |handle|
421
+ user(handle)
422
+ end
423
+ end
424
+
425
+ def self.searchCalls target
426
+ search('CALLS','CALLS',target).map do |id|
427
+ call(id)
428
+ end
429
+ end
430
+
431
+ def self.searchActiveCalls
432
+ search('ACTIVECALLS','CALLS').map do |id|
433
+ call(id)
434
+ end
435
+ end
436
+
437
+ def self.searchMissedCalls
438
+ search('MISSEDCALLS','CALLS').map do |id|
439
+ call(id)
440
+ end
441
+ end
442
+
443
+ def self.searchSMSs
444
+ search('SMSS').map do |id|
445
+ sms(id)
446
+ end
447
+ end
448
+
449
+ def self.searchMissedSMSs
450
+ search('MISSEDSMSS','SMSS').map do |id|
451
+ sms(id)
452
+ end
453
+ end
454
+
455
+ def self.searchVoiceMails
456
+ search('VOICEMAILS').map do |id|
457
+ voiceMail(id)
458
+ end
459
+ end
460
+
461
+ def self.searchMissedVoiceMails
462
+ search('MISSEDVOICEMAILS','VOICEMAILS').map do |id|
463
+ voiceMail id
464
+ end
465
+ end
466
+
467
+ def self.searchMessages(target='')
468
+ search('MESSAGES', 'MESSAGES', target).map do |id|
469
+ message id
470
+ end
471
+ end
472
+
473
+ def self.searchMissedMessages
474
+ search('MISSEDMESSAGES','MESSAGES').map do |id|
475
+ message id
476
+ end
477
+ end
478
+
479
+ def self.searchChats
480
+ search('CHATS').map do |id|
481
+ chat id
482
+ end
483
+ end
484
+
485
+ def self.searchActiveChats
486
+ search('ACTIVECHATS','CHATS').map do |id|
487
+ chat id
488
+ end
489
+ end
490
+
491
+ def self.searchMissedChats
492
+ search('MISSEDCHATS','CHATS').map do |id|
493
+ chat id
494
+ end
495
+ end
496
+
497
+ def self.searchRecentChats
498
+ search('RECENTCHATS','CHATS').map do |id|
499
+ chat id
500
+ end
501
+ end
502
+
503
+ def self.searchBookMarkedChats
504
+ search('BOOKMARKEDCHATS','CHATS').map do |id|
505
+ chat id
506
+ end
507
+ end
508
+
509
+ def self.searchChatMessages val=''
510
+ search('CHATMESSAGES','CHATMESSAGES',val).map do |id|
511
+ chatMessage id
512
+ end
513
+ end
514
+
515
+ def self.searchMissedChatMessages
516
+ search('MISSEDCHATMESSAGES','CHATMESSAGES').map do |id|
517
+ chatMessage id
518
+ end
519
+ end
520
+
521
+ def self.searchUsersWaitingMyAuthorization
522
+ search('USERSWAITINGMYAUTHORIZATION','USERS').map do |handle|
523
+ user handle
524
+ end
525
+ end
526
+
527
+ def self.searchGroups type=''
528
+ search('GROUPS','GROUPS',type).map do |id|
529
+ group id
530
+ end
531
+ end
532
+
533
+ def self.searchFileTransfers
534
+ search('FILETRANSFERS').map do |id|
535
+ fileTransfer id
536
+ end
537
+ end
538
+
539
+ def self.searchActiveFileTransfers
540
+ search('ACTIVEFILETRANSFERS','FILETRANSFERS').map do |id|
541
+ fileTransfer id
542
+ end
543
+ end
544
+
545
+ #History
546
+
547
+ def self.clearChatHistory() sendCMD('CLEAR CHATHISTORY') == 'CLEAR CHATHISTORY' ; end
548
+
549
+ def self.clearVoicemailHistory() sendCMD('CLEAR VOICEMAILHISTORY') == 'CLEAR VOICEMAILHISTORY' ; end
550
+
551
+ def self.clearCallHistory(type, handle='')
552
+ sendCMD("CLEAR CALLHISTORY #{type} #{handle}") == "CLEAR CALLHISTORY #{type} #{handle}".rstrip
553
+ end
554
+
555
+ notice :CallHistoryChanged, 'CALLHISTORYCHANGED'
556
+ notice :IMHistoryChanged, 'IMHISTORYCHANGED'
557
+
558
+ #private :notified, :open, :search
559
+ #obs
560
+
561
+ #def openApplication appName
562
+ # return A2A.new(appName,self)
563
+ #end
564
+
565
+ #def openExtendApplication appName
566
+ # return A2AEx.new(appName,self)
567
+ #end
568
+ end
569
+
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: Ruby4Skype
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.2.1
7
+ date: 2008-02-01 00:00:00 +09:00
8
+ summary: SkypeAPI wrapper
9
+ require_paths:
10
+ - lib
11
+ email: bopper@kf7.so-net.ne.jp
12
+ homepage: http://rubyforge.org/projects/skyperapper/
13
+ rubyforge_project: Ruby4Skype
14
+ description:
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - bopper
31
+ files:
32
+ - lib/skypeapi
33
+ - lib/skypeapi/application.rb
34
+ - lib/skypeapi/call.rb
35
+ - lib/skypeapi/chat.rb
36
+ - lib/skypeapi/chatmember.rb
37
+ - lib/skypeapi/chatmessage.rb
38
+ - lib/skypeapi/event.rb
39
+ - lib/skypeapi/filetransfer.rb
40
+ - lib/skypeapi/group.rb
41
+ - lib/skypeapi/menuitem.rb
42
+ - lib/skypeapi/message.rb
43
+ - lib/skypeapi/object.rb
44
+ - lib/skypeapi/os.rb
45
+ - lib/skypeapi/profile.rb
46
+ - lib/skypeapi/sharefunctions.rb
47
+ - lib/skypeapi/sms.rb
48
+ - lib/skypeapi/user.rb
49
+ - lib/skypeapi/voicemail.rb
50
+ - lib/skypeapi.rb
51
+ test_files: []
52
+
53
+ rdoc_options: []
54
+
55
+ extra_rdoc_files: []
56
+
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ requirements:
62
+ - swin
63
+ dependencies: []
64
+