Ruby4Skype 0.2.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/LICENSE +3 -0
  2. data/README +14 -0
  3. data/Rakefile +67 -0
  4. data/lib/skypeapi.rb +570 -509
  5. data/lib/skypeapi/application.rb +79 -77
  6. data/lib/skypeapi/call.rb +243 -230
  7. data/lib/skypeapi/chat.rb +162 -172
  8. data/lib/skypeapi/chatmember.rb +26 -28
  9. data/lib/skypeapi/chatmessage.rb +81 -65
  10. data/lib/skypeapi/error.rb +8 -0
  11. data/lib/skypeapi/event.rb +25 -26
  12. data/lib/skypeapi/filetransfer.rb +47 -28
  13. data/lib/skypeapi/group.rb +72 -73
  14. data/lib/skypeapi/menuitem.rb +44 -44
  15. data/lib/skypeapi/message.rb +39 -41
  16. data/lib/skypeapi/object.rb +246 -82
  17. data/lib/skypeapi/os/etc.rb +48 -98
  18. data/lib/skypeapi/os/mac.rb +92 -4
  19. data/lib/skypeapi/os/notifier.rb +31 -0
  20. data/lib/skypeapi/os/window_event_queue.rb +198 -0
  21. data/lib/skypeapi/os/window_messagehandler.rb +120 -0
  22. data/lib/skypeapi/os/windows.rb +170 -306
  23. data/lib/skypeapi/profile.rb +190 -120
  24. data/lib/skypeapi/sharefunctions.rb +31 -23
  25. data/lib/skypeapi/sms.rb +87 -67
  26. data/lib/skypeapi/user.rb +159 -99
  27. data/lib/skypeapi/version.rb +3 -3
  28. data/lib/skypeapi/voicemail.rb +59 -52
  29. data/spec/matcher_be_boolean.rb +10 -0
  30. data/spec/skypeapi/application_spec.rb +76 -0
  31. data/spec/skypeapi/chat_spec.rb +356 -0
  32. data/spec/skypeapi/chatmember_spec.rb +42 -0
  33. data/spec/skypeapi/chatmessage_spec.rb +89 -0
  34. data/spec/skypeapi/event_spec.rb +31 -0
  35. data/spec/skypeapi/filetransfer_spec.rb +67 -0
  36. data/spec/skypeapi/group_spec.rb +16 -0
  37. data/spec/skypeapi/menuitem_spec.rb +37 -0
  38. data/spec/skypeapi/os/windows_spec.rb +305 -0
  39. data/spec/skypeapi/profile_spec.rb +22 -0
  40. data/spec/skypeapi/user_spec.rb +25 -0
  41. data/spec/skypeapi_spec.rb +528 -0
  42. metadata +32 -12
  43. data/lib/skypeapi/os/timer.rb +0 -108
data/lib/skypeapi/user.rb CHANGED
@@ -1,109 +1,169 @@
1
1
  module SkypeAPI
