SkypeR 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +20 -0
- data/bin/iskype.rb +29 -62
- data/bin/iskype.rb.back +170 -0
- data/lib/skyper.rb +2 -1
- data/lib/skyper/command.rb +52 -27
- data/lib/skyper/exception.rb +14 -0
- data/lib/skyper/object.rb +454 -8
- data/lib/skyper/parser.rb +13 -4
- data/lib/skyper/response.rb +44 -18
- data/lib/skyper/service.rb +44 -16
- data/lib/skyper/service.rb.back +127 -0
- data/lib/skyper/service.rb.org +181 -0
- data/rails/init.rb +1 -0
- data/tests/test_parser.rb +22 -13
- metadata +17 -9
data/README
CHANGED
@@ -56,6 +56,9 @@ And then, run iskype.rb with application name.
|
|
56
56
|
|
57
57
|
Skype> GET USER somebodys_account LASTONLINETIMESTAMP
|
58
58
|
|
59
|
+
Skype> CHAT CREATE somebodys_account
|
60
|
+
Skype> CHATMESSAGE <chat_id> This is a test
|
61
|
+
|
59
62
|
Skype> exit
|
60
63
|
See you again.
|
61
64
|
|
@@ -70,6 +73,23 @@ With -p option, iskype parses input command before execution. The parser is stil
|
|
70
73
|
=> USERS echo123, foo, bar
|
71
74
|
|
72
75
|
|
76
|
+
== Library Usage
|
77
|
+
|
78
|
+
|
79
|
+
user = SkypeR::Object::User.new
|
80
|
+
user.execute('CHAT CREATE akimichi_tatsukawa')
|
81
|
+
|
82
|
+
== Problems with dbus
|
83
|
+
|
84
|
+
$ sudo dbus-daemon-1 --system
|
85
|
+
$ ~/develop/ruby/skyper$ dbus-launch
|
86
|
+
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-ZJrpT6QzE1,guid=a0ad7207e19214f478b3d900490d662f
|
87
|
+
DBUS_SESSION_BUS_PID=32350
|
88
|
+
$ export DBUS_SESSION_BUS_ADDRESS='unix:abstract=/tmp/dbus-ZJrpT6QzE1,guid=a0ad7207e19214f478b3d900490d662f'
|
89
|
+
$ export DBUS_SESSION_BUS_PID=32350
|
90
|
+
$ echo $DBUS_SESSION_BUS_ADDRESS
|
91
|
+
unix:abstract=/tmp/dbus-ZJrpT6QzE1,guid=a0ad7207e19214f478b3d900490d662f
|
92
|
+
|
73
93
|
Have fun!!
|
74
94
|
|
75
95
|
Akimichi Tatsukawa
|
data/bin/iskype.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
# author: Péter Kiss, Akimichi TATSUKAWA
|
3
3
|
|
4
4
|
require 'rubygems'
|
5
5
|
require 'yaparc'
|
@@ -19,15 +19,15 @@ module SkypeR
|
|
19
19
|
opts.on('-n', '--name [STRING]', 'application name to access Skype') do |string|
|
20
20
|
self[:name] = string || '$'
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
opts.on('-l', '--log [STRING]', 'log file path') do |string|
|
24
24
|
self[:log] = string || '$'
|
25
25
|
end
|
26
|
-
|
27
|
-
opts.on('-p', '--parse', '
|
26
|
+
|
27
|
+
opts.on('-p', '--parse', 'parse input') do |string|
|
28
28
|
self[:parse] = true
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
opts.on_tail('-h', '--help', 'display this help') do
|
32
32
|
puts opts
|
33
33
|
exit
|
@@ -36,65 +36,46 @@ module SkypeR
|
|
36
36
|
opts.parse(args)
|
37
37
|
end
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
|
+
SKYPE = Service::Application.new('test')
|
41
|
+
|
40
42
|
class REPL
|
43
|
+
|
44
|
+
application = nil
|
45
|
+
|
41
46
|
def initialize(name, log = nil, parse = false)
|
42
47
|
@debug = false
|
43
|
-
@application =
|
44
|
-
@parse =
|
48
|
+
@application = SKYPE
|
49
|
+
@parse = false
|
45
50
|
@headers = []
|
51
|
+
|
52
|
+
FileUtils::mkdir(File.dirname(log)) unless File.exists?(log)
|
53
|
+
|
46
54
|
@logger = Logger.new(log ? log : $stderr)
|
47
|
-
@commands = {
|
48
|
-
'd' => ['toggle debug mode.',
|
49
|
-
proc { @debug = !@debug; puts "debug is #{@debug?'on':'off'}" }],
|
50
|
-
'logger' => ['"logger on": bring logger active.',
|
51
|
-
proc {|args|
|
52
|
-
@headers << args
|
53
|
-
}],
|
54
|
-
'l' => ['"l m": bring in a C library.',
|
55
|
-
proc { |args| @libraries << args }],
|
56
|
-
'test' => ['test if the repl is ok by running a printf through it.',
|
57
|
-
proc { xsb_command('printf("repl is ok\n");') }],
|
58
|
-
'help' => ['show help on commands.', proc { show_help }]
|
59
|
-
}
|
60
55
|
end
|
61
|
-
|
62
|
-
|
56
|
+
|
57
|
+
|
63
58
|
def skype_command(command_statement)
|
64
59
|
command_message = Service::CommandMessage.new(command_statement)
|
65
60
|
end
|
66
|
-
|
61
|
+
|
67
62
|
def skype_response(response_statement, response_instance)
|
68
63
|
response = Service::ResponseMessage.new(response_statement, response_instance)
|
69
64
|
result = @application.parse(response)
|
70
65
|
end
|
71
|
-
|
66
|
+
|
72
67
|
def skype_exit
|
73
68
|
raise
|
74
69
|
end
|
75
|
-
|
76
|
-
|
77
|
-
def show_help
|
78
|
-
puts <<-EOT
|
79
|
-
Not in use, yet.
|
80
|
-
Type C statements and declarations as you would in a normal program.
|
81
|
-
Type a variable name by itself to see its value.
|
82
|
-
|
83
|
-
Commands start with a . and are as follows:
|
84
|
-
EOT
|
85
|
-
cmds = @commands.keys.sort
|
86
|
-
len = cmds.map{|c|c.length}.max
|
87
|
-
@commands.keys.sort.each do |cmd|
|
88
|
-
printf(" %-#{len}s %s\n", cmd, @commands[cmd][0])
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
70
|
+
|
92
71
|
def input_loop
|
93
72
|
loop do
|
94
|
-
line = Readline.readline('
|
73
|
+
line = Readline.readline('SkypeAPI> ')
|
95
74
|
break unless line
|
96
75
|
line.chomp!
|
97
76
|
if line.empty?
|
77
|
+
sleep(1)
|
78
|
+
puts '.'
|
98
79
|
next
|
99
80
|
else
|
100
81
|
@logger.debug("INPUT> #{line}")
|
@@ -106,20 +87,8 @@ Commands start with a . and are as follows:
|
|
106
87
|
else
|
107
88
|
response_statement = nil
|
108
89
|
command_message = SkypeR::Service::CommandMessage.new(line)
|
109
|
-
|
110
|
-
|
111
|
-
when Yaparc::OK
|
112
|
-
response_statement = @application.invoke(command_message, 30)
|
113
|
-
# response_instance = result.value[:command_instance].response
|
114
|
-
# skype_response(response_statement, response_instance)
|
115
|
-
when Yaparc::Fail
|
116
|
-
response_statement = "##{command_message.command_id} Parse Error"
|
117
|
-
else
|
118
|
-
raise
|
119
|
-
end
|
120
|
-
else # in case of parse option disabled
|
121
|
-
response_statement = @application.invoke(command_message, 30)
|
122
|
-
end
|
90
|
+
response_statement = @application.invoke(command_message, 30)
|
91
|
+
|
123
92
|
unless response_statement.empty?
|
124
93
|
puts response_statement
|
125
94
|
response_id, response_statement = split_response(response_statement)
|
@@ -131,12 +100,11 @@ Commands start with a . and are as follows:
|
|
131
100
|
Readline::HISTORY.push(line)
|
132
101
|
end
|
133
102
|
@interpreter.close
|
134
|
-
|
103
|
+
|
135
104
|
end # of input_loop method
|
136
|
-
|
105
|
+
|
137
106
|
private
|
138
107
|
def split_response(response_statement)
|
139
|
-
# if match = Regexp.new(/(#[0-9]+) (.*)$/).match(response_statement)
|
140
108
|
if match = Regexp.new(/(#[0-9]+) (.*)$/).match(response_statement.to_s)
|
141
109
|
[match[1], match[2]]
|
142
110
|
else
|
@@ -146,8 +114,7 @@ Commands start with a . and are as follows:
|
|
146
114
|
end
|
147
115
|
end # of Service
|
148
116
|
end # of SkypeR
|
149
|
-
|
150
|
-
|
117
|
+
|
151
118
|
begin
|
152
119
|
arguments = SkypeR::Arguments.new(ARGV)
|
153
120
|
if name = arguments[:name]
|
data/bin/iskype.rb.back
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'yaparc'
|
5
|
+
require 'readline'
|
6
|
+
require 'optparse'
|
7
|
+
require 'logger'
|
8
|
+
require "lib/skyper.rb"
|
9
|
+
|
10
|
+
module SkypeR
|
11
|
+
LOGGER = nil
|
12
|
+
class Arguments < Hash
|
13
|
+
def initialize(args)
|
14
|
+
super()
|
15
|
+
# default values
|
16
|
+
opts = ::OptionParser.new do |opts|
|
17
|
+
opts.banner = "Usage: #$0 [options]"
|
18
|
+
opts.on('-n', '--name [STRING]', 'application name to access Skype') do |string|
|
19
|
+
self[:name] = string || '$'
|
20
|
+
end
|
21
|
+
|
22
|
+
opts.on('-l', '--log [STRING]', 'log file path') do |string|
|
23
|
+
self[:log] = string || '$'
|
24
|
+
end
|
25
|
+
|
26
|
+
opts.on('-p', '--parse', 'parsing enabled') do
|
27
|
+
self[:parse] = true
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on_tail('-h', '--help', 'display this help') do
|
31
|
+
puts opts
|
32
|
+
exit
|
33
|
+
end
|
34
|
+
end
|
35
|
+
opts.parse(args)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class REPL
|
40
|
+
def initialize(name, log = nil, parse = false)
|
41
|
+
@debug = false
|
42
|
+
@application = Service::Application.new(name)
|
43
|
+
@parse = parse
|
44
|
+
@headers = []
|
45
|
+
@logger = Logger.new(log ? log : $stderr)
|
46
|
+
@commands = {
|
47
|
+
'd' => ['toggle debug mode.',
|
48
|
+
proc { @debug = !@debug; puts "debug is #{@debug?'on':'off'}" }],
|
49
|
+
'logger' => ['"logger on": bring logger active.',
|
50
|
+
proc {|args|
|
51
|
+
@headers << args
|
52
|
+
}],
|
53
|
+
'l' => ['"l m": bring in a C library.',
|
54
|
+
proc { |args| @libraries << args }],
|
55
|
+
'test' => ['test if the repl is ok by running a printf through it.',
|
56
|
+
proc { xsb_command('printf("repl is ok\n");') }],
|
57
|
+
'help' => ['show help on commands.', proc { show_help }]
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
|
62
|
+
def skype_command(command_statement)
|
63
|
+
command_message = Service::CommandMessage.new(command_statement)
|
64
|
+
end
|
65
|
+
|
66
|
+
def skype_response(response_statement, response_instance)
|
67
|
+
response = Service::ResponseMessage.new(response_statement, response_instance)
|
68
|
+
result = @application.parse(response)
|
69
|
+
end
|
70
|
+
|
71
|
+
def skype_exit
|
72
|
+
raise
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
def show_help
|
77
|
+
puts <<-EOT
|
78
|
+
Not in use, yet.
|
79
|
+
Type C statements and declarations as you would in a normal program.
|
80
|
+
Type a variable name by itself to see its value.
|
81
|
+
|
82
|
+
Commands start with a . and are as follows:
|
83
|
+
EOT
|
84
|
+
cmds = @commands.keys.sort
|
85
|
+
len = cmds.map{|c|c.length}.max
|
86
|
+
@commands.keys.sort.each do |cmd|
|
87
|
+
printf(" %-#{len}s %s\n", cmd, @commands[cmd][0])
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def input_loop
|
92
|
+
loop do
|
93
|
+
line = Readline.readline('Skype> ')
|
94
|
+
break unless line
|
95
|
+
line.chomp!
|
96
|
+
if line.empty?
|
97
|
+
next
|
98
|
+
else
|
99
|
+
@logger.debug("INPUT> #{line}")
|
100
|
+
case line
|
101
|
+
when /^exit$/
|
102
|
+
puts "See you again."
|
103
|
+
@logger.debug("OUTPUT> See you again.")
|
104
|
+
return
|
105
|
+
else
|
106
|
+
response_statement = nil
|
107
|
+
command_message = SkypeR::Service::CommandMessage.new(line)
|
108
|
+
if @parse
|
109
|
+
case result = @application.parse(command_message)
|
110
|
+
when Yaparc::OK
|
111
|
+
response_statement = @application.invoke(command_message, 30)
|
112
|
+
# response_instance = result.value[:command_instance].response
|
113
|
+
# skype_response(response_statement, response_instance)
|
114
|
+
when Yaparc::Fail
|
115
|
+
response_statement = "##{command_message.command_id} Parse Error"
|
116
|
+
else
|
117
|
+
raise
|
118
|
+
end
|
119
|
+
else # in case of parse option disabled
|
120
|
+
response_statement = @application.invoke(command_message, 30)
|
121
|
+
end
|
122
|
+
unless response_statement.nil? or response_statement.empty?
|
123
|
+
puts response_statement
|
124
|
+
response_id, response_statement = split_response(response_statement)
|
125
|
+
puts "=> #{response_statement}"
|
126
|
+
@logger.debug("OUTPUT> #{response_statement}")
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
Readline::HISTORY.push(line)
|
131
|
+
end
|
132
|
+
@interpreter.close
|
133
|
+
|
134
|
+
end # of input_loop method
|
135
|
+
|
136
|
+
private
|
137
|
+
def split_response(response_statement)
|
138
|
+
# if match = Regexp.new(/(#[0-9]+) (.*)$/).match(response_statement)
|
139
|
+
if match = Regexp.new(/(#[0-9]+) (.*)$/).match(response_statement.to_s)
|
140
|
+
[match[1], match[2]]
|
141
|
+
else
|
142
|
+
p "#{response_statement}"
|
143
|
+
raise
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end # of Service
|
147
|
+
end # of SkypeR
|
148
|
+
|
149
|
+
|
150
|
+
begin
|
151
|
+
arguments = SkypeR::Arguments.new(ARGV)
|
152
|
+
if name = arguments[:name]
|
153
|
+
repl = SkypeR::REPL.new(name, arguments[:log], arguments[:parse])
|
154
|
+
else
|
155
|
+
repl = SkypeR::REPL.new('test', 'log/iskype.log', arguments[:parse])
|
156
|
+
end
|
157
|
+
repl.input_loop
|
158
|
+
# rescue Exception => e
|
159
|
+
# puts e.message
|
160
|
+
# puts "Backtrace:"
|
161
|
+
# e.backtrace.each {|line|
|
162
|
+
# puts line
|
163
|
+
# }
|
164
|
+
end
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
data/lib/skyper.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
$:.unshift File.join(File.dirname(__FILE__))
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
|
-
require 'rbus.rb'
|
4
|
+
#require 'rbus.rb'
|
5
5
|
|
6
6
|
require 'skyper/service.rb'
|
7
7
|
require 'skyper/object.rb'
|
8
8
|
require 'skyper/parser.rb'
|
9
9
|
require 'skyper/response.rb'
|
10
10
|
require 'skyper/command.rb'
|
11
|
+
require 'skyper/exception.rb'
|
11
12
|
|
12
13
|
|
13
14
|
|
data/lib/skyper/command.rb
CHANGED
@@ -10,8 +10,6 @@ require "logger"
|
|
10
10
|
=end
|
11
11
|
|
12
12
|
module SkypeR
|
13
|
-
|
14
|
-
|
15
13
|
module Parser
|
16
14
|
|
17
15
|
class CommandBase < Yaparc::AbstractParser
|
@@ -347,14 +345,14 @@ module SkypeR
|
|
347
345
|
Yaparc::Symbol.new("CALL"),
|
348
346
|
Target.new,
|
349
347
|
Yaparc::Many.new(
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
348
|
+
Yaparc::Seq.new(
|
349
|
+
Yaparc::Symbol.new(','),
|
350
|
+
Target.new) do |_, target|
|
351
|
+
[target]
|
352
|
+
end,
|
353
|
+
[]
|
354
|
+
)
|
355
|
+
) do |_,target,targets|
|
358
356
|
{:command_instance => self, :targets => [target] + targets}
|
359
357
|
end
|
360
358
|
end
|
@@ -387,35 +385,62 @@ module SkypeR
|
|
387
385
|
end
|
388
386
|
end
|
389
387
|
end
|
390
|
-
|
388
|
+
=begin
|
391
389
|
# <chat_create_command> := CHAT CREATE <target>[, <target>]*
|
392
390
|
# <chat_create_response> := CHAT <chat_id> STATUS <value>
|
393
|
-
|
394
|
-
# <chat_message_response> := CHATMESSAGE <id> STATUS SENDING
|
391
|
+
=end
|
395
392
|
class ChatCreateCommand < CommandBase
|
396
393
|
def initialize
|
397
394
|
@parser = lambda do
|
398
395
|
Yaparc::Seq.new(
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
396
|
+
Yaparc::Symbol.new("CHAT"),
|
397
|
+
Yaparc::Symbol.new("CREATE"),
|
398
|
+
Target.new,
|
399
|
+
Yaparc::Many.new(
|
400
|
+
Yaparc::Seq.new(Yaparc::Symbol.new(','),
|
401
|
+
Target.new) do |_, target|
|
402
|
+
[target]
|
403
|
+
end,
|
404
|
+
[]
|
405
|
+
)
|
409
406
|
) do |_,_,target,targets|
|
410
|
-
|
407
|
+
@response = ChatCreateResponse.new(SkypeR::Object::Chat.new(:members => [target] + targets))
|
408
|
+
{:response_parser => @response}
|
411
409
|
end
|
412
410
|
end
|
413
|
-
|
411
|
+
|
414
412
|
end
|
413
|
+
|
415
414
|
end
|
416
415
|
|
417
|
-
|
418
|
-
|
416
|
+
=begin
|
417
|
+
Synopsis: Send chatmessage to chat_id
|
418
|
+
# <chat_message_command> := CHATMESSAGE <chat_id> <message>
|
419
|
+
# <chat_message_response> := CHATMESSAGE <id> STATUS SENDING
|
420
|
+
# c.f. https://developer.skype.com/Docs/ApiDoc/CHATMESSAGE_object
|
421
|
+
=end
|
422
|
+
|
423
|
+
class ChatMessageCommand < CommandBase
|
424
|
+
def initialize(chatmessage_object)
|
425
|
+
@chatmessage_object = chatmessage_object
|
426
|
+
@response = ChatMessageResponse.new
|
427
|
+
|
428
|
+
@parser = lambda do
|
429
|
+
Yaparc::Seq.new(
|
430
|
+
Yaparc::Symbol.new("CHATMESSAGE"),
|
431
|
+
ChatID.new,
|
432
|
+
Yaparc::Regex.new(/\A.*\Z/)
|
433
|
+
) do |_,chat_id,message|
|
434
|
+
#{:chat_id => chat_id, :message => message}
|
435
|
+
@chatmessage_object.messages << message
|
436
|
+
@chatmessage_object.chat_id = chat_id
|
437
|
+
@chatmessage_object
|
438
|
+
end
|
439
|
+
end
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
|
419
444
|
class HistoryCommand < CommandBase
|
420
445
|
def initialize
|
421
446
|
@parser = lambda do
|