Ruby4Skype 0.2.3 → 0.3.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/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
data/lib/skypeapi/object.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
require 'date'
|
2
|
+
require 'forwardable'
|
2
3
|
|
3
|
-
module SkypeAPI
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
#������R�s�y�U�݁B
|
4
|
+
module SkypeAPI
|
5
|
+
class AbstractObject #:nodoc: all
|
8
6
|
module Notify
|
9
7
|
def setNotify property=nil,value=nil, block=Proc.new
|
10
8
|
property = property.to_s.downcase.to_sym if property
|
@@ -12,15 +10,17 @@ module SkypeAPI
|
|
12
10
|
@notify[property] = Hash.new unless @notify[property]
|
13
11
|
@notify[property][value] = block
|
14
12
|
end
|
15
|
-
|
13
|
+
alias set_notify setNotify
|
14
|
+
|
16
15
|
def delNotify property=nil,value=nil
|
17
16
|
@notify[property].delete value
|
18
17
|
end
|
19
|
-
|
18
|
+
alias del_notify delNotify
|
19
|
+
|
20
20
|
def notify
|
21
21
|
@notify
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def notified instance, property,value
|
25
25
|
if @notify[nil]
|
26
26
|
@notify[nil][nil].call instance, property, value if @notify[nil][nil]
|
@@ -34,99 +34,263 @@ module SkypeAPI
|
|
34
34
|
alias set_notify setNotify
|
35
35
|
alias del_notify delNotify
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
module Get
|
39
|
-
def getter
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
39
|
+
# def getter method_name, skypeProperty=method_name.to_s.upcase, &callBack
|
40
|
+
# define_method = self == SkypeAPI ? self.class.method(:define_method) : method(:define_method)
|
41
|
+
# alias_method = self == SkypeAPI ? self.class.method(:alias_method) : method(:alias_method)
|
42
|
+
#
|
43
|
+
# define_method.call 'get' + method_name.to_s do
|
44
|
+
# str = invoke_get skypeProperty
|
45
|
+
# callBack ? callBack.call(str) : str
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# understyle_method_name = 'get'+method_name.to_s.gsub(/[A-Z]+/){ |s| '_' + s.downcase}
|
49
|
+
# alias_method.call(understyle_method_name, 'get'+method_name.to_s)
|
50
|
+
#
|
51
|
+
# notice method_name, skypeProperty, &callBack
|
52
|
+
# end
|
53
|
+
|
54
|
+
def notice methodName, skypeProperty, &callBack
|
55
|
+
if SkypeAPI.kind_of? self
|
56
|
+
SkypeAPI.property2symbol[skypeProperty] = methodName.to_sym
|
57
|
+
SkypeAPI.property2callback[skypeProperty] = callBack if callBack
|
58
|
+
else
|
59
|
+
property2symbol[skypeProperty] = methodName.to_sym
|
60
|
+
property2callback[skypeProperty] = callBack if callBack
|
44
61
|
end
|
45
|
-
|
46
|
-
#code4doc
|
47
|
-
#className = (defined? self::OBJECT_NAME) ? self::OBJECT_NAME : ''#'SkypeAPI'
|
48
|
-
#puts "'" + className + "::" + 'get' + methodName.to_s + "',"
|
49
|
-
|
50
|
-
self::P2M[skypeProperty] = methodName.to_sym
|
51
|
-
self::V2O[skypeProperty] = callBack if callBack
|
52
62
|
end
|
53
|
-
|
54
|
-
def
|
55
|
-
|
56
|
-
self::V2O[methodName] = block if block
|
63
|
+
|
64
|
+
def def_parser sym, property=sym.to_s.upcase, &callback
|
65
|
+
notice sym, property, &callback
|
57
66
|
end
|
67
|
+
|
68
|
+
attr_reader :property2symbol, :property2callback
|
58
69
|
end
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
#�p�������ނ�S������B@@instance[class][id of instance]
|
68
|
-
@@instance = Hash.new do |hash,key|
|
69
|
-
hash[key] = Hash.new
|
70
|
+
|
71
|
+
module Parser
|
72
|
+
def parse sym, res
|
73
|
+
if self == SkypeAPI
|
74
|
+
SkypeAPI.property2callback[SkypeAPI.property2symbol.index(sym)].call(res)
|
75
|
+
else
|
76
|
+
self.class.property2callback[self.class.property2symbol.index(sym)].call(res)
|
77
|
+
end
|
70
78
|
end
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
#
|
76
|
-
|
77
|
-
#
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
private :parse
|
80
|
+
end
|
81
|
+
|
82
|
+
module Invokers
|
83
|
+
#private
|
84
|
+
|
85
|
+
#invoke_echo "CREATE APPLICATION #{@appName}"
|
86
|
+
#CREATE APPLICATION #{@appName} -> CREATE APPLICATION #{@appName}
|
87
|
+
def invoke_echo cmd
|
88
|
+
begin
|
89
|
+
invoke(cmd) == cmd
|
90
|
+
rescue SkypeAPI::Error::API => e
|
91
|
+
e.backtrace.shift
|
92
|
+
e.backtrace.shift
|
93
|
+
raise e
|
82
94
|
end
|
83
|
-
sub.instance_variable_set :@notify, Hash.new
|
84
95
|
end
|
96
|
+
|
97
|
+
#invoke_one "GET CHATMESSAGE #{@id} BODY", "CHATMESSAGE #{@id} BODY"
|
98
|
+
#GET CHATMESSAGE #{@id} BODY -> CHATMESSAGE #{@id} BODY (.+)
|
99
|
+
def invoke_one cmd, regExp=cmd
|
100
|
+
regExp.gsub!(/[\^$.\\\[\]*+{}?|()]/) do |char|
|
101
|
+
"\\" + char
|
102
|
+
end
|
103
|
+
begin
|
104
|
+
invoke(cmd) =~ /^#{regExp} (.*)$/m
|
105
|
+
rescue SkypeAPI::Error::API => e
|
106
|
+
e.backtrace.shift
|
107
|
+
e.backtrace.shift
|
108
|
+
raise e
|
109
|
+
end
|
110
|
+
return $1
|
111
|
+
end
|
112
|
+
|
113
|
+
#invoke_get("GET USER #{@handle} SkypeOut")
|
114
|
+
#GET USER #{@handle} SkypeOut -> USER #{@handle} SkypeOut (.+)
|
115
|
+
def invoke_get prop, value=nil
|
116
|
+
cmd = "GET #{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{@id ? @id.to_s+' ' : ''}#{prop}#{value ? ' ' + value : ''}"
|
117
|
+
reg = "#{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{@id ? @id.to_s+' ' : ''}#{prop}#{value ? ' ' + value : ''}".gsub(/[\^$.\\\[\]*+{}?|()]/) do |char|
|
118
|
+
"\\" + char
|
119
|
+
end
|
120
|
+
begin
|
121
|
+
invoke(cmd) =~ /^#{reg} (.*)$/m
|
122
|
+
rescue SkypeAPI::Error::API => e
|
123
|
+
e.backtrace.shift
|
124
|
+
e.backtrace.shift
|
125
|
+
raise e
|
126
|
+
end
|
127
|
+
return $1
|
128
|
+
end
|
129
|
+
|
130
|
+
def invoke_set prop,value=nil
|
131
|
+
cmd = "SET #{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{@id ? @id.to_s + ' ' : ''}#{prop}#{value ? ' '+value.to_s : '' }"
|
132
|
+
reg = "#{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{@id ? @id.to_s + ' ' : ''}#{prop}"
|
133
|
+
begin
|
134
|
+
str = invoke_one cmd, reg
|
135
|
+
rescue SkypeAPI::Error::API => e
|
136
|
+
e.backtrace.shift
|
137
|
+
e.backtrace.shift
|
138
|
+
raise e
|
139
|
+
end
|
140
|
+
#p [self,self.class]
|
141
|
+
#if self.class == Module
|
142
|
+
# @property2callcack[prop] ? @property2callback[prop].call(str) : str
|
143
|
+
#else
|
144
|
+
# self[prop] ? self.class::V2O[prop].call(str) : str
|
145
|
+
#end
|
146
|
+
str
|
147
|
+
end
|
148
|
+
|
149
|
+
def invoke_alter prop, value=nil
|
150
|
+
cmd = "ALTER #{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{@id ? @id.to_s + ' ' : ''}#{prop}#{value ? ' '+value.to_s : '' }"
|
151
|
+
#res = "ALTER #{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{@id ? @id.to_s + ' ' : ''}#{prop}"
|
152
|
+
#reg.gsub!(/[\^$.\\\[\]*+{}?|()]/) do |char|
|
153
|
+
# "\\" + char
|
154
|
+
#end
|
155
|
+
#res = "ALTER #{defined?(self.class::OBJECT_NAME) ? self.class::OBJECT_NAME + ' ' : ''}#{prop}"
|
156
|
+
begin
|
157
|
+
invoke(cmd)# == res
|
158
|
+
rescue SkypeAPI::Error::API => e
|
159
|
+
e.backtrace.shift
|
160
|
+
e.backtrace.shift
|
161
|
+
raise e
|
162
|
+
end
|
163
|
+
true
|
164
|
+
end
|
165
|
+
|
166
|
+
#def sendAlterWithID prop, value=nil
|
167
|
+
# str = invoke_one "ALTER #{self.class::OBJECT_NAME} #{@id} #{prop}#{value ? ' '+value.to_s : '' }","ALTER #{self.class::OBJECT_NAME} #{@id} #{prop}"
|
168
|
+
# self.class::V2O[self.class::P2M[prop]] ? self.class::V2O[self.class::P2M[prop]].call(str) : str
|
169
|
+
#end
|
170
|
+
end
|
171
|
+
|
172
|
+
extend Notify
|
173
|
+
extend Forwardable
|
174
|
+
extend Get
|
175
|
+
include Parser
|
176
|
+
include Notify
|
177
|
+
include Invokers
|
85
178
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
179
|
+
@@instance = Hash.new do |hash,key|
|
180
|
+
hash[key] = Hash.new
|
181
|
+
end
|
182
|
+
@@skypeApi = SkypeAPI
|
183
|
+
|
184
|
+
def self.inherited sub
|
185
|
+
if self == AbstractObject
|
186
|
+
sub.instance_variable_set :@property2symbol, Hash.new{|hash,key| hash[key] = key}
|
187
|
+
sub.instance_variable_set :@property2callback, Hash.new
|
188
|
+
end
|
189
|
+
sub.instance_variable_set :@notify, Hash.new
|
190
|
+
end
|
191
|
+
|
192
|
+
def self.notified msg
|
193
|
+
if msg =~ /^([^ ]+) ([^ ]+) (.*)$/m
|
194
|
+
id = $1; skypeProperty = $2; value = $3
|
195
|
+
instance = new id
|
196
|
+
property = @property2symbol[skypeProperty].to_s.downcase.to_sym if @property2symbol[skypeProperty].class == Symbol
|
197
|
+
value = @property2callback[skypeProperty].call value if @property2callback[skypeProperty]
|
198
|
+
|
94
199
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
end
|
99
|
-
if @notify[property]
|
100
|
-
@notify[property][nil].call instance, value if @notify[property][nil]
|
101
|
-
@notify[property][value].call instance if @notify[property][value]
|
102
|
-
end
|
103
|
-
@@instance[self][id].notified instance, property, value if @@instance[self][id]
|
200
|
+
if @notify[nil]
|
201
|
+
@notify[nil][nil].call instance, property, value if @notify[nil][nil]
|
202
|
+
@notify[nil][value].call instance, property if @notify[nil][value]
|
104
203
|
end
|
204
|
+
if @notify[property]
|
205
|
+
@notify[property][nil].call instance, value if @notify[property][nil]
|
206
|
+
@notify[property][value].call instance if @notify[property][value]
|
207
|
+
end
|
208
|
+
@@instance[self][id].notified instance, property, value if @@instance[self][id]
|
105
209
|
end
|
210
|
+
end
|
106
211
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
212
|
+
def self.new id
|
213
|
+
if @@instance[self][id]
|
214
|
+
return @@instance[self][id]
|
215
|
+
else
|
216
|
+
instance = super id
|
217
|
+
instance.instance_variable_set(:@notify, Hash.new do |h,k|
|
113
218
|
h[k] = Hash.new
|
114
219
|
end)
|
115
|
-
|
116
|
-
|
117
|
-
end
|
220
|
+
@@instance[self][id] = instance
|
221
|
+
return instance
|
118
222
|
end
|
223
|
+
end
|
119
224
|
|
120
|
-
|
121
|
-
|
122
|
-
|
225
|
+
def initialize id
|
226
|
+
@id = id
|
227
|
+
end
|
123
228
|
|
124
|
-
|
125
|
-
|
126
|
-
|
229
|
+
def to_s
|
230
|
+
@id.to_s
|
231
|
+
end
|
127
232
|
|
128
|
-
|
233
|
+
def_delegators :@@skypeApi, :invoke
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
|
238
|
+
class NilClass
|
239
|
+
def _flag
|
240
|
+
nil
|
241
|
+
end
|
242
|
+
|
243
|
+
def _swi
|
244
|
+
nil
|
245
|
+
end
|
246
|
+
|
247
|
+
def _str
|
248
|
+
""
|
249
|
+
end
|
250
|
+
|
251
|
+
def _int
|
252
|
+
nil
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
class String
|
257
|
+
def _flag
|
258
|
+
case self
|
259
|
+
when /^(TRUE)|(ON)$/i
|
260
|
+
return true
|
261
|
+
when /^(FALSE)|(OFF)$/i
|
262
|
+
return false
|
263
|
+
else
|
264
|
+
self
|
129
265
|
end
|
130
|
-
|
266
|
+
end
|
267
|
+
|
268
|
+
def _int
|
269
|
+
self.empty? ? nil : self.to_i
|
270
|
+
end
|
271
|
+
|
272
|
+
def _str
|
273
|
+
self
|
131
274
|
end
|
132
275
|
end
|
276
|
+
|
277
|
+
class TrueClass
|
278
|
+
def _swi
|
279
|
+
"ON"
|
280
|
+
end
|
281
|
+
|
282
|
+
def _str
|
283
|
+
"TRUE"
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
class FalseClass
|
288
|
+
def _swi
|
289
|
+
"OFF"
|
290
|
+
end
|
291
|
+
|
292
|
+
def _str
|
293
|
+
"FALSE"
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
data/lib/skypeapi/os/etc.rb
CHANGED
@@ -1,132 +1,82 @@
|
|
1
|
+
require 'skypeapi/error'
|
2
|
+
|
1
3
|
module SkypeAPI
|
2
4
|
module OS
|
3
|
-
|
4
|
-
def invoke cmd, method=nil, &block
|
5
|
-
method = method ? method : block
|
6
|
-
if method
|
7
|
-
invoke_callback cmd do |res|
|
8
|
-
check_response res,cmd
|
9
|
-
method.call res
|
10
|
-
end
|
11
|
-
return true
|
12
|
-
else
|
13
|
-
begin
|
14
|
-
return check_response(invoke_block(cmd), cmd)
|
15
|
-
rescue SkypeAPIError
|
16
|
-
raise $!, caller(1)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
#����reg==nil�ŁA���̑��ƌ���㩁B
|
22
|
-
def add_notify reg, block=Proc.new
|
23
|
-
@notify[reg] = block
|
24
|
-
end
|
5
|
+
class Abstruct
|
25
6
|
|
26
|
-
def
|
27
|
-
@
|
7
|
+
def initialize
|
8
|
+
@send_count = 0
|
9
|
+
@hook = Hash.new do |h,k|
|
10
|
+
h[k] = Array.new
|
11
|
+
end
|
12
|
+
@attached = false
|
13
|
+
@first_attached = true
|
14
|
+
@raise_when_detached = false
|
28
15
|
end
|
29
|
-
|
30
|
-
def
|
31
|
-
@
|
16
|
+
|
17
|
+
def add_hook sym, block=Proc.new
|
18
|
+
@hook[sym].push block
|
32
19
|
block
|
33
20
|
end
|
34
|
-
|
35
|
-
|
36
|
-
# @event[sym] = Array.new
|
37
|
-
# add_event sym, block
|
38
|
-
#end
|
39
|
-
|
40
|
-
def del_event sym, block=nil
|
21
|
+
|
22
|
+
def del_hook sym, block=nil
|
41
23
|
unless block
|
42
|
-
@
|
24
|
+
@hook[sym] = Array.new
|
43
25
|
else
|
44
|
-
@
|
26
|
+
@hook[sym].delete block
|
45
27
|
end
|
46
28
|
end
|
47
|
-
|
48
|
-
def
|
49
|
-
if @
|
29
|
+
|
30
|
+
def exist_hook? sym
|
31
|
+
if @hook[sym].length > 0
|
50
32
|
return true
|
51
33
|
else
|
52
34
|
return false
|
53
35
|
end
|
54
36
|
end
|
55
|
-
|
56
|
-
def
|
57
|
-
@
|
58
|
-
end
|
59
|
-
|
60
|
-
def
|
61
|
-
@
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
37
|
+
|
38
|
+
def get_hook sym
|
39
|
+
@hook[sym]
|
40
|
+
end
|
41
|
+
|
42
|
+
def call_hook sym,*args
|
43
|
+
@hook[sym].each{ |h| h.call *args }
|
44
|
+
end
|
45
|
+
private :call_hook
|
46
|
+
|
47
|
+
def invoke cmd
|
48
|
+
begin
|
49
|
+
check_response(invoke_block(cmd), cmd)
|
50
|
+
rescue SkypeAPI::Error::API => e
|
51
|
+
e.backtrace.shift
|
52
|
+
e.backtrace.shift
|
53
|
+
raise e
|
67
54
|
end
|
68
55
|
end
|
56
|
+
|
57
|
+
def invoke_callback cmd, callback = Proc.new
|
58
|
+
end
|
69
59
|
|
70
|
-
|
60
|
+
def invoke_block cmd
|
61
|
+
end
|
71
62
|
|
72
|
-
def check_response res,cmd
|
63
|
+
def check_response res, cmd
|
73
64
|
if res =~ /^ERROR /m
|
74
|
-
raise
|
65
|
+
raise SkypeAPI::Error::API.new("#{cmd} => #{res}")
|
75
66
|
else
|
76
67
|
return res
|
77
68
|
end
|
78
69
|
end
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
class Abstruct
|
83
|
-
include Share
|
84
|
-
|
85
|
-
def initialize
|
86
|
-
@send_count = 0
|
87
|
-
@queue = Queue.new
|
88
|
-
#@queue = Array.new
|
89
|
-
@notify = Hash.new
|
90
|
-
@event = Hash.new do |h,k|
|
91
|
-
h[k] = Array.new
|
92
|
-
end
|
93
|
-
@attached = false
|
94
|
-
@first_attached = true
|
95
|
-
@raise_when_detached = false
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
def invoke_callback cmd, callback = Proc.new
|
100
|
-
end
|
101
|
-
|
102
|
-
def invoke_block cmd
|
103
|
-
end
|
104
|
-
|
70
|
+
private :check_response
|
71
|
+
|
105
72
|
def attach name = nil
|
106
73
|
end
|
107
74
|
|
108
75
|
def attach_wait name = nil
|
109
76
|
end
|
110
77
|
|
111
|
-
def wait action = nil
|
112
|
-
end
|
113
|
-
|
114
|
-
def polling
|
115
|
-
end
|
116
|
-
|
117
78
|
def close
|
118
|
-
end
|
119
|
-
|
120
|
-
private
|
121
|
-
def invoke_prototype cmd
|
122
|
-
end
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
class Mac
|
127
|
-
#wiki like
|
128
|
-
def initialize
|
129
|
-
raise SkypeAPIError::NotImplement
|
79
|
+
end
|
130
80
|
end
|
131
81
|
end
|
132
82
|
end
|