Ruby4Skype 0.2.3 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +3 -0
- data/README +14 -0
- data/Rakefile +67 -0
- data/lib/skypeapi.rb +570 -509
- data/lib/skypeapi/application.rb +79 -77
- data/lib/skypeapi/call.rb +243 -230
- data/lib/skypeapi/chat.rb +162 -172
- data/lib/skypeapi/chatmember.rb +26 -28
- data/lib/skypeapi/chatmessage.rb +81 -65
- data/lib/skypeapi/error.rb +8 -0
- data/lib/skypeapi/event.rb +25 -26
- data/lib/skypeapi/filetransfer.rb +47 -28
- data/lib/skypeapi/group.rb +72 -73
- data/lib/skypeapi/menuitem.rb +44 -44
- data/lib/skypeapi/message.rb +39 -41
- data/lib/skypeapi/object.rb +246 -82
- data/lib/skypeapi/os/etc.rb +48 -98
- data/lib/skypeapi/os/mac.rb +92 -4
- data/lib/skypeapi/os/notifier.rb +31 -0
- data/lib/skypeapi/os/window_event_queue.rb +198 -0
- data/lib/skypeapi/os/window_messagehandler.rb +120 -0
- data/lib/skypeapi/os/windows.rb +170 -306
- data/lib/skypeapi/profile.rb +190 -120
- data/lib/skypeapi/sharefunctions.rb +31 -23
- data/lib/skypeapi/sms.rb +87 -67
- data/lib/skypeapi/user.rb +159 -99
- data/lib/skypeapi/version.rb +3 -3
- data/lib/skypeapi/voicemail.rb +59 -52
- data/spec/matcher_be_boolean.rb +10 -0
- data/spec/skypeapi/application_spec.rb +76 -0
- data/spec/skypeapi/chat_spec.rb +356 -0
- data/spec/skypeapi/chatmember_spec.rb +42 -0
- data/spec/skypeapi/chatmessage_spec.rb +89 -0
- data/spec/skypeapi/event_spec.rb +31 -0
- data/spec/skypeapi/filetransfer_spec.rb +67 -0
- data/spec/skypeapi/group_spec.rb +16 -0
- data/spec/skypeapi/menuitem_spec.rb +37 -0
- data/spec/skypeapi/os/windows_spec.rb +305 -0
- data/spec/skypeapi/profile_spec.rb +22 -0
- data/spec/skypeapi/user_spec.rb +25 -0
- data/spec/skypeapi_spec.rb +528 -0
- metadata +32 -12
- data/lib/skypeapi/os/timer.rb +0 -108
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'skypeapi'
|
2
|
+
require 'timeout'
|
3
|
+
|
4
|
+
describe SkypeAPI::Event do
|
5
|
+
before :all do
|
6
|
+
SkypeAPI.init
|
7
|
+
SkypeAPI.start_messageloop
|
8
|
+
SkypeAPI.attach_wait
|
9
|
+
end
|
10
|
+
|
11
|
+
after :all do
|
12
|
+
SkypeAPI.close
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should event create" do
|
16
|
+
pending 'skype event obs?'
|
17
|
+
flag = false
|
18
|
+
event = SkypeAPI::Event.create('testEvent','testEvent','Testhint') do
|
19
|
+
flag = true
|
20
|
+
end
|
21
|
+
event.should be_instance_of SkypeAPI::Event
|
22
|
+
|
23
|
+
puts 'click testEvent'
|
24
|
+
|
25
|
+
timeout(60){sleep 1 until flag}
|
26
|
+
|
27
|
+
event.delete.should be_true
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
require 'skypeapi'
|
5
|
+
|
6
|
+
describe SkypeAPI::FileTransfer do
|
7
|
+
before :all do
|
8
|
+
SkypeAPI.init
|
9
|
+
SkypeAPI.start_messageloop
|
10
|
+
SkypeAPI.attach_wait
|
11
|
+
end
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
@filetransfer = SkypeAPI.searchFileTransfers[0]
|
15
|
+
pending 'a file_trasfer is nothing.' unless @filetransfer
|
16
|
+
end
|
17
|
+
|
18
|
+
after :all do
|
19
|
+
SkypeAPI.close
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'get_type should match /(INCOMING)|(OUTGOING)/' do
|
23
|
+
@filetransfer.get_type.should match /(INCOMING)|(OUTGOING)/
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'get_status should match /(NEW)|(WAITING_FOR_ACCEPT)|(CONNECTING)|(TRANSFERRING)|(TRANSFERRING_OVER_RELAY)|(PAUSED)|(REMOTELY_PAUSED)|(CANCELLED)|(COMPLETED)|(FAILED)/' do
|
27
|
+
@filetransfer.get_status.should match /(NEW)|(WAITING_FOR_ACCEPT)|(CONNECTING)|(TRANSFERRING)|(TRANSFERRING_OVER_RELAY)|(PAUSED)|(REMOTELY_PAUSED)|(CANCELLED)|(COMPLETED)|(FAILED)/
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'get_failure_reason /(SENDER_NOT_AUTHORIZED)|(REMOTELY_CANCELLED)|(FAILED_READ)|(FAILED_REMOTE_READ)|(FAILED_WRITE)|(FAILED_REMOTE_WRITE)|(REMOTE_DOES_NOT_SUPPORT_FT)|(REMOTE_OFFLINE_FOR_TOO_LONG)|(UNKNOWN)/' do
|
31
|
+
@filetransfer.get_failure_reason.should match /(SENDER_NOT_AUTHORIZED)|(REMOTELY_CANCELLED)|(FAILED_READ)|(FAILED_REMOTE_READ)|(FAILED_WRITE)|(FAILED_REMOTE_WRITE)|(REMOTE_DOES_NOT_SUPPORT_FT)|(REMOTE_OFFLINE_FOR_TOO_LONG)|(UNKNOWN)/
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'get_partner should be instance of User' do
|
35
|
+
@filetransfer.get_partner.should be_instance_of SkypeAPI::User
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'get_partner_dispname should be instance of String' do
|
39
|
+
@filetransfer.get_partner_dispname.should be_instance_of String
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'get_start_time should be instance of Time' do
|
43
|
+
@filetransfer.get_start_time.should be_instance_of Time
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'get_finish_time should be instance of Time' do
|
47
|
+
@filetransfer.get_finish_time.should be_instance_of Time
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'get_file_path should be instance of String' do
|
51
|
+
@filetransfer.get_file_path.should be_instance_of String
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'get_file_size should kind of Numeric' do
|
55
|
+
@filetransfer.get_file_size.should be_kind_of Numeric
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'get_bytes_per_second should be kind of Numeric' do
|
59
|
+
@filetransfer.get_bytes_per_second.should be_kind_of Numeric
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'get_bytes_transferred should be kind of Numeric' do
|
63
|
+
@filetransfer.get_bytes_transferred.should be_kind_of Numeric
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
require 'skypeapi'
|
5
|
+
|
6
|
+
describe SkypeAPI::Group do
|
7
|
+
before(:each) do
|
8
|
+
pending 'constructor is broken'
|
9
|
+
@group = Group.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should desc" do
|
13
|
+
# TODO
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'skypeapi'
|
2
|
+
|
3
|
+
describe SkypeAPI::MenuItem do
|
4
|
+
before :all do
|
5
|
+
SkypeAPI.init
|
6
|
+
SkypeAPI.start_messageloop
|
7
|
+
SkypeAPI.attach_wait
|
8
|
+
end
|
9
|
+
|
10
|
+
after :all do
|
11
|
+
SkypeAPI.close
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should,,," do
|
15
|
+
pending 'menu_item obs?'
|
16
|
+
flag = false
|
17
|
+
menuitem = SkypeAPI::MenuItem.create(:id => 'testMenu', :context => 'CONTACT', :caption => 'testMenu') do |instance, context, user, context_id|
|
18
|
+
menuitem.should == instance
|
19
|
+
context.should be_instance_of String
|
20
|
+
user.should be_instance_of SkypeAPI::User
|
21
|
+
context_id.should be_nil
|
22
|
+
flag = true
|
23
|
+
end
|
24
|
+
|
25
|
+
puts "click user context menu changeCap"
|
26
|
+
|
27
|
+
menuitem.should be_instance_of SkypeAPI::MenuItem
|
28
|
+
menuitem.setCaption('changeCap').should be_true
|
29
|
+
menuitem.setHint('changeHint').should be_true
|
30
|
+
menuitem.setEnabled(false).should be_true
|
31
|
+
menuitem.setEnabled(true).should be_true
|
32
|
+
timeout(60){sleep until flag}
|
33
|
+
menuitem.delete.should be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,305 @@
|
|
1
|
+
# To change this template, choose Tools | Templates
|
2
|
+
# and open the template in the editor.
|
3
|
+
|
4
|
+
require 'skypeapi/os/etc'
|
5
|
+
require 'skypeapi/os/windows'
|
6
|
+
|
7
|
+
Thread.abort_on_exception = true
|
8
|
+
|
9
|
+
describe SkypeAPI::OS::Windows do
|
10
|
+
describe 'before attach' do
|
11
|
+
describe 'attach' do
|
12
|
+
before(:each) do
|
13
|
+
@message = Array.new
|
14
|
+
@win = SkypeAPI::OS::Windows.new
|
15
|
+
@win.set_notify_selector{ |msg| @message.push msg }
|
16
|
+
@win.start_messageloop
|
17
|
+
end
|
18
|
+
|
19
|
+
after(:each) do
|
20
|
+
@win.close
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should notified 3 message" do
|
24
|
+
@win.attach_wait
|
25
|
+
sleep 1
|
26
|
+
@message[0].should match(/^CONNSTATUS /)
|
27
|
+
@message[1].should match(/^CURRENTUSERHANDLE /)
|
28
|
+
@message[2].should match(/^USERSTATUS /)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should many attach and close" do
|
32
|
+
@win.close
|
33
|
+
10.times do |i|
|
34
|
+
@win = SkypeAPI::OS::Windows.new
|
35
|
+
@win.set_notify_selector{ |msg| @message.push msg }
|
36
|
+
@win.start_messageloop
|
37
|
+
@win.attach_wait
|
38
|
+
@win.close
|
39
|
+
end
|
40
|
+
@win = SkypeAPI::OS::Windows.new
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should call attached event" do
|
44
|
+
flag = false
|
45
|
+
@win.add_event(:attached){ flag=true }
|
46
|
+
@win.attach
|
47
|
+
sleep 3
|
48
|
+
flag.should be_true
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "windows event queue process on main thread" do
|
54
|
+
before(:each) do
|
55
|
+
@win = SkypeAPI::OS::Windows.new
|
56
|
+
end
|
57
|
+
|
58
|
+
after(:each) do
|
59
|
+
@win.close
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should attach and close" do
|
63
|
+
i = 0
|
64
|
+
@win.set_notify_selector do |msg|
|
65
|
+
i+=1
|
66
|
+
@win.close if i >= 3
|
67
|
+
end
|
68
|
+
f = false
|
69
|
+
#@win.add_event(:attached){f=true}
|
70
|
+
@win.attach_wait
|
71
|
+
timeout(10) do
|
72
|
+
@win.messageloop
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "after attach" do
|
82
|
+
|
83
|
+
def chat_send id, msg
|
84
|
+
@win.invoke("CHAT CREATE #{id}") =~ /^CHAT (.+?) /
|
85
|
+
chat_id = $1
|
86
|
+
chat_id.should match /^#bopper-\/\$#{id};.+$/
|
87
|
+
@win.invoke("CHATMESSAGE #{chat_id} #{msg}") =~ /CHATMESSAGE (\d+?) STATUS SENDING/
|
88
|
+
chat_message_id = $1
|
89
|
+
chat_message_id.should match /^\d+$/
|
90
|
+
@win.invoke("GET CHATMESSAGE #{chat_message_id} BODY").should == "CHATMESSAGE #{chat_message_id} BODY #{msg}"
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
before :each do
|
95
|
+
@win = SkypeAPI::OS::Windows.new
|
96
|
+
@win.start_messageloop
|
97
|
+
@win.attach_wait
|
98
|
+
end
|
99
|
+
|
100
|
+
after :each do
|
101
|
+
@win.close
|
102
|
+
end
|
103
|
+
|
104
|
+
describe 'invoke' do
|
105
|
+
|
106
|
+
def get_skype_version
|
107
|
+
@win.invoke('GET SKYPEVERSION').should match(/^SKYPEVERSION \d+\.\d+\.\d+\.\d+$/)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "invoke GET SKYPEVERSION should match SKYPEVERSION num.num.num.num" do
|
111
|
+
get_skype_version
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should invoke many times" do
|
115
|
+
10.times do |i|
|
116
|
+
get_skype_version
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
describe 'notify' do
|
123
|
+
|
124
|
+
#it "sleeped notify thread by invoke should wake up" do
|
125
|
+
it "" do
|
126
|
+
i = 0
|
127
|
+
@win.set_notify_selector do |msg|
|
128
|
+
if msg =~ /^CHATMESSAGE \d+ STATUS SENDING/ and i < 10
|
129
|
+
i+=1
|
130
|
+
end
|
131
|
+
end
|
132
|
+
10.times{ chat_send('echo123', 'this is a notify test') }
|
133
|
+
timeout(6) do
|
134
|
+
sleep 1 until i >= 9
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|
139
|
+
|
140
|
+
describe 'recovery timeout' do
|
141
|
+
it '' do
|
142
|
+
count = 0
|
143
|
+
@win.add_hook :sent do |msg|
|
144
|
+
p "#{Time.now.to_i}s>#{msg}"
|
145
|
+
count += 1 if msg =~ /SEARCH USERS foobarsdfjweiorj/
|
146
|
+
end
|
147
|
+
@win.add_hook :received do |msg|
|
148
|
+
p "#{Time.now.to_i}r>#{msg}"
|
149
|
+
end
|
150
|
+
@win.__send__(:invoke_block,"SEARCH USERS foobarsdfjweiorj",1).should be_instance_of String
|
151
|
+
count.should == 1
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe 'detach and reattach' do
|
156
|
+
before do
|
157
|
+
pending 'hogehoge'
|
158
|
+
end
|
159
|
+
|
160
|
+
describe 'Skype shutdonw' do
|
161
|
+
before do
|
162
|
+
pending 'hogehoge'
|
163
|
+
end
|
164
|
+
|
165
|
+
end
|
166
|
+
describe 'Skype killed' do
|
167
|
+
before do
|
168
|
+
pending 'hogehoge'
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
describe 'multi threads' do
|
175
|
+
|
176
|
+
describe "many create chats" do
|
177
|
+
|
178
|
+
before :each do
|
179
|
+
@log = Array.new
|
180
|
+
@win.add_hook :sent do |msg|
|
181
|
+
@log.push "#{Time.now.to_i}s>#{msg}"
|
182
|
+
end
|
183
|
+
@win.add_hook :received do |msg|
|
184
|
+
@log.push "#{Time.now.to_i}r>#{msg}"
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
it "should not error" do
|
189
|
+
pending 'spend long time'
|
190
|
+
a = 0
|
191
|
+
3.times do |tn|
|
192
|
+
Thread.new(tn) do |n|
|
193
|
+
10000.times do |i|
|
194
|
+
begin
|
195
|
+
@win.invoke("CHAT CREATE echo123").should match(/^CHAT .+? STATUS .+?$/)
|
196
|
+
rescue TimeoutError => e
|
197
|
+
puts @log
|
198
|
+
raise e
|
199
|
+
end
|
200
|
+
end
|
201
|
+
a += 1
|
202
|
+
end
|
203
|
+
end
|
204
|
+
sleep 1 until a >= 3
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe "notify thread" do
|
209
|
+
before :each do
|
210
|
+
@win.add_hook :sent do |msg|
|
211
|
+
puts "#{Time.now.to_i}s>#{msg}"
|
212
|
+
end
|
213
|
+
@win.add_hook :received do |msg|
|
214
|
+
puts "#{Time.now.to_i}r>#{msg}"
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should invoke in notify" do
|
219
|
+
#pending
|
220
|
+
i = 0
|
221
|
+
@win.set_notify_selector do |msg|
|
222
|
+
if msg =~ /CHATMESSAGE (\d+) STATUS RECEIVED/
|
223
|
+
cid=$1
|
224
|
+
if @win.invoke("GET CHATMESSAGE #{cid} FROM_HANDLE") == "CHATMESSAGE #{cid} FROM_HANDLE ehco123"
|
225
|
+
i+=1
|
226
|
+
chat_send 'echo123', 'send from notify thread'
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
chat_send 'echo123', 'send from main thread'
|
232
|
+
|
233
|
+
sleep 1 until i < 30#00
|
234
|
+
end
|
235
|
+
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
describe 'when ctrl+c keydown' do
|
240
|
+
it 'should raise interrupt' do
|
241
|
+
pending 'how should I write this test?'
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
describe 'endurance' do
|
246
|
+
before(:each) do
|
247
|
+
@win.add_hook :sent do |msg|
|
248
|
+
puts "#{Time.now.to_i}s>#{msg}"
|
249
|
+
end
|
250
|
+
@win.add_hook :received do |msg|
|
251
|
+
puts "#{Time.now.to_i}r>#{msg}"
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
it 'should send tooo many chat messages by 3 threads' do
|
256
|
+
pending 'buzy'
|
257
|
+
@win.set_notify_selector{ |msg| }#p(msg) end
|
258
|
+
|
259
|
+
result = Array.new(3,0)
|
260
|
+
f = true
|
261
|
+
3.times do |t_num|
|
262
|
+
Thread.new(t_num) do |t_num|
|
263
|
+
while f
|
264
|
+
chat_send 'echo123', "this is a endurance test #{result[t_num]} by #{t_num} thread."
|
265
|
+
p [result[t_num],t_num]
|
266
|
+
result[t_num]+=1
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
#sleep 60*10
|
271
|
+
i =0
|
272
|
+
while true
|
273
|
+
i+=10
|
274
|
+
p [i,result]
|
275
|
+
sleep 10
|
276
|
+
end
|
277
|
+
f = false
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'should send too many chat messages while 3 days' do
|
281
|
+
pending 'bore'
|
282
|
+
i = 0
|
283
|
+
# @win.set_notify_selector do |msg|
|
284
|
+
# if msg =~ /^CHATMESSAGE \d+ STATUS SENDING/
|
285
|
+
# chat_send('echo123', "this is a endurance test #{i}")
|
286
|
+
# i+=1
|
287
|
+
# p i
|
288
|
+
# end
|
289
|
+
# end
|
290
|
+
|
291
|
+
@win.set_notify_selector{|msg|}
|
292
|
+
|
293
|
+
while true
|
294
|
+
chat_send('echo123', "this is a first endurance test #{i}")
|
295
|
+
i+=1
|
296
|
+
p i
|
297
|
+
end
|
298
|
+
#start_time = Time.now
|
299
|
+
#sleep 10 while Time.now - start_time < 60*30#60*60*24*3
|
300
|
+
end
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
|