rest-terminal 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,4 +20,5 @@ require 'rest/version'
20
20
  require 'rest/terminal/commands'
21
21
  require 'rest/terminal/commands_info'
22
22
  require 'rest/terminal/persistent'
23
- require 'rest/terminal'
23
+ require 'rest/terminal'
24
+ require 'pry'
@@ -16,6 +16,7 @@ module Rest
16
16
  @repl = ''
17
17
  @type = 'earth'
18
18
  @serv = 'localhost'
19
+ @service = ''
19
20
  @services = { }
20
21
  @response = { }
21
22
  @spaces = [ ]
@@ -126,7 +127,9 @@ module Rest
126
127
  pth = full_path(prm)
127
128
  puts "Service: #{pth}".yellow
128
129
  # puts @services.keys.inspect
129
- @_status = @services[pth].send(cmd,prm)
130
+ svc = @services[pth]
131
+ svc.load_service
132
+ @_status = svc.send(cmd,prm)
130
133
  end
131
134
  end
132
135
 
@@ -34,6 +34,7 @@ module Rest
34
34
  b << "@pwd = #{@pwd.inspect}"
35
35
  b << "@serv = #{@serv.inspect}"
36
36
  b << "@hist = #{@hist.inspect}"
37
+ b << "@service = #{@service.inspect}"
37
38
  b << "@response = #{@response.inspect}"
38
39
  c = b.join("\n ")
39
40
  s = "#env_start(.*)#env_end"
@@ -23,7 +23,7 @@ module Rest
23
23
 
24
24
  # :nodoc:
25
25
  def patch
26
- 7
26
+ 8
27
27
  end
28
28
 
29
29
  # :nodoc:
@@ -8,6 +8,11 @@ class ServiceBase
8
8
  @response = {}
9
9
  @parent = vc
10
10
  reset(%w(headers body vars))
11
+ load_service
12
+ end
13
+
14
+ def load_service
15
+ # p "services#{path}service.rb"
11
16
  if File.exists?("services#{path}service.rb")
12
17
  instance_eval(IO.read("services#{path}service.rb"))
13
18
  end
@@ -20,7 +25,6 @@ class ServiceBase
20
25
  line = ('-'*65)
21
26
 
22
27
  puts ('='*65).yellow
23
- # puts "[#{varx[:conn]}] #{varx[:url]}".intense_blue
24
28
  puts line.blue
25
29
  puts "headers".intense_green
26
30
  puts headerx.pj
@@ -59,7 +63,6 @@ class ServiceBase
59
63
  end
60
64
 
61
65
  def _send(prm)
62
- #p Rest::Terminal.instance_variable_get("@response")
63
66
  headerx = headers
64
67
  bodyx = bodies
65
68
  varx = vars
@@ -76,7 +79,8 @@ class ServiceBase
76
79
  req.body = body_join
77
80
  req.headers = headerx
78
81
  end.env
79
- if /application\/json/=~resp[:response_headers]["content-type"]
82
+ ct = resp[:response_headers]["content-type"]
83
+ if ct && /application\/json/=~ct.downcase
80
84
  body = JSON.parse(resp[:body])
81
85
  else
82
86
  body = resp[:body]
@@ -86,10 +90,11 @@ class ServiceBase
86
90
  :headers => resp[:response_headers],
87
91
  :body => body
88
92
  }
93
+ Rest::Terminal.instance_variable_set("@service",@path)
89
94
  Rest::Terminal.instance_variable_set("@response",@response)
90
95
  puts line.red
91
96
  puts "response".intense_green
92
- puts @response.pj #[:response_headers].inspect
97
+ puts @response.pj
93
98
  save_vars
94
99
  ""
95
100
  rescue Faraday::Error::ConnectionFailed => e
@@ -99,15 +104,15 @@ class ServiceBase
99
104
  end
100
105
 
101
106
  def headers(up=true)
102
- inheritances(:headers,up).select{|k,v|v && !v.empty?}
107
+ inheritances(:headers,up).select{|k,v|v}
103
108
  end
104
109
 
105
110
  def bodies(up=true)
106
- inheritances(:bodies,up).select{|k,v|v && !v.empty?}
111
+ inheritances(:bodies,up).select{|k,v|v}
107
112
  end
108
113
 
109
114
  def vars(up=true)
110
- inheritances(:vars,up).select{|k,v|v && !v.empty?}
115
+ inheritances(:vars,up).select{|k,v|v}
111
116
  end
112
117
 
113
118
  def inheritances(key,up)
@@ -122,8 +127,17 @@ class ServiceBase
122
127
  end
123
128
 
124
129
  private
125
- # ex: rest reset body
126
- # reset value to def_value or empty/[]
130
+
131
+ def last_service
132
+ t = Rest::Terminal
133
+ s = t.instance_variable_get("@service")
134
+ t.instance_variable_get("@services")[s]
135
+ end
136
+
137
+ def last_response
138
+ Rest::Terminal.instance_variable_get("@response")
139
+ end
140
+
127
141
  def reset(prm)
128
142
  params = prm - (prm - %w(headers body vars))
129
143
  params.each do |x|
@@ -155,7 +169,8 @@ class ServiceBase
155
169
  end
156
170
 
157
171
  def body_join
158
- if headers[:"content-type"]=='application/json'
172
+ ct = headers[:"content-type"]
173
+ if ct && /application\/json/=~ct.downcase
159
174
  body = bodies.to_json
160
175
  else
161
176
  body = bodies.collect do |k,v|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-terminal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-30 00:00:00.000000000 Z
12
+ date: 2012-11-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json