2
- module Object
3
- class User < AbstractObject
4
- OBJECT_NAME = "USER"
5
-
6
- getter :Handle, 'HANDLE'
7
- getter :Fullname, 'FULLNAME'
8
- getter :Birthday,'BIRTHDAY' do |yyyymmdd|
9
- (yyyymmdd =~ /(\d\d\d\d)(\d\d)(\d\d)/) ? Date.new($1.to_i,$2.to_i,$3.to_i) : nil
10
- end
11
- getter :Sex, 'SEX'
12
- getter :Language, 'LANGUAGE' do |str|
13
- str.empty? ? str : str.split(' ',2)[0]
14
- end
15
- getter :Country, 'COUNTRY' do |str|
16
- str.empty? ? str : str.split(' ',2)[0]
17
- end
18
- getter :Province, 'PROVINCE'
19
- getter :City, 'CITY'
20
- getter :PhoneHome, 'PHONE_HOME'
21
- getter :PhoneOffice, 'PHONE_OFFICE'
22
- getter :PhoneMobile, 'PHONE_MOBILE'
23
- getter :Homepage, 'HOMEPAGE'
24
- getter :About, 'ABOUT'
25
- getter :HasCallEquipment, 'HASCALLEQUIPMENT' do |str|
26
- str._flag
27
- end
28
- getter :IsVideoCapable, 'IS_VIDEO_CAPABLE' do |str|
29
- str._flag
30
- end
31
- getter :IsVoicemailCapable, 'IS_VOICEMAIL_CAPABLE' do |str|
32
- str._flag
33
- end
34
- getter :BuddyStatus, 'BUDDYSTATUS' do |str|
35
- str.to_i
36
- end
37
- getter :IsAuthorized, 'ISAUTHORIZED' do |str|
38
- str._flag
39
- end
40
- getter :IsBlocked, 'ISBLOCKED' do |str|
41
- str._flag
42
- end
43
- getter :OnlineStatus, 'ONLINESTATUS'
44
- #getter :skypeOut, 'SkypeOut'
45
- #getter :skypeMe, 'SKYPEME'
46
- getter :LastOnlineTimestamp, 'LASTONLINETIMESTAMP' do |str|
47
- if str.empty? then nil else Time.at(str.to_i) end
48
- end
49
- getter :CanLeaveVM, 'CAN_LEAVE_VM' do |str|
50
- str._flag
51
- end
52
- getter :SpeedDial, 'SPEEDDIAL' do |str|
53
- str#._int
54
- end
55
- getter :ReceivedAuthRequest, 'RECEIVEDAUTHREQUEST'
56
- getter :MoodText, 'MOOD_TEXT'
57
- getter :RichMoodText, 'RICH_MOOD_TEXT'
58
- getter :Aliases, 'ALIASES'
59
- getter :Timezone, 'TIMEZONE' do |str|
60
- str._int
61
- end
62
- getter :IsCFActive, 'IS_CF_ACTIVE' do |str|
63
- str._flag
64
- end
65
- getter :NrofAuthedBuddies, 'NROF_AUTHED_BUDDIES' do |str|
66
- str._int
67
- end
68
- getter :DisplayName, 'DISPLAYNAME'
69
-
70
- def getAvatar(filePath)
71
- invoke("GET USER #{@id} AVATAR 1 #{filePath}") =~ /^USER #{@id} AVATAR \d+ (.+)$/
72
- #if $1
73
- # return $1
74
- #else
75
- return nil
76
- #end
77
- end
78
- notice :Avatar, 'AVATAR 1'
2
+ class User < AbstractObject
3
+ OBJECT_NAME = "USER"
4
+
5
+ def get_handle() invoke_get("HANDLE") end
6
+ def_parser(:handle)
7
+ alias getHandle get_handle
8
+
9
+ def get_fullname() invoke_get("FULLNAME") end
10
+ def_parser(:fullname)
11
+ alias getFullname get_fullname
12
+
13
+ def get_birthday() parse :birthday, invoke_get("BIRTHDAY") end
14
+ def_parser(:birthday){|yyyymmdd| (yyyymmdd =~ /(\d\d\d\d)(\d\d)(\d\d)/) ? Date.new($1.to_i,$2.to_i,$3.to_i) : nil}
15
+ alias getBirthday get_birthday
16
+
17
+ def get_sex() invoke_get("SEX") end
18
+ def_parser(:sex)
19
+ alias getSex get_sex
20
+
21
+ def get_language() parse :language, invoke_get("LANGUAGE") end
22
+ def_parser(:language){|str| str.empty? ? str : str.split(' ',2)[0]}
23
+ alias getLanguage get_language
24
+
25
+ def get_country() parse :country, invoke_get("COUNTRY") end
26
+ def_parser(:country){|str| str.empty? ? str : str.split(' ',2)[0]}
27
+ alias getCountry get_country
28
+
29
+ def get_province() invoke_get("PROVINCE") end
30
+ def_parser(:province)
31
+ alias getProvince get_province
32
+
33
+ def get_city() invoke_get("CITY") end
34
+ def_parser(:city)
35
+ alias getCity get_city
36
+
37
+ def get_phone_home() invoke_get("PHONE_HOME") end
38
+ def_parser(:phone_home)
39
+ alias getPhoneHome get_phone_home
40
+
41
+ def get_phone_office() invoke_get("PHONE_OFFICE") end
42
+ def_parser(:phone_office)
43
+ alias getPhoneOffice get_phone_office
44
+
45
+ def get_phone_mobile() invoke_get("PHONE_MOBILE") end
46
+ def_parser(:phone_mobile)
47
+ alias getPhoneMobile get_phone_mobile
48
+
49
+ def get_homepage() invoke_get("HOMEPAGE") end
50
+ def_parser(:homepage)
51
+ alias getHomepage get_homepage
52
+
53
+ def get_about() invoke_get("ABOUT") end
54
+ def_parser(:about)
55
+ alias getAbout get_about
56
+
57
+ def get_has_call_equipment?() parse :has_call_equipment, invoke_get("HASCALLEQUIPMENT") end
58
+ def_parser(:has_call_equipment, "HASCALLEQUIPMENT"){|str| str == 'TRUE' ? true : false}
59
+ alias getHasCallEquipment? get_has_call_equipment?
60
+
61
+ def get_is_video_capable?() parse :is_video_capable, invoke_get("IS_VIDEO_CAPABLE") end
62
+ def_parser(:is_video_capable){|str| str == 'TRUE' ? true : false}
63
+ alias getIsVideoCapable? get_is_video_capable?
64
+
65
+ def get_is_voicemail_capable?() parse :is_voicemail_capable, invoke_get("IS_VOICEMAIL_CAPABLE") end
66
+ def_parser(:is_voicemail_capable){|str| str == 'TRUE' ? true : false}
67
+ alias getIsVoicemailCapable? get_is_voicemail_capable?
68
+
69
+ def get_buddy_status() parse :buddy_status, invoke_get("BUDDYSTATUS") end
70
+ def_parser(:buddy_status, 'BUDDYSTATUS'){|str| str.to_i}
71
+ alias getBuddyStatus get_buddy_status
72
+
73
+ def get_is_authorized?() parse :is_authorized, invoke_get("ISAUTHORIZED") end
74
+ def_parser(:is_authorized, 'ISAUTHORIZED'){|str| str == 'TRUE' ? true : false}
75
+ alias getIsAuthorized? get_is_authorized?
76
+
77
+ def get_is_blocked?() parse :is_blocked, invoke_get("ISBLOCKED") end
78
+ def_parser(:is_blocked, 'ISBLOCKED'){|str| str == 'TRUE' ? true : false}
79
+ alias getIsBlocked? get_is_blocked?
80
+
81
+ def get_online_status() parse :online_status, invoke_get("ONLINESTATUS") end
82
+ def_parser(:online_status, 'ONLINESTATUS')
83
+ alias getOnlineStatus get_online_status
84
+
85
+ def get_last_online_timestamp() parse :last_online_timestamp, invoke_get("LASTONLINETIMESTAMP") end
86
+ def_parser(:last_online_timestamp, "LASTONLINETIMESTAMP"){|str| str.empty? ? nil : Time.at(str.to_i)}
87
+ alias getLastOnlineTimestamp get_last_online_timestamp
88
+
89
+ def get_can_leave_vm?() parse :can_leave_vm, invoke_get("CAN_LEAVE_VM") end
90
+ def_parser(:can_leave_vm){|str| str == 'TRUE' ? true : false}
91
+ alias getCanLeaveVM? get_can_leave_vm?
92
+
93
+ def get_speed_dial() invoke_get("SPEEDDIAL") end
94
+ def_parser(:speed_dial, 'SPEEDDIAL')
95
+ alias getSpeedDial get_speed_dial
96
+
97
+ def get_received_auth_request() invoke_get("RECEIVEDAUTHREQUEST") end
98
+ def_parser(:received_auth_request,"RECEIVEDAUTHREQUEST")
99
+ alias getReceivedAuthRequest get_received_auth_request
100
+
101
+ def get_mood_text() invoke_get("MOOD_TEXT") end
102
+ def_parser(:mood_text)
103
+ alias getMoodText get_mood_text
104
+
105
+ def get_rich_mood_text() invoke_get("RICH_MOOD_TEXT") end
106
+ def_parser(:rich_mood_text)
107
+ alias getRichMoodText get_rich_mood_text
108
+
109
+ def get_aliases() invoke_get("ALIASES") end
110
+ def_parser(:aliases)
111
+ alias getAliases get_aliases
112
+
113
+ def get_timezone() parse :timezone, invoke_get("TIMEZONE") end
114
+ def_parser(:timezone){|str| str.to_i}
115
+ alias getTimezone get_timezone
116
+
117
+ def get_is_cf_active?() parse :is_cf_active, invoke_get("IS_CF_ACTIVE") end
118
+ def_parser(:is_cf_active){|str| str == 'TRUE' ? true : false}
119
+ alias getIsCFActive? get_is_cf_active?
120
+
121
+ def get_nrof_authed_buddies() parse :nrof_authed_buddies, invoke_get("NROF_AUTHED_BUDDIES") end
122
+ def_parser(:nrof_authed_buddies){|str| str.to_i}
123
+ alias getNrofAuthedBuddies get_nrof_authed_buddies
124
+
125
+ def get_displayname() invoke_get("DISPLAYNAME") end
126
+ def_parser(:displayname)
127
+ alias getDisplayname get_displayname
79
128
 
