rb-skypemac 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Manifest.txt CHANGED
@@ -3,6 +3,11 @@ Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
5
  lib/rb-skypemac.rb
6
+ lib/rb-skypemac/call.rb
7
+ lib/rb-skypemac/group.rb
8
+ lib/rb-skypemac/iam.rb
9
+ lib/rb-skypemac/skype.rb
10
+ lib/rb-skypemac/user.rb
6
11
  lib/rb-skypemac/version.rb
7
12
  scripts/txt2html
8
13
  setup.rb
data/README.txt CHANGED
@@ -1,3 +1,5 @@
1
1
  README for rb-skypemac
2
2
  ======================
3
3
 
4
+ Include support for calling, managing calls, and managing users. Most invocations are made via the Skype class which
5
+ abstracts much of the Skype API, delegating calls to the constituent objects in the official Skype API.
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'appscript'
3
+ include Appscript
4
+
5
+
6
+ module SkypeMac
7
+
8
+ # Represents a Skype call
9
+ class Call
10
+ @@TOGGLE_FLAGS = [:START, :STOP]
11
+
12
+ attr :id
13
+
14
+ # Creates and initializes a Skype call. Accepts the handle of the user to call or a User object
15
+ def initialize(user)
16
+ user = user.handle if user.is_a? User
17
+ status = Skype.send_ :command => "call #{user}"
18
+ if status =~ /CALL (\d+) STATUS/
19
+ @id = $1
20
+ else
21
+ raise Error.new("Could not obtain Call ID")
22
+ end
23
+ end
24
+
25
+ # Attempts to hang up a call.<br>
26
+ # <b>Note</b>: If Skype hangs while placing the call, this method could hang indefinitely
27
+ def hangup
28
+ Skype.send_ :command => "set call #{@id} status finished"
29
+ end
30
+
31
+ # Retrieves the status of the current call.<br>
32
+ # <b>Untested</b>
33
+ def status
34
+ Skype.send_ :command => "get call #{@id} status"
35
+ end
36
+
37
+ # Returns one of: VIDEO_NONE, VIDEO_SEND_ENABLED, VIDEO_RECV_ENABLED, VIDEO_BOTH_ENABLED
38
+ def get_video_status
39
+ Skype.send_ :command => "get call #{id} video_status"
40
+ end
41
+
42
+ # Accepts <i>:START</i> or <em>:STOP</em>
43
+ def send_video(toggle_flag)
44
+ raise Error.new("Illegal flag: #{toggle_flag}") if not @@TOGGLE_FLAGS.index toggle_flag
45
+ Skype.send_ :command => "alter call #{id} #{toggle_flag.downcase.to_s}_video_send"
46
+ end
47
+
48
+ # Accepts <em>:START</em> or <em>:STOP</em>
49
+ def rcv_video(toggle_flag)
50
+ raise Error.new("Illegal flag: #{toggle_flag}") if not @@TOGGLE_FLAGS.index toggle_flag
51
+ Skype.send_ :command => "alter call #{id} #{toggle_flag.downcase.to_s}_video_receive"
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,52 @@
1
+ require 'rubygems'
2
+ require 'appscript'
3
+ include Appscript
4
+
5
+ module SkypeMac
6
+
7
+ # Represents Skype internal grouping of contacts; https://developer.skype.com/Docs/ApiDoc/GROUP_object
8
+ class Group
9
+ attr_reader :gtype, :gid
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
16
+
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
22
+
23
+ # Returns array of skype names of users in this group
24
+ def member_user_names
25
+ r = Skype.send_ :command => "get group #{@gid} users"
26
+ r.sub(/^.*USERS /, "").split(", ")
27
+ end
28
+
29
+ # Returns array of Users in this Group
30
+ def users
31
+ member_user_names.map { |h| User.new h }
32
+ end
33
+
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
45
+
46
+ private
47
+ def initialize(id, type)
48
+ @gid = id
49
+ @gtype = type
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,22 @@
1
+ require 'rubygems'
2
+ require 'appscript'
3
+ include Appscript
4
+
5
+ module SkypeMac
6
+
7
+ # Singleton for managing Skype user status
8
+ class Iam
9
+ @@STATUSES = [:ONLINE, :OFFLINE, :SKYPEME, :AWAY, :NA, :DND, :INVISIBLE]
10
+
11
+ def Iam.set_user_status(status)
12
+ raise NoMethodError.new("#{status} in #{Iam.to_s}") if not @@STATUSES.index status.upcase.to_sym
13
+ Skype.send_ :command => "SET USERSTATUS #{status}"
14
+ end
15
+
16
+ # Handles all of the user status permutations accepted by Skype otherwise Errors.
17
+ # For example, <i>Iam.away</i> is legal.
18
+ def Iam.method_missing(id)
19
+ Iam.set_user_status(id.id2name)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,73 @@
1
+ require 'rubygems'
2
+ require 'appscript'
3
+ include Appscript
4
+
5
+ module SkypeMac
6
+
7
+ # Singleton for interfacing with Skype
8
+ class Skype
9
+ @@groups = nil
10
+
11
+ # Initiates a Skype call
12
+ def Skype.call(name_or_num)
13
+ Call.new name_or_num
14
+ end
15
+
16
+ # The Appscript interface to Skype. Requires a Hash containing:
17
+ # (1) <i>:command</i> - the Skype API command to pass,
18
+ # (2) <i>:script_name</i> - unknown all though an empty String makes Skype happy.
19
+ # Impl adds <i>:script_name</i> to Hash and warns if it is not provided
20
+ def Skype.send_(params)
21
+ params[:script_name] = "" if not params.has_key? :script_name
22
+ app('Skype').send_ params
23
+ end
24
+
25
+ # Returns an Array of Groups
26
+ def Skype.groups
27
+ if not @@groups
28
+ @@groups = Group.groups
29
+ end
30
+ @@groups
31
+ end
32
+
33
+ # Returns Array of all users in Group. Accepts types as defined by Group.types
34
+ def Skype.find_users_of_type(group_type)
35
+ Skype.groups.find { |g| g.gtype == group_type}.users
36
+ end
37
+
38
+ # Returns an array of users online friends as User objects
39
+ def Skype.online_friends
40
+ Skype.find_users_of_type "ONLINE_FRIENDS"
41
+ end
42
+
43
+ # Array of all Users that are friends of the current user
44
+ def Skype.all_friends
45
+ Skype.find_users_of_type "ALL_FRIENDS"
46
+ end
47
+
48
+ # Array of all Users defined as Skype Out users
49
+ def Skype.skypeout_friends
50
+ Skype.find_users_of_type "SKYPEOUT_FRIENDS"
51
+ end
52
+
53
+ # Array of all Users that the user knows
54
+ def Skype.all_users
55
+ Skype.find_users_of_type "ALL_USERS"
56
+ end
57
+
58
+ # Array of Users recently contacted by the user, friends or not
59
+ def Skype.recently_contacted_users
60
+ Skype.find_users_of_type "RECENTLY_CONTACTED_USERS"
61
+ end
62
+
63
+ # Array of Users waiting for authorization
64
+ def Skype.users_waiting_for_authorization
65
+ Skype.find_users_of_type "USERS_WAITING_MY_AUTHORIZATION"
66
+ end
67
+
68
+ # Array of Users blocked
69
+ def Skype.blocked_users
70
+ Skype.find_users_of_type "USERS_BLOCKED_BY_ME"
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'appscript'
3
+ include Appscript
4
+
5
+ module SkypeMac
6
+
7
+ # Represents Skype internal grouping of contacts; https://developer.skype.com/Docs/ApiDoc/GROUP_object
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 = nil 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}"
22
+ v = r.sub(/^.*#{attr_sym.to_s.upcase} /, "")
23
+ v = true if v == "TRUE"
24
+ v = nil if v == "FALSE"
25
+ v
26
+ end}
27
+ end
28
+ end
29
+
30
+ def User.skype_attr_reader(*attr_sym)
31
+ attr_sym.each do |a|
32
+ User.skype_attr a, false
33
+ end
34
+ end
35
+
36
+ def User.skype_attr_accessor(*attr_sym)
37
+ attr_sym.each do |a|
38
+ User.skype_attr a, true
39
+ end
40
+ end
41
+
42
+ attr_reader :handle
43
+ skype_attr_reader :fullname, :birthday, :sex, :language, :country, :province
44
+ skype_attr_reader :city, :phone_home, :phone_office, :phone_mobile, :homepage
45
+ skype_attr_reader :about, :is_video_capable, :buddystatus, :is_authorized
46
+ skype_attr_reader :is_blocked, :onlinestatus, :skypeout, :lastonlinetimestamp
47
+ skype_attr_reader :can_leave_vm, :speeddial, :receivedauthrequest, :mood_text
48
+ skype_attr_reader :rich_mood_text, :is_cf_active, :nrof_authed_buddies
49
+
50
+ #TODO: attr_reader :aliases, :timezone
51
+
52
+ attr_accessor :buddystatus, :isblocked, :isauthorized, :speeddial, :displayname
53
+
54
+ def initialize(handle)
55
+ @handle = handle
56
+ end
57
+ end
58
+ end
@@ -1,7 +1,7 @@
1
1
  module SkypeMac #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 1
