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.
@@ -6,7 +6,7 @@ module SkypeAPI
6
6
  def self.create h, block=Proc.new
7
7
  raise ArgumentError unless h[:id] and h[:context] and h[:caption]
8
8
  #id, context, caption, hint=nil, icon=nil, enabled=nil, enableMultipleContacts=nil, &block
9
- res = @@skypeApi.sendCMD "CREATE MENU_ITEM #{h[:id]} CONTEXT #{h[:context]} CAPTION #{h[:caption]}#{h[:hint].nil? ? '' : " HINT #{h[:hint]}"}#{h[:icon].nil? ? '' : " ICON #{h[:icon]}"}#{h[:enable].nil? ? '' : " ENABLED #{h[:enabled]}"}#{h[:enableMultipleContacts].nil? ? '' : " ENABLE_MULTIPLE_CONTACTS #{h[:enableMultipleContacts]}"}"
9
+ res = SkypeAPI.invoke "CREATE MENU_ITEM #{h[:id]} CONTEXT #{h[:context]} CAPTION #{h[:caption]}#{h[:hint].nil? ? '' : " HINT #{h[:hint]}"}#{h[:icon].nil? ? '' : " ICON #{h[:icon]}"}#{h[:enable].nil? ? '' : " ENABLED #{h[:enabled]}"}#{h[:enableMultipleContacts].nil? ? '' : " ENABLE_MULTIPLE_CONTACTS #{h[:enableMultipleContacts]}"}"
10
10
  res == "MENU_ITEM #{h[:id]} CREATED"
11
11
  instance = new h[:id]
12
12
  instance.setNotify block if block
@@ -20,16 +20,16 @@ module SkypeAPI
20
20
  def self.notified msg
21
21
  if msg =~ /^([^ ]+) CLICKED( ([^ ]+))? CONTEXT ([^ ]+)( CONTEXT_ID (.+))?$/m
22
22
  id = $1; context = $4; userID = $3; contextID = $6
23
- user = userID ? @@skypeApi.user(userID) : nil
23
+ user = userID ? SkypeAPI.user(userID) : nil
24
24
  instance = new $1
25
25
  @notify[nil].call instance, context, user, contextID if @notify[nil]
26
26
  @notify[id].call instance, context, user, contextID if @notify[id]
27
- @@instance[self][id].notified context, user, contextID if @@instance[self][id]
27
+ @@instance[self][id].notified instance, context, user, contextID if @@instance[self][id]
28
28
  end
29
29
  end
30
30
 
31
- def notified context, user, contextID
32
- @notify.call context, user, contextID if @notify
31
+ def notified instance, context, user, contextID
32
+ @notify.call instance, context, user, contextID if @notify
33
33
  end
34
34
 
35
35
  def setNotify block=Proc.new
@@ -41,24 +41,30 @@ module SkypeAPI
41
41
  end
42
42
 
43
43
  def delete
44
- res = @@skypeApi.sendCMD "DELETE MENU_ITEM #{@id}"
44
+ res = SkypeAPI.invoke "DELETE MENU_ITEM #{@id}"
45
45
  res == "DELETE MENU_ITEM #{@id}"
46
46
  end
47
47
 
48
48
  def setCaption caption
49
- res = sendCMD "SET MENU_ITEM #{@id} CAPTION #{caption}"
49
+ res = invoke "SET MENU_ITEM #{@id} CAPTION #{caption}"
50
50
  res == "MENU_ITEM #{@id} CAPTION \"#{caption}\""
51
51
  end
52
52
 
53
53
  def setHint hint
54
- res = sendCMD "SET MENU_ITEM #{@id} HINT #{hint}"
54
+ res = invoke "SET MENU_ITEM #{@id} HINT #{hint}"
55
55
  res == "MENU_ITEM #{@id} HINT \"#{hint}\""
56
56
  end
57
57
 
58
58
  def setEnabled flag