80
- def setBuddyStatus(statusCode, msg="")
81
- raise ArgumentErorr unless statusCode.to_i == 1 or statusCode.to_i == 2
82
- invoke_set('BUDDYSTATUS',"#{statusCode} #{msg}")
83
- end
129
+ def get_avatar(file_path) invoke("GET USER #{@id} AVATAR 1 #{file_path}") =~ /^USER #{@id} AVATAR \d+ (.+)$/ end
130
+ def_parser :avatar, 'AVATAR 1'
131
+ alias getAvatar get_avatar
132
+
133
+ def set_buddy_status(statusCode, msg="")
134
+ raise ArgumentErorr unless statusCode.to_i == 1 or statusCode.to_i == 2
135
+ invoke_set('BUDDYSTATUS',"#{statusCode} #{msg}")
136
+ end
137
+ alias setBuddyStatus set_buddy_status
84
138
 
85
- def setIsBlocked(flag) invoke_set('ISBLOCKED', flag._str); end
139
+ def set_is_blocked(flag) invoke_set('ISBLOCKED', flag ? 'TRUE' : 'FALSE') end
140
+ alias setIsBlocked set_is_blocked
86
141
 
87
- def setIsAuthorized(flag) invoke_set('ISAUTHORIZED', flag._str); end
142
+ def set_is_authorized(flag) invoke_set('ISAUTHORIZED', flag ? 'TRUE' : 'FALSE') end
143
+ alias setIsAuthorized set_is_authorized
88
144
 