4
+ MINOR = 2
5
5
  TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
data/lib/rb-skypemac.rb CHANGED
@@ -1,95 +1 @@
1
- Dir[File.join(File.dirname(__FILE__), 'rb-skypemac/**/*.rb')].sort.each { |lib| require lib }
2
-
3
- require 'rubygems'
4
- require 'appscript'
5
- include Appscript
6
-
7
- module SkypeMac
8
- # Singleton for interfacing with Skype
9
- class Skype
10
- def Skype.call(name_or_num)
11
- Call.new name_or_num
12
- end
13
-
14
- # The Appscript interface to Skype. Requires a Hash containing:
15
- # <li><i>:command</i> - the <a href="https://developer.skype.com/Docs/ApiDoc">Skype API command to pass</a>
16
- # <li><i>:script_name</i> - unknown all though an empty String makes Skype happy
17
- # Impl adds :script_name to Hash and warns if it is not provided
18
- def Skype.send_(params)
19
- if not params.has_key? :script_name and not @suppress_warnings
20
- puts "Warning: Skype Applescript API require 'script_name' key (even with an empty String value). Adding..."
21
- params[:script_name] = ""
22
- end
23
- app('Skype').send_ params
24
- end
25
-
26
- def Skype.suppress_warnings
27
- @suppress_warnings = 1
28
- end
29
- end
30
-
31
- class Call
32
- @@TOGGLE_FLAGS = [:START, :STOP]
33
-
34
- attr :id
35
-
36
- # Creates and initializes a Skype call
37
- def initialize(name_or_num)
38
- status = Skype.send_ :command => "call #{name_or_num}"
39
- if status =~ /CALL (\d+) STATUS/
40
- @id = $1
41
- else
42
- raise Error.new("Could not obtain Call ID")
43
- end
44
- end
45
-
46
- # Attempts to hang up a call.<br>
47
- # <b>Note</b>: If Skype hangs while placing the call, this method could hang indefinitely
48
- def hangup
49
- Skype.send_ :command => "set call #{@id} status finished"
50
- end
51
-
52
- # Retrieves the status of the current call.<br>
53
- # <b>Untested</b>
54
- def status
55
- Skype.send_ :command => "get call #{@id} status"
56
- end
57
-
58
- # Returns one of:<br>
59
- # <li>VIDEO_NONE
60
- # <li>VIDEO_SEND_ENABLED
61
- # <li>VIDEO_RECV_ENABLED
62
- # <li>VIDEO_BOTH_ENABLED
63
- def get_video_status
64
- Skype.send_ :command => "get call #{id} video_status"
65
- end
66
-
67
- # Accepts :START or :STOP
68
- def send_video(toggle_flag)
69
- raise Error.new("Illegal flag: #{toggle_flag}") if not @@TOGGLE_FLAGS.index toggle_flag
70
- Skype.send_ :command => "alter call #{id} #{toggle_flag.downcase.to_s}_video_send"
71
- end
72
-
73
- # Accepts :START or :STOP
74
- def rcv_video(toggle_flag)
75
- raise Error.new("Illegal flag: #{toggle_flag}") if not @@TOGGLE_FLAGS.index toggle_flag
76
- Skype.send_ :command => "alter call #{id} #{toggle_flag.downcase.to_s}_video_receive"
77
- end
78
- end
79
-
80
- # Singleton for managing Skype user status
81
- class Iam
82
- @@STATUSES = [:ONLINE, :OFFLINE, :SKYPEME, :AWAY, :NA, :DND, :INVISIBLE]
83
-
84
- def Iam.set_user_status(status)
85
- raise NoMethodError.new("#{status} in #{Iam.to_s}") if not @@STATUSES.index status.upcase.to_sym
86
- Skype.send_ :command => "SET USERSTATUS #{status}"
87
- end
88
-
89
- # Handles all of the user status permutations accepted by Skype otherwise Errors.
90
- # For example, <i>Iam.away</i> is legal.
91
- def Iam.method_missing(id)
92
- Iam.set_user_status(id.id2name)
93
- end
94
- end
95
- end
1
+ Dir[File.join(File.dirname(__FILE__), 'rb-skypemac/**/*.rb')].sort.each { |lib| require lib }
@@ -0,0 +1,55 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ include SkypeMac
3
+
4
+ class TestGroup < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @gs = Group.groups
8
+ end
9
+
10
+ def test_group_types
11
+ gtypes = Group.types
12
+ assert gtypes
13
+ assert gtypes.class == Array
14
+ assert !gtypes.empty?
15
+ end
16
+
17
+ def test_groups
18
+ assert @gs
19
+ assert @gs.class == Array
20
+ assert !@gs.empty?
21
+ end
22
+
23
+ def test_get_type
24
+ type = Group.get_type @gs[0].gid
25
+ assert type
26
+ assert type.class == String
27
+ assert type.match(/^\w+$/)
28
+ end
29
+
30
+ def test_gtype
31
+ assert @gs[0].gtype
32
+ assert @gs[0].gtype.class == String
33
+ assert @gs[0].gtype.match(/^\w+$/)
34
+ end
35
+
36
+ def test_gid
37
+ assert @gs[0].gid
38
+ assert @gs[0].gid.class == String
39
+ assert @gs[0].gid.match(/^\d+$/)
40
+ end
41
+
42
+ def test_member_user_names
43
+ user_names = @gs[0].member_user_names
44
+ assert user_names
45
+ assert user_names.class == Array
46
+ assert !user_names.empty?
47
+ user_names.each { |n| assert n.index(" ").nil? }
48
+ end
49
+
50
+ def test_users
51
+ assert users = @gs[0].users
52
+ assert users.empty? == false
53
+ assert users[0].class == User
54
+ end
55
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+
4
+ class TestSkype < Test::Unit::TestCase
5
+
6
+ def test_groups
7
+ gs = Skype.groups
8
+ end
9
+
10
+ def test_online_friends
11
+ assert users = Skype.online_friends
12
+ assert users.empty? == false
13
+ assert users[0].class == User
14
+ end
15
+ end
data/test/test_user.rb ADDED
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+ include SkypeMac
3
+
4
+ class TestUser < Test::Unit::TestCase
5
+
6
+ def setup
7
+ @user = User.new "sleight42"
8
+ end
9
+
10
+ def test_handle
11
+ assert @user.handle
12
+ assert @user.handle == "sleight42"
13
+ end
14
+
15
+ def test_fullname
16
+ assert @user.fullname
17
+ assert @user.fullname == "Evan"
18
+ end
19
+
20
+ def test_city
21
+ assert @user.city
22
+ assert @user.city == "Vienna"
23
+ end
24
+
25
+ def test_isblocked
26
+ prk166 = User.new prk166
27
+ prk166.isblocked = true
28
+ assert prk166.isblocked
29
+ prk166.isblocked = false
30
+ assert prk166.isblocked == false
31
+ end
32
+ end
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.1.0</a>
36
+ <a href="http://rubyforge.org/projects/rb-skypemac" class="numbers">0.2.0</a>
37
37
  </div>
