rb-skypemac 0.3.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/rb-skypemac/call.rb +14 -9
- data/lib/rb-skypemac/group.rb +25 -21
- data/lib/rb-skypemac/skype.rb +84 -72
- data/lib/rb-skypemac/user.rb +31 -22
- data/lib/rb-skypemac/version.rb +1 -1
- data/test/test_call.rb +1 -1
- data/website/index.html +22 -3
- data/website/index.txt +1 -1
- metadata +2 -2
data/lib/rb-skypemac/call.rb
CHANGED
@@ -11,14 +11,16 @@ module SkypeMac
|
|
11
11
|
|
12
12
|
attr :call_id
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
class << self
|
15
|
+
def Call.active_call_ids
|
16
|
+
r = Skype.send_ :command => "SEARCH ACTIVECALLS"
|
17
|
+
r.gsub(/CALLS /, "").split(", ")
|
18
|
+
end
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
20
|
+
def Call.active_calls
|
21
|
+
calls = Call.active_call_ids.collect { |id| Call.new id unless id == "COMMAND_PENDING"}
|
22
|
+
calls
|
23
|
+
end
|
22
24
|
end
|
23
25
|
|
24
26
|
# Creates a Call object from a call_id.
|
@@ -28,9 +30,12 @@ module SkypeMac
|
|
28
30
|
end
|
29
31
|
|
30
32
|
# Attempts to hang up a call. <b>Note</b>: If Skype hangs while placing the call, this method could hang indefinitely.
|
31
|
-
# <u>Use Skype#Call instead of this method unless you like memory leaks</u
|
33
|
+
# <u>Use Skype#Call instead of this method unless you like memory leaks</u>.
|
34
|
+
# Raises SkypeError if an error is reported from the Skype API
|
32
35
|
def hangup
|
33
|
-
Skype.send_ :command => "set call #{@call_id} status finished"
|
36
|
+
s = Skype.send_ :command => "set call #{@call_id} status finished"
|
37
|
+
raise SkypeError("Error occurred on hangup: #{s.message}") if s =~ /ERROR/
|
38
|
+
s
|
34
39
|
end
|
35
40
|
|
36
41
|
# Retrieves the status of the current call.<br>
|
data/lib/rb-skypemac/group.rb
CHANGED
@@ -8,17 +8,31 @@ module SkypeMac
|
|
8
8
|
class Group
|
9
9
|
attr_reader :gtype, :gid
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
class << self
|
12
|
+
# Gets the type of a group by id
|
13
|
+
def get_type(id)
|
14
|
+
r = Skype.send_ :command => "get group #{id} type"
|
15
|
+
r.sub(/.*TYPE\b/, "").strip
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
# Returns an array of your Skype instance's supported group types
|
19
|
+
def types
|
20
|
+
groups = Group.groups
|
21
|
+
groups.map { |g| g.gtype }
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns hash of symols (group types) => Group objects
|
25
|
+
def groups
|
26
|
+
r = Skype.send_ :command => "search groups hardwired", :script_name => ""
|
27
|
+
r.gsub!(/^\D+/, "")
|
28
|
+
group_ids = r.split ", "
|
29
|
+
groups = []
|
30
|
+
group_ids.each do |id|
|
31
|
+
groups << Group.new(id, Group.get_type(id))
|
32
|
+
end
|
33
|
+
groups
|
34
|
+
end
|
35
|
+
end
|
22
36
|
|
23
37
|
# Returns array of skype names of users in this group
|
24
38
|
def member_user_names
|
@@ -31,17 +45,7 @@ module SkypeMac
|
|
31
45
|
member_user_names.map { |h| User.new h }
|
32
46
|
end
|
33
47
|
|
34
|
-
|
35
|
-
def Group.groups
|
36
|
-
r = Skype.send_ :command => "search groups hardwired", :script_name => ""
|
37
|
-
r.gsub!(/^\D+/, "")
|
38
|
-
group_ids = r.split ", "
|
39
|
-
groups = []
|
40
|
-
group_ids.each do |id|
|
41
|
-
groups << Group.new(id, Group.get_type(id))
|
42
|
-
end
|
43
|
-
groups
|
44
|
-
end
|
48
|
+
|
45
49
|
|
46
50
|
def <=>(grp)
|
47
51
|
@gtype <=> grp.gtype
|
data/lib/rb-skypemac/skype.rb
CHANGED
@@ -5,93 +5,105 @@ include Appscript
|
|
5
5
|
module SkypeMac
|
6
6
|
|
7
7
|
# Singleton for interfacing with Skype
|
8
|
-
|
9
|
-
|
8
|
+
class Skype
|
9
|
+
@@groups = nil
|
10
10
|
@@calls = []
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
class << self
|
13
|
+
# The Appscript interface to Skype. Requires a Hash containing:
|
14
|
+
# (1) <i>:command</i> - the Skype API command to pass,
|
15
|
+
# (2) <i>:script_name</i> - unknown all though an empty String makes Skype happy.
|
16
|
+
# Impl adds <i>:script_name</i> to Hash and warns if it is not provided
|
17
|
+
def send_(params)
|
18
|
+
params[:script_name] = "" if not params.has_key? :script_name
|
19
|
+
app('Skype').send_ params
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
# Initiates a Skype call
|
23
|
+
def call(*person)
|
24
|
+
user_handles = person.collect { |u| (u.is_a? User) ? u.handle : u }
|
25
|
+
status = Skype.send_ :command => "call #{user_handles.join(', ')}"
|
26
|
+
if status =~ /CALL (\d+) STATUS/: @@calls << call = Call.new($1)
|
27
|
+
else raise RuntimeError.new("Call failed. Skype returned '#{status}'")
|
28
|
+
end
|
29
|
+
call
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
# Returns an Array of Call IDs if there is an incoming Skype call otherwise nil
|
33
|
+
def incoming_calls
|
34
|
+
calls = Call.active_calls - @@calls
|
35
|
+
calls
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
# Answers a call given a skype Call ID. Returns an Array of Call objects.
|
39
|
+
def answer(call)
|
40
|
+
cmd = "ALTER CALL #{call.call_id} ANSWER"
|
41
|
+
r = Skype.send_ :command => cmd
|
42
|
+
raise RuntimeError("Failed to answer call. Skype returned '#{r}'") unless r == cmd
|
43
|
+
@@calls << call
|
44
|
+
end
|
44
45
|
|
45
|
-
# Use this method to disconnect from a Call whether it was answered or iniiated locally.
|
46
|
-
def Skype.hangup(call)
|
47
|
-
call.hangup
|
48
|
-
@@calls.delete call
|
49
|
-
end
|
50
46
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
47
|
+
# Use this method to disconnect from a Call whether it was answered or iniiated locally.
|
48
|
+
# Raises SkypeError if an error is reported from the Skype API
|
49
|
+
def hangup(call)
|
50
|
+
@@calls.delete call if call.hangup
|
51
|
+
end
|
56
52
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
53
|
+
# Returns an Array of Group
|
54
|
+
def groups
|
55
|
+
@@groups = Group.groups if @@groups.nil? or @@groups.empty?
|
56
|
+
@@groups
|
57
|
+
end
|
58
|
+
|
59
|
+
# Returns Array of all User in a particular Group type. Accepts types as defined by Group.types
|
60
|
+
def find_users_of_type(group_type)
|
61
|
+
begin
|
62
|
+
Skype.groups.find { |g| g.gtype == group_type}.users
|
63
|
+
rescue Exception => e
|
64
|
+
puts e.message
|
65
|
+
end
|
66
|
+
end
|
61
67
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
68
|
+
# Returns an array of users online friends as User objects
|
69
|
+
def online_friends
|
70
|
+
Skype.find_users_of_type "ONLINE_FRIENDS"
|
71
|
+
end
|
66
72
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
73
|
+
# Array of all User that are friends of the current user
|
74
|
+
def all_friends
|
75
|
+
Skype.find_users_of_type "ALL_FRIENDS"
|
76
|
+
end
|
71
77
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
78
|
+
# Array of all User defined as Skype Out users
|
79
|
+
def skypeout_friends
|
80
|
+
Skype.find_users_of_type "SKYPEOUT_FRIENDS"
|
81
|
+
end
|
76
82
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
83
|
+
# Array of all User that the user knows
|
84
|
+
def all_users
|
85
|
+
Skype.find_users_of_type "ALL_USERS"
|
86
|
+
end
|
81
87
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
88
|
+
# Array of User recently contacted by the user, friends or not
|
89
|
+
def recently_contacted_users
|
90
|
+
Skype.find_users_of_type "RECENTLY_CONTACTED_USERS"
|
91
|
+
end
|
86
92
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
93
|
+
# Array of User waiting for authorization
|
94
|
+
def users_waiting_for_authorization
|
95
|
+
Skype.find_users_of_type "USERS_WAITING_MY_AUTHORIZATION"
|
96
|
+
end
|
97
|
+
|
98
|
+
# Array of User blocked
|
99
|
+
def blocked_users
|
100
|
+
Skype.find_users_of_type "USERS_BLOCKED_BY_ME"
|
101
|
+
end
|
91
102
|
|
92
|
-
|
93
|
-
|
94
|
-
|
103
|
+
# Minimize the Skype window
|
104
|
+
def minimize
|
105
|
+
Skype.send_ :command => "MINIMIZE"
|
106
|
+
end
|
95
107
|
end
|
96
108
|
end
|
97
109
|
end
|
data/lib/rb-skypemac/user.rb
CHANGED
@@ -6,36 +6,38 @@ module SkypeMac
|
|
6
6
|
|
7
7
|
# Represents Skype internal grouping of contacts; https://developer.skype.com/Docs/ApiDoc/GROUP_object
|
8
8
|
class User
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
v = true if v == "TRUE"
|
14
|
-
v = false if v == "FALSE"
|
15
|
-
v
|
16
|
-
end}
|
17
|
-
if accessor
|
18
|
-
module_eval %{def #{attr_sym.to_s}=(value)
|
19
|
-
value = "true" if value == true
|
20
|
-
value = "False" if value == false
|
21
|
-
r = Skype.send_ :command => "set user \#{@handle} #{attr_sym.to_s} \#{value}"
|
9
|
+
class << self
|
10
|
+
def skype_attr(attr_sym, accessor=false)
|
11
|
+
module_eval %{def #{attr_sym.to_s}
|
12
|
+
r = Skype.send_ :command => "get user \#{@handle} #{attr_sym.to_s}"
|
22
13
|
v = r.sub(/^.*#{attr_sym.to_s.upcase} /, "")
|
23
14
|
v = true if v == "TRUE"
|
24
15
|
v = false if v == "FALSE"
|
25
16
|
v
|
26
17
|
end}
|
18
|
+
if accessor
|
19
|
+
module_eval %{def #{attr_sym.to_s}=(value)
|
20
|
+
value = "true" if value == true
|
21
|
+
value = "False" if value == false
|
22
|
+
r = Skype.send_ :command => "set user \#{@handle} #{attr_sym.to_s} \#{value}"
|
23
|
+
v = r.sub(/^.*#{attr_sym.to_s.upcase} /, "")
|
24
|
+
v = true if v == "TRUE"
|
25
|
+
v = false if v == "FALSE"
|
26
|
+
v
|
27
|
+
end}
|
28
|
+
end
|
27
29
|
end
|
28
|
-
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
def skype_attr_reader(*attr_sym)
|
32
|
+
attr_sym.each do |a|
|
33
|
+
User.skype_attr a, false
|
34
|
+
end
|
33
35
|
end
|
34
|
-
end
|
35
36
|
|
36
|
-
|
37
|
-
|
38
|
-
|
37
|
+
def User.skype_attr_accessor(*attr_sym)
|
38
|
+
attr_sym.each do |a|
|
39
|
+
User.skype_attr a, true
|
40
|
+
end
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
@@ -55,8 +57,15 @@ module SkypeMac
|
|
55
57
|
@handle = handle
|
56
58
|
end
|
57
59
|
|
60
|
+
def name
|
61
|
+
if displayname != "": displayname
|
62
|
+
elsif fullname != "": fullname
|
63
|
+
else handle
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
58
67
|
def <=>(user)
|
59
|
-
|
68
|
+
name.upcase <=> user.name.upcase
|
60
69
|
end
|
61
70
|
end
|
62
71
|
end
|
data/lib/rb-skypemac/version.rb
CHANGED
data/test/test_call.rb
CHANGED
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>rb skypemac</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/rb-skypemac"; return false'>
|
35
35
|
Get Version
|
36
|
-
<a href="http://rubyforge.org/projects/rb-skypemac" class="numbers">0.2
|
36
|
+
<a href="http://rubyforge.org/projects/rb-skypemac" class="numbers">0.3.2</a>
|
37
37
|
</div>
|
38
38
|
<h1>→ ‘rb-skypemac’</h1>
|
39
39
|
|
@@ -65,13 +65,29 @@ call.hangup
|
|
65
65
|
|
66
66
|
sleight42 = Skype.online_friends.find { |u| u.handle == "sleight42" }
|
67
67
|
call = Skype.call sleight42
|
68
|
-
|
68
|
+
Skype.hangup call # no one wants to talk to him anyway
|
69
69
|
|
70
70
|
# Set your user status to away
|
71
71
|
Iam.away
|
72
72
|
|
73
73
|
# Set your user status to back
|
74
74
|
Iam.online
|
75
|
+
|
76
|
+
# Attempt to detect and answer a call -- still experimental!
|
77
|
+
# Sporadically crashes Skype 2.6.0.17
|
78
|
+
loop do
|
79
|
+
begin
|
80
|
+
if not (calls = Skype.incoming_calls).empty?
|
81
|
+
call = Skype.answer calls.first
|
82
|
+
sleep 10
|
83
|
+
Skype.hangup call
|
84
|
+
end
|
85
|
+
rescue RuntimeError => e
|
86
|
+
puts e.message
|
87
|
+
end
|
88
|
+
puts "sleeping..."
|
89
|
+
sleep 1
|
90
|
+
end
|
75
91
|
</pre>
|
76
92
|
|
77
93
|
<h2>Licence</h2>
|
@@ -84,8 +100,11 @@ Iam.online
|
|
84
100
|
|
85
101
|
|
86
102
|
<p>Comments are welcome. Send an email to <a href="mailto:sleight42@gmail.com">Evan Light</a>.</p>
|
103
|
+
|
104
|
+
|
105
|
+
<p>Copyright 2007, Evan Light</p>
|
87
106
|
<p class="coda">
|
88
|
-
<a href="mailto:sleight42@gmail.com.com">Evan Light</a>,
|
107
|
+
<a href="mailto:sleight42@gmail.com.com">Evan Light</a>, 2nd May 2007<br>
|
89
108
|
</p>
|
90
109
|
</div>
|
91
110
|
|
data/website/index.txt
CHANGED
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: rb-skypemac
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.3.
|
7
|
-
date: 2007-05-
|
6
|
+
version: 0.3.2
|
7
|
+
date: 2007-05-23 00:00:00 -04:00
|
8
8
|
summary: Ruby interface to Skype on Mac OS X
|
9
9
|
require_paths:
|
10
10
|
- lib
|