89
- def setSpeedDial(numbers) invoke_set('SPEEDDIAL', numbers); end
145
+ def set_speed_dial(numbers) invoke_set('SPEEDDIAL', numbers) end
146
+ alias setSpeedDial set_speed_dial
90
147
 
91
- def setDisplayName(name) invoke_set('DISPLAYNAME', name);end
92
-
93
-
94
- def addContactList msg=""
95
- val = invoke_set("BUDDYSTATUS","2 #{msg}")
96
- val == 2 or val == 3
97
- end
98
-
99
- def addedContactList?
100
- val = getBuddyStatus
101
- val == 3 or val == 2
102
- end
148
+ def set_displayname(name) invoke_set('DISPLAYNAME', name);end
149
+ alias setDisplayname set_displayname
150
+
151
+
152
+ def add_contactlist msg=""
153
+ val = invoke_set("BUDDYSTATUS","2 #{msg}")
154
+ val == 2 or val == 3
155
+ end
156
+ alias addContactlist add_contactlist
157
+
158
+ def added_contactlist?
159
+ val = get_buddy_status
160
+ val == 3 or val == 2
161
+ end
162
+ alias addedContactlist? added_contactlist?
103
163
 
104
- def delContactList
105
- invoke_set("BUDDYSTATUS","1") == 1
106
- end
164
+ def del_contactlist
165
+ invoke_set("BUDDYSTATUS","1") == 1
107
166
  end
