Ruby4Skype 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,186 @@
1
+ module SkypeAPI
2
+ module Object
3
+ class Chat < AbstractObject
4
+ OBJECT_NAME = "CHAT"
5
+
6
+ getter :Name, 'NAME'
7
+ getter :Timestamp, 'TIMESTAMP' do |str|
8
+ str.to_i
9
+ end
10
+ getter :Adder, 'ADDER' do |str|
11
+ str.empty? ? nil : @@skypeApi.user(str)
12
+ end
13
+ getter :Status, 'STATUS'
14
+ getter :Posters, 'POSTERS' do |str|
15
+ str.split(', ').map do |handle|
16
+ @@skypeApi.user handle
17
+ end
18
+ end
19
+ getter :Members, 'MEMBERS' do |str|
20
+ str.split(' ').map do |handle|
21
+ @@skypeApi.user handle
22
+ end
23
+ end
24
+ getter :Topic, 'TOPIC'
25
+ getter :TopicXML, 'TOPICXML'
26
+ getter :ChatMessages, 'CHATMESSAGES' do |str|
27
+ str.split(' ').map do |id|
28
+ @@skypeApi.chatMessage id
29
+ end
30
+ end
31
+ getter :ActiveMembers, 'ACTIVEMEMBERS' do |str|
32
+ str.split(' ').map do |handle|
33
+ @@skypeApi.user handle
34
+ end
35
+ end
36
+ getter :FriendlyName, 'FRIENDLYNAME'
37
+ getter :RecentChatMessages, 'RECENTCHATMESSAGES' do |str|
38
+ str.split(' ').map do |handle|
39
+ @@skypeApi.chatMessage handle
40
+ end
41
+ end
42
+ getter :Bookmarked, 'BOOKMARKED' do |str|
43
+ str._flag
44
+ end
45
+ getter :MemberObjects, 'MEMBEROBJECTS' do |str|
46
+ str.split(', ').map do |id|
47
+ @@skypeApi.chatMember id
48
+ end
49
+ end
50
+ getter :PasswordHint, 'PASSWORDHINT'
51
+ getter :GuideLines, 'GUIDELINES'
52
+ getter :Options, 'OPTIONS' do |str|
53
+ str.to_i
54
+ end
55
+ getter :Description, 'DESCRIPTION'
56
+ getter :DialogPartner, 'DIALOG_PARTNER' do |str|
57
+ if str.empty?
58
+ nil
59
+ else
60
+ @@skypeApi.user str
61
+ end
62
+ end
63
+ getter :ActivityTimestamp, 'ACTIVITY_TIMESTAMP' do |str|
64
+ str.to_i
65
+ end
66
+ getter :Type, 'TYPE'
67
+ getter :MyStatus, 'MYSTATUS'
68
+ getter :MyRole, 'MYROLE'
69
+ getter :Blob, 'BLOB'
70
+ getter :Applicants, 'APPLICANTS' do |str|
71
+ str.split(' ').map do |handle|
72
+ @@skypeApi.user handle
73
+ end
74
+ end
75
+
76
+
77
+ def self.create *users
78
+ retVal = @@skypeApi.sendCMD "CHAT CREATE #{users.join(', ')}"
79
+ retVal =~ /^CHAT ([^ ]+) STATUS (.+)$/
80
+ chatID, status = $1, $2
81
+ return @@skypeApi.chat(chatID)#, status
82
+ end
83
+
84
+ def self.findUsingBlob blob
85
+ retVal = @@skypeApi.sendCMD "CHAT FINDUSINGBLOB #{blob}"
86
+ retVal =~ /^CHAT ([^ ]+) STATUS (.+)$/
87
+ chatID, status = $1, $2
88
+ return @@skypeApi.chat(chatID)#, status
89
+ end
90
+
91
+ def self.createUsingBlob blob
92
+ retVal = @@skypeApi.sendCMD "CHAT CREATEUSINGBLOB #{blob}"
93
+ retVal =~ /^CHAT ([^ ]+) STATUS (.+)$/
94
+ chatID, status = $1, $2
95
+ return @@skypeApi.chat(chatID)#, status
96
+ end
97
+
98
+ #���[
99
+ #def open
100
+ # retVal = sendCMD "OPEN CHAT #{@id}"
101
+ # retVal =~ /^OPEN CHAT (.+)$/
102
+ # return @@skypeApi.chat($1)
103
+ #end
104
+
105
+ def setTopic str
106
+ sendAlter "SETTOPIC", str
107
+ end
108
+
109
+ def setTopicXML str
110
+ sendAlter "SETTOPICXML", str
111
+ end
112
+
113
+ def addMembers *member
114
+ sendAlter "ADDMEMBERS", member.join(', ')
115
+ end
116
+
117
+ def leave
118
+ sendAlter "LEAVE"
119
+ end
120
+
121
+ def bookmarked
122
+ sendAlter "BOOKMARK"
123
+ end
124
+
125
+ def unbookmarked
126
+ sendAlter "UNBOOKMARK"
127
+ end
128
+
129
+ def join
130
+ #
131
+ sendAlter "JOIN"
132
+ end
133
+
134
+ def clearRecentMessages
135
+ sendAlter "CLEARRECENTMESSAGES"
136
+ end
137
+
138
+ def setAlertString str
139
+ sendAlter "SETALERTSTRING", str
140
+ end
141
+
142
+ def acceptadd
143
+ sendAlter "ACCEPTADD"
144
+ end
145
+
146
+ def disband
147
+ sendAlter "DISBAND"
148
+ end
149
+
150
+
151
+ def setPassword password, passwordHint=''
152
+ sendAlter "SETPASSWORD", password + ' ' + passwordHint
153
+ end
154
+
155
+ def enterPassword password
156
+ sendAlter "ENTERPASSWORD", password
157
+ end
158
+
159
+ def setOptions option
160
+ sendAlter "SETOPTIONS", option
161
+ end
162
+
163
+ def kick *users
164
+ users = users.join ', '
165
+ sendAlter "KICK", users
166
+ end
167
+
168
+ def kickBan *users
169
+ users = users.join ', '
170
+ sendAlter "KICKBAN", users
171
+ end
172
+
173
+ def setGuideLines guidlines
174
+ sendAlter 'SETGUIDELINES', guidlines
175
+ end
176
+
177
+ def setOptions optionsBitmap
178
+ sendAlter 'SETOPTIONS', optionsBitmap.to_s
179
+ end
180
+
181
+ def sendMessage msg
182
+ @@skypeApi.ChatMessage.create self, msg
183
+ end
184
+ end
185
+ end
186
+ end
@@ -0,0 +1,33 @@
1
+ module SkypeAPI
2
+ module Object
3
+ class ChatMember < AbstractObject
4
+ OBJECT_NAME = "CHATMEMBER"
5
+
6
+ getter :Chat, 'CHATNAME' do |str|
7
+ @@skypeApi.chat(str)
8
+ end
9
+
10
+ getter :User,'IDENTITY' do |str|
11
+ @@skypeApi.user str
12
+ end
13
+
14
+ getter :Role, 'ROLE'
15
+
16
+ getter :IsActive, 'IS_ACTIVE' do |str|
17
+ str._flag
18
+ end
19
+
20
+ def setRoleTo role
21
+ sendAlter('SETROLETO', role)
22
+ end
23
+
24
+ def canSetRoleTo role
25
+ #ALTER�ŕԂ茌������ɂ߂ē����B
26
+ res = sendCMD("ALTER CHATMEMBER #{@id} CANSETROLETO #{role}")
27
+ res =~ /ALTER CHATMEMBER CANSETROLETO (TRUE|FALSE)/
28
+ $1._flag
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,64 @@
1
+ module SkypeAPI
2
+ module Object
3
+ class ChatMessage < AbstractObject
4
+ OBJECT_NAME = "CHATMESSAGE"
5
+
6
+ def self.create chatId ,msg
7
+ res = @@skypeApi.sendCMD "CHATMESSAGE #{chatId} #{msg}"
8
+ if res =~ /^CHATMESSAGE (\d+) STATUS (.+)$/
9
+ return @@skypeApi.chatMessage($1)#, $2
10
+ else
11
+ raise #????
12
+ end
13
+ end
14
+
15
+ getter :Body, 'BODY'
16
+ getter :Timestamp, 'TIMESTAMP' do |str|
17
+ str.to_i
18
+ end
19
+ getter :Partner, 'PARTNER_HANDLE' do |str|
20
+ @@skypeApi.user str
21
+ end
22
+ getter :PartnerDispname, 'PARTNER_DISPNAME'
23
+ getter :From, 'FROM_HANDLE' do |str|
24
+ @@skypeApi.user str
25
+ end
26
+ getter :FromDispname, 'FROM_DISPNAME'
27
+ getter :Type, 'TYPE'
28
+ getter :Status, 'STATUS'
29
+ getter :LeaveReason, 'LEAVEREASON'
30
+ getter :Chat, 'CHATNAME' do |str|
31
+ @@skypeApi.chat str
32
+ end
33
+ getter :Users, 'USERS' do |str|
34
+ str.split(',').map do |handle|
35
+ @@skypeApi.user handle
36
+ end
37
+ end
38
+ getter :IsEditable, 'IS_EDITABLE' do |str|
39
+ str._flag
40
+ end
41
+ getter :EditedBy, 'EDITED_BY' do |str|
42
+ str.empty? ? nil : @@skypeApi.user(str)
43
+ end
44
+ getter :EditedTimestamp, 'EDITED_TIMESTAMP' do |str|
45
+ str.to_i
46
+ end
47
+ getter :Options, 'OPTIONS' do |str|
48
+ str.to_i
49
+ end
50
+ getter :Role, 'ROLE'
51
+
52
+ def setSeen
53
+ str = @@skypeApi.sendCMD "SET CHATMESSAGE #{@id} SEEN"
54
+ if str =~ /^CHATMESSAGE #{@id} STATUS (.+)$/
55
+ return true
56
+ else
57
+ raise #????
58
+ end
59
+ end
60
+
61
+ def setBody (val) sendSet('BODY',val._str); end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,46 @@
1
+ module SkypeAPI
2
+ module Object
3
+ class Event < AbstractObject
4
+ OBJECT_NAME = "EVENT"
5
+
6
+ def self.create id, caption, hint, block=Proc.new
7
+ res = @@skypeApi.sendCMD "CREATE EVENT #{id} CAPTION #{caption} HINT #{hint}"
8
+ res == "EVENT #{id} CREATED"
9
+ instance = new id
10
+ instance.setNotify block if block
11
+ instance
12
+ end
13
+
14
+ def self.setNotify id=nil, block=Proc.new
15
+ @notify[id] = block
16
+ end
17
+
18
+ def self.notified msg
19
+ if msg =~ /^([^ ]+) CLICKED$/m
20
+ id = $1
21
+ instance = new $1
22
+ @notify[nil].call instance if @notify[nil]
23
+ @notify[id].call instance if @notify[id]
24
+ @@instance[self][id].notified if @@instance[self][id]
25
+ end
26
+ end
27
+
28
+ def notified
29
+ @notify.call self if @notify
30
+ end
31
+
32
+ def setNotify block=Proc.new
33
+ @notify = block
34
+ end
35
+
36
+ def self.delete id
37
+ new(id).delete
38
+ end
39
+
40
+ def delete
41
+ res = sendCMD "DELETE EVENT #{@id}"
42
+ res == "DLEETE EVENT #{@id}"
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,31 @@
1
+ module SkypeAPI
2
+ module Object
3
+ class FileTransfer < AbstractObject
4
+ OBJECT_NAME = "FILETRANSFER"
5
+
6
+ getter :Type, 'TYPE'
7
+ getter :Status, 'STATUS'
8
+ getter :FailureReason, 'FAILUREREASON'
9
+ getter :Partner, 'PARTNER_HANDLE' do |str|
10
+ @@skypeApi.user str
11
+ end
12
+ getter :PartnerDispname, 'PARTNER_DISPNAME'
13
+ getter :StartTime, 'STARTTIME' do |str|
14
+ str.to_i
15
+ end
16
+ getter :FinishTime, 'FINISHTIME' do |str|
17
+ str.to_i
18
+ end
19
+ getter :FilePath, 'FILEPATH'
20
+ getter :FileSize, 'FILESIZE' do |str|
21
+ str.to_i
22
+ end
23
+ getter :BytesPerSecond, 'BYTESPERSECOND' do |str|
24
+ str.to_i
25
+ end
26
+ getter :BytesTransferred, 'BYTESTRANSFERRED' do |str|
27
+ str.to_i
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,81 @@
1
+ module SkypeAPI
2
+ module Object
3
+ class Group < AbstractObject
4
+ OBJECT_NAME = "GROUP"
5
+
6
+ def self.create family
7
+ @@skypeApi.sendCMD("CREATE GROUP #{family}")
8
+ group = nil
9
+ tmp = nil
10
+ if @@skypeApi.Group.notify[:displayname] and @@skypeApi.Group.notify[:displayname][family]
11
+ tmp = @@skypeApi.Group.notify[:displayname][family]
12
+ end
13
+ @@skypeApi.Group.setNotify :DisplayName, family do |g|
14
+ group = g
15
+ end
16
+ until group
17
+ @@skypeApi.polling
18
+ sleep 0.0123
19
+ end
20
+ if tmp
21
+ @@skypeApi.Group.setNotify :DisplayName, family, tmp
22
+ tmp.call group
23
+ else
24
+ @@skypeApi.Group.notify[:displayname][family] = nil
25
+ end
26
+ group
27
+ #ThreadSafe ����ς��낤�Ȃ��B�B�B
28
+ end
29
+
30
+ getter :Type, 'TYPE'
31
+ getter :CustomGroupID, 'CUSTOM_GROUP_ID' do |str|
32
+ str.to_i
33
+ end
34
+ getter :DisplayName, 'DISPLAYNAME'
35
+ getter :NrofUsers, 'NROFUSERS' do |str|
36
+ str.to_i
37
+ end
38
+ getter :NrofUsersOnline, 'NROFUSERS_ONLINE' do |str|
39
+ str.to_i
40
+ end
41
+ getter :Users, 'USERS' do |str|
42
+ str.split('./')
43
+ end
44
+ getter :Visible, 'VISIBLE' do |str|
45
+ str._flag
46
+ end
47
+ getter :Expanded, 'EXPANDED' do |str|
48
+ str._flag
49
+ end
50
+
51
+ def setDisplayName name
52
+ sendSet "DISPLAYNAME", name
53
+ end
54
+
55
+ def delete
56
+ sendEcho "DELETE GROUP #{@id}"
57
+ end
58
+
59
+ def addUser user
60
+ sendAlter "ADDUSER", user
61
+ end
62
+
63
+ def removeUser user
64
+ sendAlter "REMOVEUSER", user
65
+ end
66
+
67
+ def share text
68
+ sendAlter "Share", text
69
+ end
70
+
71
+ def accept
72
+ sendAlter "ACCEPT"
73
+ end
74
+
75
+ def decline
76
+ sendAlter "DECLINE"
77
+ end
78
+
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,64 @@
1
+ module SkypeAPI
2
+ module Object
3
+ class MenuItem < AbstractObject
4
+ OBJECT_NAME = 'MENU_ITEM'
5
+
6
+ def self.create h, block=Proc.new
7
+ raise ArgumentError unless h[:id] and h[:context] and h[:context]
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]}"}"
10
+ res == "MENU_ITEM #{h[:id]} CREATED"
11
+ instance = new h[:id]
12
+ instance.setNotify block if block
13
+ instance
14
+ end
15
+
16
+ def self.setNotify sym=nil, block=Proc.new
17
+ @notify[sym] = block
18
+ end
19
+
20
+ def self.notified msg
21
+ if msg =~ /^([^ ]+) CLICKED( ([^ ]+))? CONTEXT ([^ ]+)( CONTEXT_ID (.+))?$/m
22
+ id = $1; context = $4; userID = $3; contextID = $6
23
+ user = userID ? @@skypeApi.user(userID) : nil
24
+ instance = new $1
25
+ @notify[nil].call instance, context, user, contextID if @notify[nil]
26
+ @notify[id].call instance, context, user, contextID if @notify[id]
27
+ @@instance[self][id].notified context, user, contextID if @@instance[self][id]
28
+ end
29
+ end
30
+
31
+ def notified context, user, contextID
32
+ @notify.call context, user, contextID if @notify
33
+ end
34
+
35
+ def setNotify block=Proc.new
36
+ @notify = block
37
+ end
38
+
39
+ def self.delete id
40
+ new(id).delete
41
+ end
42
+
43
+ def delete
44
+ res = @@skypeApi.sendCMD "DELETE MENU_ITEM #{@id}"
45
+ res == "DELETE MENU_ITEM #{@id}"
46
+ end
47
+
48
+ def setCaption value
49
+ res = sendCMD "SET MENU_ITEM #{@id} CAPTION #{value}"
50
+ res == "MENU_ITEM #{@id} CAPTION \"#{value}\""
51
+ end
52
+
53
+ def setHint value
54
+ res = sendCMD "SET MENU_ITEM #{@id} HINT #{value}"
55
+ res == "MENU_ITEM #{@id} HINT \"#{value}\""
56
+ end
57
+
58
+ def setEnabled value
59
+ res = sendCMD "SET MENU_ITEM #{@id} ENABLED #{value._str}"
60
+ res == "MENU_ITEM #{@id} ENABLED #{value._str}"
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,46 @@
1
+ module SkypeAPI
2
+ module Object
3
+ class Message < AbstractObject
4
+ OBJECT_NAME = "MESSAGE"
5
+
6
+ PROPERTY2METHOD = {
7
+ 'TIMESTAMP' => :timestamp,
8
+ 'PARTNER_HANDLE' => :partnerHandle,
9
+ 'PARTNER_DISPNAME' => :partnerDispname,
10
+ 'CONF_ID' => :confIdD,
11
+ 'TYPE' => :type,
12
+ 'STATUS' => :status,
13
+ 'FAILUREREASON' => :failureReason,
14
+ 'BODY' => :body,
15
+ }
16
+
17
+ def self.create target,text
18
+ if defined? target.getHandle
19
+ target = target.getHandle
20
+ elsif target.class == String
21
+ else
22
+ raise target
23
+ end
24
+ res = @skypeApi.sendOne "MESSAGE #{target} #{text}","MESSAGE"
25
+ if res =~ /^(\d+) STATUS (.+)$/
26
+ return @skypeApi.getMessage($1),"getStatus",$2
27
+ else
28
+ raise #????
29
+ end
30
+ end
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
40
+
41
+ #def setSeen
42
+ # str2object sendOne("SET MESSAGE #{@id} SEEN","SET MESSAGE #{@id} STATUS")
43
+ #end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,122 @@
1
+ require 'date'
2
+
3
+ module SkypeAPI
4
+ module Object
5
+
6
+
7
+ #������R�s�y�U�݁B
8
+ module Notify
9
+ def setNotify property=nil,value=nil, block=Proc.new
10
+ property = property.to_s.downcase.to_sym if property
11
+ value = value.to_s.upcase if value.class == Symbol
12
+ @notify[property] = Hash.new unless @notify[property]
13
+ @notify[property][value] = block
14
+ end
15
+
16
+ def delNotify property=nil,value=nil
17
+ @notify[property].delete value
18
+ end
19
+
20
+ def notify
21
+ @notify
22
+ end
23
+
24
+ def notified property,value
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]
28
+ end
29
+ if @notify[property]
30
+ @notify[property][nil].call value if @notify[property][nil]
31
+ @notify[property][value].call if @notify[property][value]
32
+ end
33
+ end
34
+ end
35
+
36
+ module Get
37
+ def getter methodName, skypeProperty=methodName.to_s.upcase, &callBack
38
+ defineMethod = self == SkypeAPI ? self.class.method(:define_method) : method(:define_method)
39
+ defineMethod.call 'get' + methodName.to_s do
40
+ str = sendGet skypeProperty
41
+ callBack ? callBack.call(str) : str
42
+ end
43
+ self::P2M[skypeProperty] = methodName.to_sym
44
+ self::V2O[skypeProperty] = callBack if callBack
45
+ end
46
+
47
+ def notice methodName,skypeProperty,&block
48
+ self::P2M[skypeProperty] = methodName.to_sym
49
+ self::V2O[methodName] = block if block
50
+ end
51
+ end
52
+
53
+ class AbstractObject
54
+ extend SkypeAPI::Object::Notify
55
+ extend Forwardable
56
+ extend SkypeAPI::Object::Get
57
+ include SkypeAPI::Object::Notify
58
+ include SkypeAPI::ShareFunctions
59
+
60
+ #�p�������ނ�S������B@@instance[class][id of instance]
61
+ @@instance = Hash.new do |hash,key|
62
+ hash[key] = Hash.new
63
+ end
64
+ @@skypeApi = SkypeAPI
65
+
66
+ #�萔�͌p�����Ăق����Ȃ��ׁA�•ʂɐ����B
67
+ #Module include self.class::P2M
68
+ #Module extend self::P2M
69
+ #Class P2M
70
+ #Instance P2M �ŃA�N�Z�X�B
71
+ def self.inherited sub
72
+ sub.const_set :P2M, Hash.new{|hash,key| hash[key] = key}
73
+ sub.const_set :V2O, Hash.new
74
+ sub.instance_variable_set :@notify, Hash.new
75
+ end
76
+
77
+ #extend����Notify���I�[�o�[���C�h�B
78
+ #����Ă�̂́A�l�̕ϊ��Ǝ�����notify�ƃC���X�^���X��notify�񂵁B
79
+ def self.notified msg
80
+ if msg =~ /^([^ ]+) ([^ ]+) (.*)$/m
81
+ id = $1; skypeProperty = $2; value = $3
82
+ instance = new id
83
+ property = self::P2M[skypeProperty].to_s.downcase.to_sym if self::P2M[skypeProperty].class == Symbol
84
+ value = self::V2O[skypeProperty].call value if self::V2O[skypeProperty]
85
+
86
+ if @notify[nil]
87
+ @notify[nil][nil].call instance, property, value if @notify[nil][nil]
88
+ @notify[nil][value].call instance, property if @notify[nil][value]
89
+ end
90
+ if @notify[property]
91
+ @notify[property][nil].call instance, value if @notify[property][nil]
92
+ @notify[property][value].call instance if @notify[property][value]
93
+ end
94
+ @@instance[self][id].notified property,value if @@instance[self][id]
95
+ end
96
+ end
97
+
98
+ def self.new id
99
+ if @@instance[self][id]
100
+ return @@instance[self][id]
101
+ else
102
+ instance = super id
103
+ instance.instance_variable_set :@notify, Hash.new
104
+ @@instance[self][id] = instance
105
+ return instance
106
+ end
107
+ end
108
+
109
+ def initialize id
110
+ @id = id
111
+ end
112
+
113
+ def to_s
114
+ @id.to_s
115
+ end
116
+
117
+ #def_delegators :@@skypeApi, :sendCMD
118
+ def_delegators :@@skypeApi, :sendCMD
119
+ end
120
+
121
+ end
122
+ end