59
- res = sendCMD "SET MENU_ITEM #{@id} ENABLED #{flag._str}"
59
+ res = invoke "SET MENU_ITEM #{@id} ENABLED #{flag._str}"
60
60
  res == "MENU_ITEM #{@id} ENABLED #{flag._str}"
61
61
  end
62
+
63
+ alias set_notify setNotify
64
+ #alias del_notify delNotify
65
+ alias set_caption setCaption
66
+ alias set_hint setHint
67
+ alias set_enabled setEnabled
62
68
  end
63
69
  end
64
70
  end
@@ -21,7 +21,7 @@ module SkypeAPI
21
21
  else
22
22
  raise target
23
23
  end
24
- res = @skypeApi.sendOne "MESSAGE #{target} #{text}","MESSAGE"
24
+ res = @skypeApi.invoke_one "MESSAGE #{target} #{text}","MESSAGE"
25
25
  if res =~ /^(\d+) STATUS (.+)$/
26
26
  return @skypeApi.getMessage($1),"getStatus",$2
27
27
  else
@@ -29,17 +29,17 @@ module SkypeAPI
29
29
  end
30
30
  end
31
31
 
32
- def timestamp() sendGet('TIMESTAMP'); end
33
- def partnerHandle() sendGet('PARTNER_HANDLE'); end
34
- def partnerDispname() sendGet('PARTNER_DISPNAME'); end
35
- def confIdD() sendGet('CONF_ID'); end
36
- def type() sendGet('TYPE'); end
37
- def status() sendGet('STATUS'); end
38
- def failureReason() sendGet('FAILUREREASON'); end
39
- def body() sendGet('BODY'); end
32
+ def timestamp() invoke_get('TIMESTAMP'); end
33
+ def partnerHandle() invoke_get('PARTNER_HANDLE'); end
34
+ def partnerDispname() invoke_get('PARTNER_DISPNAME'); end
35
+ def confIdD() invoke_get('CONF_ID'); end
36
+ def type() invoke_get('TYPE'); end
37
+ def status() invoke_get('STATUS'); end
38
+ def failureReason() invoke_get('FAILUREREASON'); end
39
+ def body() invoke_get('BODY'); end
40
40
 
41
41
  #def setSeen
42
- # str2object sendOne("SET MESSAGE #{@id} SEEN","SET MESSAGE #{@id} STATUS")
42
+ # str2object invoke_one("SET MESSAGE #{@id} SEEN","SET MESSAGE #{@id} STATUS")
43
43
  #end
44
44
  end
45
45
  end
@@ -21,23 +21,25 @@ module SkypeAPI
21
21
  @notify
22
22
  end
23
23
 
24
- def notified property,value
24
+ def notified instance, property,value
25
25
  if @notify[nil]
26
- @notify[nil][nil].call property, value if @notify[nil][nil]
27
- @notify[nil][value].call property if @notify[nil][value]
26
+ @notify[nil][nil].call instance, property, value if @notify[nil][nil]
27
+ @notify[nil][value].call instance, property if @notify[nil][value]
28
28
  end
29
29
  if @notify[property]
30
- @notify[property][nil].call value if @notify[property][nil]
31
- @notify[property][value].call if @notify[property][value]
30
+ @notify[property][nil].call instance, value if @notify[property][nil]
31
+ @notify[property][value].call instance if @notify[property][value]
32
32
  end
33
33
  end
34
+ alias set_notify setNotify
35
+ alias del_notify delNotify
34
36
  end
35
37
 
36
38
  module Get
37
39
  def getter methodName, skypeProperty=methodName.to_s.upcase, &callBack
38
40
  defineMethod = self == SkypeAPI ? self.class.method(:define_method) : method(:define_method)
39
41
  defineMethod.call 'get' + methodName.to_s do
40
- str = sendGet skypeProperty
42
+ str = invoke_get skypeProperty
41
43
  callBack ? callBack.call(str) : str
42
44
  end
43
45
 
@@ -98,7 +100,7 @@ module SkypeAPI
98
100
  @notify[property][nil].call instance, value if @notify[property][nil]