167
+ alias delContactlist del_contactlist
108
168
  end
109
169
  end
@@ -1,9 +1,9 @@
1
1
  module SkypeAPI
2
2
  module VERSION
3
3
  MAJOR = 0
4
- MINOR = 2
5
- TINY = 3
6
-
4
+ MINOR = 3
5
+ TINY = 1
6
+
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
 
9
9
  def self.to_s
@@ -1,60 +1,67 @@
1
1
  module SkypeAPI
2
- module Object
3
- class VoiceMail < AbstractObject
4
- OBJECT_NAME = "VOICEMAIL"
2
+ class VoiceMail < AbstractObject
3
+ OBJECT_NAME = "VOICEMAIL"
5
4
 
6
- def self.create target
7
- @@skypeApi.invoke "CALLVOICEMAIL #{target}"
8
- end
9
-
10
- def self.open id
11
- @@skypeApi.invoke "OPEN VOICEMAIL #{id}"
12
- end
5
+ def self.create target
6
+ SkypeAPI.invoke "CALLVOICEMAIL #{target}"
7
+ end
13
8
 
14
- getter :Type, 'TYPE'
15
- getter :Partner, 'PARTNER_HANDLE' do |str|
16
- @@skypeApi.user str
17
- end
18
- getter :PartnerDispname, 'PARTNER_DISPNAME'
19
- getter :Status, 'STATUS'
20
- getter :FailureReason, 'FAILUREREASON'
21
- #getter :Subject, 'SUBJECT'
22
- getter :Timestamp, 'TIMESTAMP' do |str|
23
- if str.empty? then nil else Time.at(str.to_i) end
24
- end
25
- getter :Duration, 'DURATION' do |str|
26
- str.to_i
27
- end
28
- getter :AllowedDuration, 'ALLOWED_DURATION' do |str|
29
- str.to_i
30
- end
9
+ def self.open id
10
+ SkypeAPI.invoke "OPEN VOICEMAIL #{id}"
11
+ end
31
12
 
32
- #def alter action
33
- # @@skypeApi.invoke "ALTER VOICEMAIL #{id} #{action}"
34
- #end
13
+ def get_type() invoke_get("TYPE") end
14
+ def_parser(:type)
15
+ alias getType get_type
16
+
17
+ def get_partner() parse :partner, invoke_get("PARTNER_HANDLE") end
18
+ def_parser(:partner,"PARTNER_HANDLE"){|str| SkypeAPI::User.new str}
19
+ alias getPartner get_partner
20
+
21
+ def get_partner_dispname() invoke_get("PARTNER_DISPNAME") end
22
+ def_parser(:partner_dispname)
23
+ alias getPartnerDispname get_partner_dispname
24
+
25
+ def get_status() invoke_get("STATUS") end
26
+ def_parser(:status)
27
+ alias getStatus get_status
28
+
29
+ def get_failure_reason() invoke_get("FAILUREREASON") end
30
+ def_parser(:failure_reason,"FAILUREREASON")
31
+ alias getFailureReason get_failure_reason
32
+
33
+ def get_timestamp() parse :timestamp, invoke_get("TIMESTAMP") end
34
+ def_parser(:timestamp){|str| str.empty? ? nil : Time.at(str.to_i)}
35
+ alias getTimestamp get_timestamp
36
+
37
+ def get_duration() parse :duration, invoke_get("DURATION") end
38
+ def_parser(:duration){|str| str.to_i}
39
+ alias getDuration get_duration
40
+
41
+ def get_allowed_duration() parse :allowed_duration, invoke_get("ALLOWED_DURATION") end
42
+ def_parser(:allowed_duration){|str| str.to_i}
43
+ alias getAllowedDuration get_allowed_duration
44
+ #def alter action
45
+ # @@skypeApi.invoke "ALTER VOICEMAIL #{id} #{action}"
46
+ #end
35
47
 
