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.
@@ -11,14 +11,16 @@ module SkypeMac
11
11
 
12
12
  attr :call_id
13
13
 
14
- def Call.active_call_ids
15
- r = Skype.send_ :command => "SEARCH ACTIVECALLS"
16
- r.gsub(/CALLS /, "").split(", ")
17
- end
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
- def Call.active_calls
20
- calls = Call.active_call_ids.collect { |id| Call.new id unless id == "COMMAND_PENDING"}
21
- calls
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>
@@ -8,17 +8,31 @@ module SkypeMac
8
8
  class Group
9
9
  attr_reader :gtype, :gid
10
10
 
11
- # Gets the type of a group by id
12
- def Group.get_type(id)
13
- r = Skype.send_ :command => "get group #{id} type"
14
- r.sub(/.*TYPE\b/, "").strip
15
- end
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
- # Returns an array of your Skype instance's supported group types
18
- def Group.types
19
- groups = Group.groups
20
- groups.map { |g| g.gtype }
21
- end
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
- # Returns hash of symols (group types) => Group objects
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
@@ -5,93 +5,105 @@ include Appscript
5
5
  module SkypeMac
6
6
 
7
7
  # Singleton for interfacing with Skype
8
- class Skype
9
- @@groups = nil
8
+ class Skype
9
+ @@groups = nil
10
10
  @@calls = []
11
11
 
12
- # The Appscript interface to Skype. Requires a Hash containing:
13
- # (1) <i>:command</i> - the Skype API command to pass,
14
- # (2) <i>:script_name</i> - unknown all though an empty String makes Skype happy.
15
- # Impl adds <i>:script_name</i> to Hash and warns if it is not provided
16
- def Skype.send_(params)
17
- params[:script_name] = "" if not params.has_key? :script_name
18
- app('Skype').send_ params
19
- end
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
- # Initiates a Skype call
22
- def Skype.call(*person)
23
- user_handles = person.collect { |u| user_str << ((u.is_a? User) ? u.handle : u) }
24
- status = Skype.send_ :command => "call #{user_handles.join(', ')}"
25
- if status =~ /CALL (\d+) STATUS/: @@calls << call = Call.new($1)
26
- else raise RuntimeError.new("Call failed. Skype returned '#{status}'")
27
- end
28
- call
29
- end
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
- # Returns an Array of call IDs if there is an incoming Skype call otherwise nil
32
- def Skype.incoming_calls
33
- calls = Call.active_calls - @@calls
34
- calls
35
- end
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
- # Answers a call given a skype call ID. Returns an Array of Call objects.
38
- def Skype.answer(call)
39
- cmd = "ALTER CALL #{call.call_id} ANSWER"
40
- r = Skype.send_ :command => cmd
41
- raise RuntimeError("Failed to answer call. Skype returned '#{r}'") unless r == cmd
42
- @@calls << call
43
- end
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
- # Returns an Array of Group
52
- def Skype.groups
53
- @@groups = Group.groups if not @@groups
54
- @@groups
55
- end
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
- # Returns Array of all users in Group. Accepts types as defined by Group.types
58
- def Skype.find_users_of_type(group_type)
59
- Skype.groups.find { |g| g.gtype == group_type}.users
60
- end
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
- # Returns an array of users online friends as User objects
63
- def Skype.online_friends
64
- Skype.find_users_of_type "ONLINE_FRIENDS"
65
- end
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
- # Array of all Users that are friends of the current user
68
- def Skype.all_friends
69
- Skype.find_users_of_type "ALL_FRIENDS"
70
- end
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
- # Array of all Users defined as Skype Out users
73
- def Skype.skypeout_friends
74
- Skype.find_users_of_type "SKYPEOUT_FRIENDS"
75
- end
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
- # Array of all Users that the user knows
78
- def Skype.all_users
79
- Skype.find_users_of_type "ALL_USERS"
80
- end
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
- # Array of Users recently contacted by the user, friends or not
83
- def Skype.recently_contacted_users
84
- Skype.find_users_of_type "RECENTLY_CONTACTED_USERS"
85
- end
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
- # Array of Users waiting for authorization
88
- def Skype.users_waiting_for_authorization
89
- Skype.find_users_of_type "USERS_WAITING_MY_AUTHORIZATION"
90
- end
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
- # Array of Users blocked
93
- def Skype.blocked_users
94
- Skype.find_users_of_type "USERS_BLOCKED_BY_ME"
103
+ # Minimize the Skype window
104
+ def minimize
105
+ Skype.send_ :command => "MINIMIZE"
106
+ end
95
107
  end
96
108
  end
97
109
  end
@@ -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
- def User.skype_attr(attr_sym, accessor=false)
10
- module_eval %{def #{attr_sym.to_s}
11
- r = Skype.send_ :command => "get user \#{@handle} #{attr_sym.to_s}"
12
- v = r.sub(/^.*#{attr_sym.to_s.upcase} /, "")
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
- def User.skype_attr_reader(*attr_sym)
31
- attr_sym.each do |a|
32
- User.skype_attr a, false
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
- def User.skype_attr_accessor(*attr_sym)
37
- attr_sym.each do |a|
38
- User.skype_attr a, true
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
- @handle <=> user.handle
68
+ name.upcase <=> user.name.upcase
60
69
  end
61
70
  end
62
71
  end
@@ -2,7 +2,7 @@ module SkypeMac #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- TINY = 0
5
+ TINY = 2
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/test/test_call.rb CHANGED
@@ -4,7 +4,7 @@ include SkypeMac
4
4
  class TestCall< Test::Unit::TestCase
5
5
 
6
6
  def test_new
7
- assert Call.new 42
7
+ assert Call.new(42)
8
8
  end
9
9
 
10
10
  def test_active_call_ids
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.1</a>
36
+ <a href="http://rubyforge.org/projects/rb-skypemac" class="numbers">0.3.2</a>
37
37
  </div>
38
38
  <h1>&#x2192; &#8216;rb-skypemac&#8217;</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
- call.hangup # no one wants to talk to him anyway
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 =&gt; 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>, 26th April 2007<br>
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
@@ -40,7 +40,7 @@ loop do
40
40
  if not (calls = Skype.incoming_calls).empty?
41
41
  call = Skype.answer calls.first
42
42
  sleep 10
43
- call.hangup
43
+ Skype.hangup call
44
44
  end
45
45
  rescue RuntimeError => e
46
46
  puts e.message
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.0
7
- date: 2007-05-02 00:00:00 -04:00
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