99
101
  @notify[property][value].call instance if @notify[property][value]
100
102
  end
101
- @@instance[self][id].notified property,value if @@instance[self][id]
103
+ @@instance[self][id].notified instance, property, value if @@instance[self][id]
102
104
  end
103
105
  end
104
106
 
@@ -123,8 +125,7 @@ module SkypeAPI
123
125
  @id.to_s
124
126
  end
125
127
 
126
- #def_delegators :@@skypeApi, :sendCMD
127
- def_delegators :@@skypeApi, :sendCMD
128
+ def_delegators :@@skypeApi, :invoke
128
129
  end
129
130
 
130
131
  end
@@ -0,0 +1,132 @@
1
+ module SkypeAPI
2
+ module OS
3
+ module Share
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
25
+
26
+ def del_notify reg
27
+ @notify.delete reg
28
+ end
29
+
30
+ def add_event sym, block=Proc.new
31
+ @event[sym].push block
32
+ block
33
+ end
34
+
35
+ #def set_event sym, block=Proc.new
36
+ # @event[sym] = Array.new
37
+ # add_event sym, block
38
+ #end
39
+
40
+ def del_event sym, block=nil
41
+ unless block
42
+ @event[sym] = Array.new
43
+ else
44
+ @event[sym].delete block
45
+ end
46
+ end
47
+
48
+ def exist_event? sym
49
+ if @event[sym].length > 0
50
+ return true
51
+ else
52
+ return false
53
+ end
54
+ end
55
+
56
+ def get_event sym
57
+ @event[sym]
58
+ end
59
+
60
+ def do_event sym,*args
61
+ @event[sym].each do |e|
62
+ if e.arity == 1
63
+ e.call args[0]
64
+ else
65
+ e.call args
66
+ end
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def check_response res,cmd
73
+ if res =~ /^ERROR /m
74
+ raise SkypeAPIError::API,res, caller
75
+ else
76
+ return res
77
+ end
78
+ end
79
+
80
+ end
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
+
105
+ def attach name = nil
106
+ end
107
+
108
+ def attach_wait name = nil
109
+ end
110
+
111
+ def wait action = nil
112
+ end
113
+
114
+ def polling
115
+ end
116
+
117
+ 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
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,110 @@
1
+ require 'dbus'
2
+ require "thread"
3
+
4
+ module SkypeAPI
5
+ module OS
6
+ class Linux < Abstruct
7
+ class Notify < DBus::Object
8
+ dbus_interface "com.Skype.API.Client" do
9
+ dbus_method :Notify, "in data:s" do |res|
10
+ @os.push_queue res
11
+ end
12
+ end
13
+ end
14
+
15
+ def initialize service_name="org.ruby.service"
16
+ super()
17
+ bus = DBus.session_bus
18
+ exobj = Notify.new("/com/Skype/Client")
19
+ #exobj.instance_variable_set(:@queue, @queue)
20
+ exobj.instance_variable_set(:@os, self)
21
+ bus.request_service(service_name).export(exobj)
22
+ service = bus.service 'com.Skype.API'
23
+ @invoker = service.object '/com/Skype'
24
+ @invoker.default_iface = 'com.Skype.API'
25
+ @invoker.introspect
26
+
27
+ #l = DBus::Main.new
28
+ #l << bus
29
+ #Thread.new do
30
+ # l.run
31
+ #end
32
+ end
33
+
34
+ def attach name
35
+ invoke "NAME #{name}"
36
+ invoke "PROTOCOL 9999"
37
+ if @first_attached
38
+ @queue.push proc{do_event :attached}
39
+ else
40
+ @queue.push proc{do_event :reattached}
41
+ end
42
+ end
43
+
44
+ def invoke_prototype(cmd)
45
+ res = @invoker.Invoke('#' + @send_count.to_s + ' ' + cmd)[0]
46
+ old_count = @send_count.to_s
47
+ @send_count+=1
48
+ @queue.push proc{do_event :sent, '#' + old_count + ' ' + cmd}
49
+ @queue.push proc{do_event :received, res}
50
+ res =~ /^##{old_count} (.*)$/m
51
+ return $1
52
+ end
53
+
54
+ alias :invoke_block :invoke_prototype
55
+
56
+ def invoke_callcack cmd,cb=Proc.new
57
+ res = send_prototype(cmd)
58
+ cb.call(res)
59
+ end
60
+
61
+ def close
62
+ end
63
+
64
+ def polling
65
+ flag = true
66
+ begin
67
+ while flag
68
+ proc = @queue.shift true
69
+ proc.call
70
+ end
71
+ rescue
72
+ flag = false
73
+ end
74
+ end
75
+
76
+ def push_queue res
77
+ @queue.push(proc{do_event(:received, res)})
78
+
79
+ if res == 'CONNSTATUS LOGGEDOUT'
80
+ @attached = false
81
+ @queue.push(proc{do_event(:detached)})
82
+ SkypeAPI.attach
83
+ end
84
+
85
+ flag = false
86
+ @notify.each do |reg,action|
87
+ if res =~ reg
88
+ tmp = $1
89
+ @queue.push(proc{action.call(tmp)})
90
+ flag = true
91
+ end
92
+ end
93
+
94
+ unless flag
95
+ action = @notify[nil]
96
+ @queue.push(proc{action.call(cmd)})
97
+ end
98
+ end
99
+
100
+
101
+ def wait
102
+ end
103
+
104
+ def attach_wait(name)
105
+ @name = name
106
+ attach(name)
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,10 @@
1
+ module SkypeAPI
2
+ module OS
3
+ class Mac
4
+ #sorry...
5
+ def initialize
6
+ raise SkypeAPIError::NotImplement
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,108 @@
1
+ #module SkypeAPI
2
+ # module OS
3
+ # class Windows
4
+ class Timer
5
+ class << self
6
+ def interval term, block=Proc.new
7
+ Interval.new term, block
8
+ end
9
+
10
+ def timeout term, block=Proc.new
11
+ Timeout.new term, block
12
+ end
13
+
14
+ def delete instance
15
+ case instance.class
16
+ when Timeout
17
+ instance.delete
18
+ when Interval
19
+ instance.delete
20
+ else
21
+ raise ArgumentError
22
+ end
23
+ end
24
+
25
+ def polling
26
+ now = Time.now.to_i
27
+ Timeout.polling now
28
+ Interval.polling now
29
+ end
30
+ end
31
+
32
+ class Abstruct
33
+
34
+ class << self
35
+
36
+ def new term, block
37
+ instance = super
38
+ @stack << instance
39
+ return instance
40
+ end
41
+
42
+ def delete instance
43
+ @stack.delete instance
44
+ end
45
+
46
+ end
47
+
48
+
49
+ def delete
50
+ self.class.delete self
51
+ end
52
+
53
+ attr_reader :term, :block
54
+
55
+ end
56
+
57
+ class Timeout < Abstruct
58
+ @stack = Array.new
59
+ class << self
60
+
61
+ def polling now
62
+ @stack.delete_if do |timeout|
63
+ if now >= timeout.term
64
+ timeout.block.call
65
+ true
66
+ else
67
+ false
68
+ end
69
+ end
70
+ end
71
+
72
+ end
73
+
74
+ def initialize term, block
75
+ @term = term + Time.now.to_i
76
+ @block = block
77
+ end
78
+
79
+ end
80
+
81
+ class Interval < Abstruct
82
+ @stack = Array.new
83
+
84
+ class << self
85
+
86
+ def polling now
87
+ @stack.each do |interval|
88
+ if now >= interval.term + interval.old
89
+ interval.old = now
90
+ interval.block.call
91
+ end
92
+ end
93
+ end
94
+
95
+ end
96
+
97
+ def initialize term, block
98
+ @term = term
99
+ @old = Time.now.to_i
100
+ @block = block
101
+ end
102
+
103
+ attr_accessor :old
104
+ end
105
+ end
106
+ # end
107
+ # end
108
+ #end