36
- def startPlayback
37
- invoke_alter "STARTPLAYBACK"
38
- end
39
- def stopPlayback
40
- invoke_alter "STOPPLAYBACK"
41
- end
42
- def upload
43
- invoke_alter "UPLOAD"
44
- end
45
- def download
46
- invoke_alter "DOWNLOAD"
47
- end
48
- def startRecording
49
- invoke_alter "STARTRECORDING"
50
- end
51
- def stopRecording
52
- invoke_alter "STOPRECORDING"
53
- end
54
- def delete
55
- invoke_alter "DELETE"
56
- end
48
+ def start_playback() invoke_alter "STARTPLAYBACK" end
49
+ alias startPlayback start_playback
57
50
 
58
- end
51
+ def stop_playback() invoke_alter "STOPPLAYBACK" end
52
+ alias stopPlayback stop_playback
53
+
54
+ def upload() invoke_alter "UPLOAD" end
55
+
56
+ def download() invoke_alter "DOWNLOAD" end
57
+
58
+ def start_recording() invoke_alter "STARTRECORDING" end
59
+ alias startRecording start_recording
60
+
61
+ def stop_recording() invoke_alter "STOPRECORDING" end
62
+ alias stopRecording stop_recording
63
+
64
+ def delete() invoke_alter "DELETE" end
65
+
59
66
  end
60
67
  end
@@ -0,0 +1,10 @@
1
+
2
+ Spec::Matchers.define :be_boolean do
3
+ match do |actual|
4
+ actual == true or actual == false
5
+ end
6
+ # failure_message_for_should do |actual|
7
+ # end
8
+ # failure_message_for_should_not do |actual|
9
+ # end
10
+ end
@@ -0,0 +1,76 @@
1
+ # To change this template, choose Tools | Templates
2
+ # and open the template in the editor.
3
+
4
+ require 'skypeapi'
5
+
6
+ describe SkypeAPI::Application do
7
+ before(:all) do
8
+ SkypeAPI.init
9
+ SkypeAPI.start_messageloop
10
+ SkypeAPI.attach_wait
11
+ end
12
+
13
+ after :all do
14
+ SkypeAPI.close
15
+ end
16
+
17
+ before :each do
18
+ @app = SkypeAPI::Application.new('testApp')
19
+ @app.create
20
+ end
21
+
22
+ after :each do
23
+ @app.delete unless @app.nil?
24
+ end
25
+
26
+ it 'get_connectable each should be instance of User' do
27
+ pending 'connectable empty' if @app.get_connectable.empty?
28
+ @app.get_connectable.each{|user| user.should be_instance_of SkypeAPI::User}
29
+ end
30
+
31
+ it 'get_connecting each should be instance of User' do
32
+ pending 'connection empty' if @app.get_connecting.empty?
33
+ @app.get_connecting.each{|user| user.should be_instance_of SkypeAPI::User}
34
+ end
35
+
36
+ it 'get_streams each should be instance of Stream' do
37
+ pending 'streams empty' if @app.get_streams.empty?
38
+ @app.get_streams.each{|stream| stream.should be_instance_of SkypeAPI::Stream}
39
+ end
40
+
41
+ it 'get_sending each should {:stream,:bytes}' do
42
+ pending 'sending empty' if @app.get_sending.empty?
43
+ @app.get_sending.each{|hash|
44
+ hash[:stream].should be_instance_of SkypeAPI::Stream
45
+ hash[:bytes].should be_kind_of Integer
46
+ }
47
+ end
48
+
49
+ it 'get_received each should {:stream,:bytes}' do
50
+ pending 'received empty' if @app.get_received.empty?
51
+ @app.get_received.each{|hash|
52
+ hash[:stream].should be_instance_of SkypeAPI::Stream
53
+ hash[:bytes].should be_kind_of Integer
54
+ }
55
+ end
56
+
57
+ it 'connect should be true' do
58
+ @app.connect('echo123').should be_true
59
+ end
60
+
61
+ it 'write should be true' do
62
+ pending 'need connection stream'
63
+ @app.write(stream,msg).should be_true
64
+ end
65
+
66
+ #assert(app.datagram(stream,msg))
67
+ #assert_instance_of(String, app.read())
68
+ #assert(app.disconnect(stram))
69
+
70
+ it 'delete should be true' do
71
+ @app.delete.should be_true
72
+ @app = nil
73
+ end
74
+
75
+ end
76
+