rest-terminal 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/rest +2 -0
- data/bin/rt +2 -0
- data/lib/rest/service.rb +10 -0
- data/lib/rest/terminal/commands.rb +116 -0
- data/lib/rest/terminal/commands_info.rb +112 -0
- data/lib/rest/terminal/persistent.rb +47 -0
- data/lib/rest/terminal/persistent_rc.rb +27 -0
- data/lib/rest/terminal.rb +127 -0
- data/lib/rest/version.rb +35 -0
- data/lib/rest.rb +23 -0
- data/lib/service_base.rb +231 -0
- metadata +106 -0
data/bin/rest
ADDED
data/bin/rt
ADDED
data/lib/rest/service.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
module Rest
|
2
|
+
class Terminal
|
3
|
+
module Commands
|
4
|
+
def is_runable?
|
5
|
+
is_restt = File.directory?(".rest-terminal")
|
6
|
+
if !is_restt
|
7
|
+
puts "\nPlease run command \"init\" to start REST Terminal!".red
|
8
|
+
puts "\n"
|
9
|
+
end
|
10
|
+
is_restt
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def _init
|
16
|
+
require 'fileutils'
|
17
|
+
pth = File.dirname(__FILE__)
|
18
|
+
FileUtils.mkdir_p ".rest-terminal"
|
19
|
+
`cp #{pth}/terminal/persistent_rc.rb .rest-terminal`
|
20
|
+
require './.rest-terminal/persistent_rc'
|
21
|
+
load_vars
|
22
|
+
FileUtils.mkdir_p "services"
|
23
|
+
`cp #{pth}/service.rb services`
|
24
|
+
@spaces.each do |path|
|
25
|
+
# `mkdir -p services#{path}`
|
26
|
+
FileUtils.mkdir_p "services#{path}"
|
27
|
+
#`cp ./service.rb services#{path}`
|
28
|
+
`cp #{pth}/service.rb services#{path}`
|
29
|
+
end
|
30
|
+
@hist = ['init']
|
31
|
+
@pwd = '/'
|
32
|
+
@_status = 'OK'
|
33
|
+
end
|
34
|
+
|
35
|
+
def _add
|
36
|
+
@prm.each do |prm|
|
37
|
+
fp = full_path(prm)
|
38
|
+
if File.directory?("services#{fp}")
|
39
|
+
fp = "Service already exists! #{fp}".red
|
40
|
+
else
|
41
|
+
FileUtils.mkdir_p("services#{fp}")
|
42
|
+
`cp ./service.rb services#{fp}`
|
43
|
+
end
|
44
|
+
end
|
45
|
+
@_status = "#{@prm.length} service created!"
|
46
|
+
end
|
47
|
+
|
48
|
+
def _cd
|
49
|
+
fp = full_path(@prm[0])
|
50
|
+
if File.directory?("services#{fp}")
|
51
|
+
@pwd = fp
|
52
|
+
else
|
53
|
+
fp = "Service not exists! #{fp}".red
|
54
|
+
end
|
55
|
+
@_status = fp
|
56
|
+
end
|
57
|
+
|
58
|
+
def _history
|
59
|
+
@hist.each_with_index do |itm,idx|
|
60
|
+
puts "#{idx.to_s.rjust(2,'0')} > `#{itm}`"
|
61
|
+
end
|
62
|
+
@_status = "#{@hist.length} histories"
|
63
|
+
end
|
64
|
+
|
65
|
+
def _ls
|
66
|
+
path = Dir["#{current_path}*/"]
|
67
|
+
path.collect do |x|
|
68
|
+
puts x.sub(current_path,'/')
|
69
|
+
end
|
70
|
+
@_status = "#{path.length} services"
|
71
|
+
# p "lolllll >>#{@serv}<< ."
|
72
|
+
end
|
73
|
+
|
74
|
+
def _pwd
|
75
|
+
@_status = "\"#{@pwd}\""
|
76
|
+
end
|
77
|
+
|
78
|
+
def _info
|
79
|
+
multi_exec(:_info)
|
80
|
+
@_status = ""
|
81
|
+
# @_status = @services[@pwd]._info(@prm)
|
82
|
+
end
|
83
|
+
|
84
|
+
def _response
|
85
|
+
@_status = @services[@pwd]._response(@prm)
|
86
|
+
end
|
87
|
+
|
88
|
+
def _headers
|
89
|
+
@_status = @services[@pwd]._headers(@prm)
|
90
|
+
end
|
91
|
+
|
92
|
+
def _body
|
93
|
+
@_status = @services[@pwd]._body(@prm)
|
94
|
+
end
|
95
|
+
|
96
|
+
def _vars
|
97
|
+
if @prm.length>1 && !@prm[/\=/]
|
98
|
+
pth = @prm.shift
|
99
|
+
@_status = @services[pth]._vars(@prm)
|
100
|
+
else
|
101
|
+
@_status = @services[@pwd]._vars(@prm)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def _reset
|
106
|
+
@_status = @services[@pwd]._reset(@prm)
|
107
|
+
end
|
108
|
+
|
109
|
+
def _send
|
110
|
+
multi_exec(:_send)
|
111
|
+
@_status = ""
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module Rest
|
2
|
+
class Terminal
|
3
|
+
module CommandsInfo
|
4
|
+
private
|
5
|
+
|
6
|
+
def add_line
|
7
|
+
"add service folder"
|
8
|
+
end
|
9
|
+
|
10
|
+
def body_line
|
11
|
+
"view or set var: body"
|
12
|
+
end
|
13
|
+
|
14
|
+
def cd_line
|
15
|
+
"change current service"
|
16
|
+
end
|
17
|
+
|
18
|
+
def headers_line
|
19
|
+
"view or set var: headers"
|
20
|
+
end
|
21
|
+
|
22
|
+
def history_line
|
23
|
+
"view history last command call"
|
24
|
+
end
|
25
|
+
|
26
|
+
def info_line
|
27
|
+
"show variables :headers, :body, :vars"
|
28
|
+
end
|
29
|
+
|
30
|
+
def init_line
|
31
|
+
"prepare folder to become rest-terminal services"
|
32
|
+
end
|
33
|
+
|
34
|
+
def ls_line
|
35
|
+
"list services"
|
36
|
+
end
|
37
|
+
|
38
|
+
def pwd_line
|
39
|
+
"print current service"
|
40
|
+
end
|
41
|
+
|
42
|
+
def reset_line
|
43
|
+
"empty variables :headers, :body, :vars"
|
44
|
+
end
|
45
|
+
|
46
|
+
def response_line
|
47
|
+
"show last response call from 'send'"
|
48
|
+
end
|
49
|
+
|
50
|
+
def send_line
|
51
|
+
"send Rest Call"
|
52
|
+
end
|
53
|
+
|
54
|
+
def vars_line
|
55
|
+
"view or set var: vars"
|
56
|
+
end
|
57
|
+
#--------------------------------------------------------
|
58
|
+
def add_help
|
59
|
+
"add service folder"
|
60
|
+
end
|
61
|
+
|
62
|
+
def body_help
|
63
|
+
"view or set var: body"
|
64
|
+
end
|
65
|
+
|
66
|
+
def cd_help
|
67
|
+
"change current service"
|
68
|
+
end
|
69
|
+
|
70
|
+
def headers_help
|
71
|
+
"view or set var: headers"
|
72
|
+
end
|
73
|
+
|
74
|
+
def history_help
|
75
|
+
"view history last command call"
|
76
|
+
end
|
77
|
+
|
78
|
+
def info_help
|
79
|
+
"show variables :headers, :body, :vars"
|
80
|
+
end
|
81
|
+
|
82
|
+
def init_help
|
83
|
+
"prepare folder to become rest-terminal services"
|
84
|
+
end
|
85
|
+
|
86
|
+
def ls_help
|
87
|
+
"list services"
|
88
|
+
end
|
89
|
+
|
90
|
+
def pwd_help
|
91
|
+
"print current service"
|
92
|
+
end
|
93
|
+
|
94
|
+
def reset_help
|
95
|
+
"empty variables :headers, :body, :vars"
|
96
|
+
end
|
97
|
+
|
98
|
+
def response_help
|
99
|
+
"show last response call from 'send'"
|
100
|
+
end
|
101
|
+
|
102
|
+
def send_help
|
103
|
+
"send Rest Call"
|
104
|
+
end
|
105
|
+
|
106
|
+
def vars_help
|
107
|
+
"view or set var: vars"
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Rest
|
2
|
+
class Terminal
|
3
|
+
module Persistent
|
4
|
+
private
|
5
|
+
def load_services
|
6
|
+
paths = "#{@pwd.strip} ".split(/\//).collect(&:strip).reject(&:empty?).unshift('')
|
7
|
+
p2 = ''
|
8
|
+
paths.each do |path|
|
9
|
+
p1 = p2
|
10
|
+
p2 = "#{p2}#{path}/"
|
11
|
+
pr = @services[p1]
|
12
|
+
@services[p2] = ServiceBase.new(pr,p2)
|
13
|
+
p "PARRENT: #{pr} - #{p1} - #{p2}"
|
14
|
+
p @services[p2].vars
|
15
|
+
end
|
16
|
+
pr = @services[@pwd]
|
17
|
+
path = Dir["#{current_path}*/"]
|
18
|
+
path.collect do |px|
|
19
|
+
p2 = px[/\/.*/]
|
20
|
+
@services[p2] = ServiceBase.new(pr,p2)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def save_hist
|
25
|
+
@hist<<@cmd
|
26
|
+
@hist = @hist.reverse.uniq.reverse
|
27
|
+
end
|
28
|
+
|
29
|
+
def save_vars
|
30
|
+
# p "pwd before save: #{@pwd}"
|
31
|
+
b = ['']
|
32
|
+
b << "@pwd = #{@pwd.inspect}"
|
33
|
+
b << "@serv = #{@serv.inspect}"
|
34
|
+
b << "@hist = #{@hist.inspect}"
|
35
|
+
b << "@response = #{@response.inspect}"
|
36
|
+
c = b.join("\n ")
|
37
|
+
s = "#env_start(.*)#env_end"
|
38
|
+
code = IO.read('./.rest-terminal/persistent_rc.rb')
|
39
|
+
#-----------------------------------------
|
40
|
+
x = code.split(/#{s}/m)
|
41
|
+
x[1] = "#env_start#{c}\n #env_end"
|
42
|
+
#-----------------------------------------
|
43
|
+
IO.write('./.rest-terminal/persistent_rc.rb', x.join)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Rest
|
2
|
+
class Terminal
|
3
|
+
module PersistentRc
|
4
|
+
private
|
5
|
+
def load_vars
|
6
|
+
spaces = []
|
7
|
+
#space_start
|
8
|
+
spaces << '/stripe/charges/'
|
9
|
+
spaces << '/stripe/token/'
|
10
|
+
spaces << '/twitter/'
|
11
|
+
#space_end
|
12
|
+
# ::Rest::Terminal.instance_variable_set("@serv",spaces)
|
13
|
+
@spaces = spaces
|
14
|
+
# spaces.each do |row|
|
15
|
+
# @repl = row ; _add(true)
|
16
|
+
# end
|
17
|
+
# @repl = ''
|
18
|
+
|
19
|
+
#env_start
|
20
|
+
@hist = [ ]
|
21
|
+
@pwd = "/"
|
22
|
+
@serv = "localhost"
|
23
|
+
#env_end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
module Rest
|
2
|
+
class Terminal
|
3
|
+
module PersistentRc
|
4
|
+
end
|
5
|
+
module CommandsInfo
|
6
|
+
end
|
7
|
+
|
8
|
+
class << self
|
9
|
+
include Persistent
|
10
|
+
include PersistentRc
|
11
|
+
include Commands
|
12
|
+
include CommandsInfo
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@skey = ''
|
16
|
+
@repl = ''
|
17
|
+
@type = 'earth'
|
18
|
+
@serv = 'localhost'
|
19
|
+
@services = { }
|
20
|
+
@response = { }
|
21
|
+
@spaces = [ ]
|
22
|
+
@hist = [ ]
|
23
|
+
@prm = [ ]
|
24
|
+
@pwd = '/'
|
25
|
+
@cmd = ''
|
26
|
+
@_status = ''
|
27
|
+
end
|
28
|
+
|
29
|
+
def run
|
30
|
+
initialize
|
31
|
+
if is_cmd_in_commands?
|
32
|
+
#p "WWWWWW #{@cmd} #{__FILE__} #{Dir.pwd}"
|
33
|
+
if @cmd == "init" || is_runable?
|
34
|
+
load_state
|
35
|
+
execute
|
36
|
+
save_vars
|
37
|
+
end
|
38
|
+
elsif ARGV == [ ]
|
39
|
+
require 'rest/terminal/commands_info'
|
40
|
+
puts ("="*65).yellow
|
41
|
+
commands.sort.each do |x|
|
42
|
+
help_line = "#{x}_line"
|
43
|
+
puts " #{x.ljust(10)}#{send(help_line)}"
|
44
|
+
end
|
45
|
+
puts ("-"*65).yellow
|
46
|
+
puts "for detail explanation on each command"
|
47
|
+
puts "type: #{'rest help xxx'.green} #xxx: command to know"
|
48
|
+
else
|
49
|
+
invalid_command
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def load_state
|
54
|
+
if File.exists?('./.rest-terminal/persistent_rc.rb')
|
55
|
+
require './.rest-terminal/persistent_rc'
|
56
|
+
load_vars
|
57
|
+
load_services
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def is_cmd_in_commands?
|
62
|
+
puts ARGV.inspect.red
|
63
|
+
@cmd = ARGV[0].to_s
|
64
|
+
parm = ARGV[1,99]
|
65
|
+
@prm = parm ? parm : [ ] #.join(' ') : ''
|
66
|
+
commands.index(@cmd) ? @cmd : nil
|
67
|
+
# if singleton_class.private_instance_methods(false).index(@@cmd.to_sym)
|
68
|
+
end
|
69
|
+
|
70
|
+
def invalid_command
|
71
|
+
puts "#{('='*65)}\n#{'invalid command!'.red}\n#{('-'*65).yellow}"
|
72
|
+
puts "valid commands are:\n#{commands.sort.collect{|x|x.green}.join(', ')}"
|
73
|
+
end
|
74
|
+
|
75
|
+
def commands
|
76
|
+
Rest::Terminal::Commands.private_instance_methods.collect do |x|
|
77
|
+
"#{x[1,99]}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def execute
|
82
|
+
puts "="*65
|
83
|
+
send("_#{@cmd}")
|
84
|
+
puts @_status.green
|
85
|
+
save_hist
|
86
|
+
end
|
87
|
+
|
88
|
+
def prompt
|
89
|
+
"#{@type}@#{@serv} >".yellow
|
90
|
+
end
|
91
|
+
|
92
|
+
def current_path
|
93
|
+
"services#{@pwd}"
|
94
|
+
end
|
95
|
+
|
96
|
+
def space_path(spc)
|
97
|
+
(spc[0] == '/') ? spc : "#{@pwd}#{spc}"
|
98
|
+
end
|
99
|
+
|
100
|
+
def full_path(spc)
|
101
|
+
x = "#{@pwd} "
|
102
|
+
l = x.count('/')+1
|
103
|
+
dots = spc[/\.+/]
|
104
|
+
if dots &&
|
105
|
+
set = l-dots.length
|
106
|
+
set = 1 if set < 1
|
107
|
+
path_up = x.split(/\//)[0,set].join('/')
|
108
|
+
spc = spc.gsub(/\.+/,path_up)
|
109
|
+
end
|
110
|
+
spc = "#{spc}/" if spc[-1]!='/'
|
111
|
+
space_path(spc)
|
112
|
+
end
|
113
|
+
|
114
|
+
def multi_exec(cmd)
|
115
|
+
@prm = ['.'] if @prm==[]
|
116
|
+
@prm.each do |prm|
|
117
|
+
prm = @pwd if prm=='.'
|
118
|
+
pth = full_path(prm)
|
119
|
+
puts "Service: #{pth}".yellow
|
120
|
+
@_status = @services[pth].send(cmd,prm)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
data/lib/rest/version.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# :nodoc:
|
2
|
+
module Rest
|
3
|
+
|
4
|
+
# :nodoc:
|
5
|
+
class Version
|
6
|
+
|
7
|
+
# :nodoc:
|
8
|
+
class <<self
|
9
|
+
def to_s
|
10
|
+
[major, minor, patch, pre].compact.join('.')
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
# :nodoc:
|
15
|
+
def major
|
16
|
+
0
|
17
|
+
end
|
18
|
+
|
19
|
+
# :nodoc:
|
20
|
+
def minor
|
21
|
+
1
|
22
|
+
end
|
23
|
+
|
24
|
+
# :nodoc:
|
25
|
+
def patch
|
26
|
+
0
|
27
|
+
end
|
28
|
+
|
29
|
+
# :nodoc:
|
30
|
+
def pre
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/rest.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'json'
|
3
|
+
require 'term/ansicolor'
|
4
|
+
include Term::ANSIColor
|
5
|
+
|
6
|
+
class Hash
|
7
|
+
def pj
|
8
|
+
JSON.pretty_generate(self)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class String
|
13
|
+
def pj
|
14
|
+
JSON.pretty_generate(JSON.parse(self))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'service_base'
|
19
|
+
require 'rest/version'
|
20
|
+
require 'rest/terminal/commands'
|
21
|
+
require 'rest/terminal/commands_info'
|
22
|
+
require 'rest/terminal/persistent'
|
23
|
+
require 'rest/terminal'
|
data/lib/service_base.rb
ADDED
@@ -0,0 +1,231 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'faraday'
|
3
|
+
|
4
|
+
class ServiceBase
|
5
|
+
attr_reader :path
|
6
|
+
def initialize(vc=nil,path='/',silent=false)
|
7
|
+
@path = path
|
8
|
+
@response = {}
|
9
|
+
@parent = vc
|
10
|
+
reset
|
11
|
+
if File.exists?("services#{path}service.rb")
|
12
|
+
instance_eval(IO.read("services#{path}service.rb"))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def _info(prm)
|
17
|
+
headerx = headers
|
18
|
+
bodyx = bodies
|
19
|
+
varx = vars
|
20
|
+
line = ('-'*65)
|
21
|
+
|
22
|
+
puts ('='*65).yellow
|
23
|
+
# puts "[#{varx[:conn]}] #{varx[:url]}".intense_blue
|
24
|
+
puts line.blue
|
25
|
+
puts "headers".intense_green
|
26
|
+
puts headerx.pj
|
27
|
+
puts line.blue
|
28
|
+
puts "body".intense_green
|
29
|
+
puts bodyx.pj
|
30
|
+
puts line.blue
|
31
|
+
puts "vars".intense_green
|
32
|
+
puts vars.pj
|
33
|
+
''
|
34
|
+
end
|
35
|
+
|
36
|
+
def _headers(prm)
|
37
|
+
prm==[] ? show_vars(headers) : set_value(:headers,prm)
|
38
|
+
end
|
39
|
+
|
40
|
+
def _body(prm)
|
41
|
+
prm==[] ? show_vars(bodies) : set_value(:bodies,prm)
|
42
|
+
end
|
43
|
+
|
44
|
+
def _vars(prm)
|
45
|
+
prm==[] ? show_vars(vars) : set_value(:vars,prm)
|
46
|
+
end
|
47
|
+
|
48
|
+
def _response(prm)
|
49
|
+
puts prm==[] ? @response.pj : @response[prm[0].to_sym].pj
|
50
|
+
"Inspecting..."
|
51
|
+
end
|
52
|
+
|
53
|
+
def _reset(prm)
|
54
|
+
@headers = {}
|
55
|
+
@bodies = {}
|
56
|
+
@vars = {}
|
57
|
+
save_vars
|
58
|
+
"Reset data"
|
59
|
+
end
|
60
|
+
|
61
|
+
def _reset_vars(prm)
|
62
|
+
prm==[] ? show_vars(vars) : reset_value(:vars,prm)
|
63
|
+
end
|
64
|
+
|
65
|
+
def _send(prm)
|
66
|
+
#p Rest::Terminal.instance_variable_get("@response")
|
67
|
+
headerx = headers
|
68
|
+
bodyx = bodies
|
69
|
+
varx = vars
|
70
|
+
line = ('-'*65)
|
71
|
+
|
72
|
+
puts line.yellow
|
73
|
+
puts "[#{varx[:conn]}] #{varx[:url]}".intense_blue
|
74
|
+
puts line.blue
|
75
|
+
puts "request".intense_green
|
76
|
+
puts({"headers" => headerx,"body" => bodyx}.pj)
|
77
|
+
begin
|
78
|
+
conn = Faraday.new(:url => varx[:url])
|
79
|
+
resp = conn.send(varx[:conn]) do |req|
|
80
|
+
req.body = body_join
|
81
|
+
req.headers = headerx
|
82
|
+
end.env
|
83
|
+
if /application\/json/=~resp[:response_headers]["content-type"]
|
84
|
+
body = JSON.parse(resp[:body])
|
85
|
+
else
|
86
|
+
body = resp[:body]
|
87
|
+
end
|
88
|
+
@response = {
|
89
|
+
:status => resp[:status],
|
90
|
+
:headers => resp[:response_headers],
|
91
|
+
:body => body
|
92
|
+
}
|
93
|
+
Rest::Terminal.instance_variable_set("@response",@response)
|
94
|
+
puts line.red
|
95
|
+
puts "response".intense_green
|
96
|
+
puts @response.pj #[:response_headers].inspect
|
97
|
+
save_vars
|
98
|
+
""
|
99
|
+
rescue Faraday::Error::ConnectionFailed => e
|
100
|
+
"#{e}"
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
def headers(up=true)
|
106
|
+
inheritances(:headers,up).select{|k,v|v && !v.empty?}
|
107
|
+
end
|
108
|
+
|
109
|
+
def bodies(up=true)
|
110
|
+
inheritances(:bodies,up).select{|k,v|v && !v.empty?}
|
111
|
+
end
|
112
|
+
|
113
|
+
def vars(up=true)
|
114
|
+
inheritances(:vars,up).select{|k,v|v && !v.empty?}
|
115
|
+
end
|
116
|
+
|
117
|
+
def inheritances(key,up)
|
118
|
+
@_tmp = {}
|
119
|
+
@_tmp.merge!(@parent.send(:inheritances,key,up)) if @parent && up
|
120
|
+
@_tmp = @_tmp.merge(instance_variable_get("@#{key}"))
|
121
|
+
# p "p: #{@path} - #{@vars} #{@parent.class} >> i: #{@_tmp}"
|
122
|
+
@_tmp
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
def reset
|
127
|
+
if @parent
|
128
|
+
@headers = {}
|
129
|
+
@bodies = {}
|
130
|
+
@vars = {}
|
131
|
+
else
|
132
|
+
@headers = def_headers
|
133
|
+
@bodies = def_bodies
|
134
|
+
@vars = def_vars
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def show_send_headers
|
139
|
+
show_vars(@headers)
|
140
|
+
end
|
141
|
+
|
142
|
+
def show_send_bodies
|
143
|
+
show_vars(@bodies)
|
144
|
+
end
|
145
|
+
|
146
|
+
def show_send_vars
|
147
|
+
v1 = [:conn,:url,:body]
|
148
|
+
v2 = vars
|
149
|
+
show_vars(Hash[v1.collect{|x|[x,v2[x]]}])
|
150
|
+
end
|
151
|
+
|
152
|
+
def body_join
|
153
|
+
bodies.collect do |k,v|
|
154
|
+
"#{k}=#{v}"
|
155
|
+
end.join("&")
|
156
|
+
end
|
157
|
+
|
158
|
+
def set_value(key,prm)
|
159
|
+
item = instance_variable_get("@#{key}")
|
160
|
+
prm.each do |p|
|
161
|
+
k,v = p.split('=',2).collect{|x|x.strip}
|
162
|
+
if k[/\*/]
|
163
|
+
p "k,v: #{k} #{v.class} #{@bodies.inspect}"
|
164
|
+
self.send(key).select{|x,y|x[/#{k}/]}.each do |x,y|
|
165
|
+
if v=='nil'
|
166
|
+
item.delete(x)
|
167
|
+
elsif v=='*'
|
168
|
+
item[x] = y
|
169
|
+
else
|
170
|
+
item[x] = v
|
171
|
+
end
|
172
|
+
end
|
173
|
+
else
|
174
|
+
if v=='nil'
|
175
|
+
item.delete(k.to_sym)
|
176
|
+
else
|
177
|
+
item[k.to_sym] = v
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
save_vars
|
182
|
+
"OK"
|
183
|
+
end
|
184
|
+
|
185
|
+
def show_vars(items)
|
186
|
+
items.each do |v|
|
187
|
+
puts "#{v[0]} = #{v[1]}"
|
188
|
+
end
|
189
|
+
"#{items.length} items".green
|
190
|
+
end
|
191
|
+
|
192
|
+
def def_headers
|
193
|
+
{
|
194
|
+
:"content-type" => 'application/json'
|
195
|
+
}
|
196
|
+
end
|
197
|
+
|
198
|
+
def def_bodies
|
199
|
+
{
|
200
|
+
|
201
|
+
}
|
202
|
+
end
|
203
|
+
|
204
|
+
def def_vars
|
205
|
+
{
|
206
|
+
:conn => 'get',
|
207
|
+
:url => 'http://localhost:3000'
|
208
|
+
}
|
209
|
+
end
|
210
|
+
|
211
|
+
def save_vars
|
212
|
+
b = ['']
|
213
|
+
b << "response = #{@response.inspect}"
|
214
|
+
b << "headers = #{@headers.inspect}"
|
215
|
+
b << "bodies = #{@bodies.inspect}"
|
216
|
+
b << "vars = #{@vars.inspect}"
|
217
|
+
c = b.join("\n")
|
218
|
+
s = "#vars_start(.*)#vars_end"
|
219
|
+
|
220
|
+
if !File.exists?("services#{@path}service.rb")
|
221
|
+
`cp service.rb services#{@path}`
|
222
|
+
end
|
223
|
+
|
224
|
+
code = IO.read("services#{@path}service.rb")
|
225
|
+
#-----------------------------------------
|
226
|
+
x = code.split(/#{s}/m)
|
227
|
+
x[1] = "#vars_start#{c}\n#vars_end"
|
228
|
+
#-----------------------------------------
|
229
|
+
IO.write("services#{@path}service.rb", x.join)
|
230
|
+
end
|
231
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rest-terminal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- WHarsojo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: term-ansicolor
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: faraday
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description:
|
63
|
+
email:
|
64
|
+
- wharsojo@gmail.com
|
65
|
+
executables:
|
66
|
+
- rest
|
67
|
+
- rt
|
68
|
+
extensions: []
|
69
|
+
extra_rdoc_files: []
|
70
|
+
files:
|
71
|
+
- bin/rest
|
72
|
+
- bin/rt
|
73
|
+
- lib/rest.rb
|
74
|
+
- lib/service_base.rb
|
75
|
+
- lib/rest/terminal.rb
|
76
|
+
- lib/rest/terminal/commands.rb
|
77
|
+
- lib/rest/terminal/commands_info.rb
|
78
|
+
- lib/rest/terminal/persistent.rb
|
79
|
+
- lib/rest/terminal/persistent_rc.rb
|
80
|
+
- lib/rest/service.rb
|
81
|
+
- lib/rest/version.rb
|
82
|
+
homepage: http://github.com/wharsojo
|
83
|
+
licenses: []
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project: rest-terminal
|
102
|
+
rubygems_version: 1.8.24
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Rest API Test on Terminal
|
106
|
+
test_files: []
|