38
38
  <h1>&#x2192; &#8216;rb-skypemac&#8217;</h1>
39
39
 
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.1.0
7
- date: 2007-04-22 00:00:00 -04:00
6
+ version: 0.2.0
7
+ date: 2007-04-26 00:00:00 -04:00
8
8
  summary: Ruby interface to Skype on Mac OS X
9
9
  require_paths:
10
10
  - lib
@@ -34,6 +34,11 @@ files:
34
34
  - README.txt
35
35
  - Rakefile
36
36
  - lib/rb-skypemac.rb
37
+ - lib/rb-skypemac/call.rb
38
+ - lib/rb-skypemac/group.rb
39
+ - lib/rb-skypemac/iam.rb
40
+ - lib/rb-skypemac/skype.rb
41
+ - lib/rb-skypemac/user.rb
37
42
  - lib/rb-skypemac/version.rb
38
43
  - scripts/txt2html
39
44
  - setup.rb
@@ -45,8 +50,11 @@ files:
45
50
  - website/stylesheets/screen.css
46
51
  - website/template.rhtml
47
52
  test_files:
53
+ - test/test_group.rb
48
54
  - test/test_helper.rb
49
55
  - test/test_rb-skypemac.rb
56
+ - test/test_skype.rb
57
+ - test/test_user.rb
50
58
  rdoc_options: []
51
59
 
52
60
  extra_rdoc_files: []