SkypeR 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/iskype.rb +45 -16
- data/bin/iskype.rb~ +58 -24
- metadata +3 -3
data/bin/iskype.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
$:.unshift File.join(File.dirname(__FILE__))
|
3
3
|
|
4
|
+
require 'rubygems'
|
5
|
+
#require_gem 'yaparc'
|
6
|
+
require 'yaparc'
|
4
7
|
require 'readline'
|
5
8
|
require 'optparse'
|
6
9
|
require 'logger'
|
@@ -39,6 +42,7 @@ module SkypeR
|
|
39
42
|
def initialize(name, log = nil, parse = false)
|
40
43
|
@debug = false
|
41
44
|
@application = Service::Application.new(name)
|
45
|
+
@parse = parse
|
42
46
|
@headers = []
|
43
47
|
@logger = Logger.new(log ? log : $stderr)
|
44
48
|
@commands = {
|
@@ -52,23 +56,18 @@ module SkypeR
|
|
52
56
|
proc { |args| @libraries << args }],
|
53
57
|
'test' => ['test if the repl is ok by running a printf through it.',
|
54
58
|
proc { xsb_command('printf("repl is ok\n");') }],
|
55
|
-
's' => ['cause a segfault to let crepl attempt to recover.',
|
56
|
-
proc do
|
57
|
-
puts 'attempting segfault'
|
58
|
-
xsb_command '*((char*)0) = 0;'
|
59
|
-
end],
|
60
59
|
'help' => ['show help on commands.', proc { show_help }]
|
61
60
|
}
|
62
61
|
end
|
63
62
|
|
64
63
|
|
65
|
-
def skype_command(
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
64
|
+
def skype_command(command_statement)
|
65
|
+
command_message = Service::CommandMessage.new(command_statement)
|
66
|
+
end
|
67
|
+
|
68
|
+
def skype_response(response_statement, response_instance)
|
69
|
+
response = Service::ResponseMessage.new(response_statement, response_instance)
|
70
|
+
result = @application.parse(response)
|
72
71
|
end
|
73
72
|
|
74
73
|
def skype_exit
|
@@ -106,18 +105,48 @@ Commands start with a . and are as follows:
|
|
106
105
|
@logger.debug("OUTPUT> See you again.")
|
107
106
|
return
|
108
107
|
else
|
109
|
-
|
110
|
-
|
111
|
-
@
|
108
|
+
response_statement = nil
|
109
|
+
command_message = SkypeR::Service::CommandMessage.new(line)
|
110
|
+
if @parse
|
111
|
+
case result = @application.parse(command_message)
|
112
|
+
when Yaparc::OK
|
113
|
+
response_statement = @application.invoke(command_message, 30)
|
114
|
+
# response_instance = result.value[:command_instance].response
|
115
|
+
# skype_response(response_statement, response_instance)
|
116
|
+
when Yaparc::Fail
|
117
|
+
response_statement = "##{command_message.command_id} Parse Error"
|
118
|
+
else
|
119
|
+
raise
|
120
|
+
end
|
121
|
+
else # in case of parse option disabled
|
122
|
+
response_statement = @application.invoke(command_message, 30)
|
123
|
+
end
|
124
|
+
unless response_statement.empty?
|
125
|
+
response_id, response_statement = split_response(response_statement)
|
126
|
+
puts "=> #{response_statement}"
|
127
|
+
@logger.debug("OUTPUT> #{response_statement}")
|
128
|
+
end
|
112
129
|
end
|
113
130
|
end
|
114
131
|
Readline::HISTORY.push(line)
|
115
132
|
end
|
116
133
|
@interpreter.close
|
117
|
-
|
134
|
+
|
135
|
+
end # of input_loop method
|
136
|
+
|
137
|
+
private
|
138
|
+
def split_response(response_statement)
|
139
|
+
if match = Regexp.new(/(#[0-9]+) (.*)$/).match(response_statement)
|
140
|
+
[match[1], match[2]]
|
141
|
+
else
|
142
|
+
p "#{response_statement}"
|
143
|
+
raise
|
144
|
+
end
|
145
|
+
end
|
118
146
|
end # of Service
|
119
147
|
end # of SkypeR
|
120
148
|
|
149
|
+
|
121
150
|
begin
|
122
151
|
arguments = SkypeR::Arguments.new(ARGV)
|
123
152
|
if name = arguments[:name]
|
data/bin/iskype.rb~
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
$:.unshift File.join(File.dirname(__FILE__))
|
3
3
|
|
4
|
+
require 'rubygems'
|
5
|
+
require_gem 'yaparc'
|
4
6
|
require 'readline'
|
5
7
|
require 'optparse'
|
6
8
|
require 'logger'
|
@@ -22,6 +24,10 @@ module SkypeR
|
|
22
24
|
self[:log] = string || '$'
|
23
25
|
end
|
24
26
|
|
27
|
+
opts.on('-p', '--parse', 'parsing enabled') do
|
28
|
+
self[:parse] = true
|
29
|
+
end
|
30
|
+
|
25
31
|
opts.on_tail('-h', '--help', 'display this help') do
|
26
32
|
puts opts
|
27
33
|
exit
|
@@ -32,9 +38,10 @@ module SkypeR
|
|
32
38
|
end
|
33
39
|
|
34
40
|
class REPL
|
35
|
-
def initialize(name, log = nil)
|
41
|
+
def initialize(name, log = nil, parse = false)
|
36
42
|
@debug = false
|
37
43
|
@application = Service::Application.new(name)
|
44
|
+
@parse = parse
|
38
45
|
@headers = []
|
39
46
|
@logger = Logger.new(log ? log : $stderr)
|
40
47
|
@commands = {
|
@@ -42,26 +49,24 @@ module SkypeR
|
|
42
49
|
proc { @debug = !@debug; puts "debug is #{@debug?'on':'off'}" }],
|
43
50
|
'logger' => ['"logger on": bring logger active.',
|
44
51
|
proc {|args|
|
45
|
-
@headers << args
|
52
|
+
@headers << args
|
46
53
|
}],
|
47
54
|
'l' => ['"l m": bring in a C library.',
|
48
55
|
proc { |args| @libraries << args }],
|
49
56
|
'test' => ['test if the repl is ok by running a printf through it.',
|
50
57
|
proc { xsb_command('printf("repl is ok\n");') }],
|
51
|
-
's' => ['cause a segfault to let crepl attempt to recover.',
|
52
|
-
proc do
|
53
|
-
puts 'attempting segfault'
|
54
|
-
xsb_command '*((char*)0) = 0;'
|
55
|
-
end],
|
56
58
|
'help' => ['show help on commands.', proc { show_help }]
|
57
59
|
}
|
58
60
|
end
|
59
61
|
|
60
62
|
|
61
|
-
def skype_command(
|
62
|
-
|
63
|
-
|
64
|
-
|
63
|
+
def skype_command(command_statement)
|
64
|
+
command_message = Service::CommandMessage.new(command_statement)
|
65
|
+
end
|
66
|
+
|
67
|
+
def skype_response(response_statement, response_instance)
|
68
|
+
response = Service::ResponseMessage.new(response_statement, response_instance)
|
69
|
+
result = @application.parse(response)
|
65
70
|
end
|
66
71
|
|
67
72
|
def skype_exit
|
@@ -99,33 +104,62 @@ Commands start with a . and are as follows:
|
|
99
104
|
@logger.debug("OUTPUT> See you again.")
|
100
105
|
return
|
101
106
|
else
|
102
|
-
|
103
|
-
|
104
|
-
@
|
107
|
+
response_statement = nil
|
108
|
+
command_message = SkypeR::Service::CommandMessage.new(line)
|
109
|
+
if @parse
|
110
|
+
case result = @application.parse(command_message)
|
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
|
123
|
+
unless response_statement.empty?
|
124
|
+
response_id, response_statement = split_response(response_statement)
|
125
|
+
puts "=> #{response_statement}"
|
126
|
+
@logger.debug("OUTPUT> #{response_statement}")
|
127
|
+
end
|
105
128
|
end
|
106
129
|
end
|
107
130
|
Readline::HISTORY.push(line)
|
108
131
|
end
|
109
132
|
@interpreter.close
|
110
|
-
|
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
|
+
[match[1], match[2]]
|
140
|
+
else
|
141
|
+
p "#{response_statement}"
|
142
|
+
raise
|
143
|
+
end
|
144
|
+
end
|
111
145
|
end # of Service
|
112
146
|
end # of SkypeR
|
113
147
|
|
148
|
+
|
114
149
|
begin
|
115
150
|
arguments = SkypeR::Arguments.new(ARGV)
|
116
|
-
# p "arguments[:name] = #{arguments[:name]}"
|
117
151
|
if name = arguments[:name]
|
118
|
-
repl = SkypeR::REPL.new(name, arguments[:log])
|
152
|
+
repl = SkypeR::REPL.new(name, arguments[:log], arguments[:parse])
|
119
153
|
else
|
120
|
-
repl = SkypeR::REPL.new('test', 'log/iskype.log')
|
154
|
+
repl = SkypeR::REPL.new('test', 'log/iskype.log', arguments[:parse])
|
121
155
|
end
|
122
156
|
repl.input_loop
|
123
|
-
rescue Exception => e
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
157
|
+
# rescue Exception => e
|
158
|
+
# puts e.message
|
159
|
+
# puts "Backtrace:"
|
160
|
+
# e.backtrace.each {|line|
|
161
|
+
# puts line
|
162
|
+
# }
|
129
163
|
end
|
130
164
|
|
131
165
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.3
|
|
3
3
|
specification_version: 1
|
4
4
|
name: SkypeR
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2008-01-
|
6
|
+
version: 0.0.5
|
7
|
+
date: 2008-01-16 00:00:00 +09:00
|
8
8
|
summary: a SkypeAPI library for Ruby
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -63,5 +63,5 @@ dependencies:
|
|
63
63
|
requirements:
|
64
64
|
- - ">="
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: 0.0
|
66
|
+
version: 0.1.0
|
67
67
|
version:
|