response_mate 0.1.14 → 0.2.0
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/.gitignore +3 -0
- data/.rspec +2 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +78 -43
- data/Guardfile +16 -0
- data/LICENSE +1 -1
- data/Rakefile +1 -1
- data/bin/response_mate +9 -1
- data/lib/response_mate/cli.rb +5 -16
- data/lib/response_mate/commands/inspect.rb +15 -35
- data/lib/response_mate/commands/list.rb +36 -47
- data/lib/response_mate/commands/record.rb +3 -10
- data/lib/response_mate/connection.rb +13 -20
- data/lib/response_mate/core.rb +3 -3
- data/lib/response_mate/environment.rb +1 -1
- data/lib/response_mate/inspector.rb +7 -39
- data/lib/response_mate/manifest.rb +16 -28
- data/lib/response_mate/recorder.rb +9 -20
- data/lib/response_mate/request.rb +33 -0
- data/lib/response_mate/tape.rb +17 -5
- data/lib/response_mate/version.rb +1 -1
- data/lib/response_mate.rb +2 -1
- data/response_mate.gemspec +1 -6
- data/spec/lib/response_mate/commands/inspect_spec.rb +61 -0
- data/spec/lib/response_mate/commands/list_spec.rb +53 -0
- data/spec/lib/response_mate/commands/record_spec.rb +91 -0
- data/spec/lib/response_mate/core_spec.rb +0 -7
- data/spec/lib/response_mate/recorder_spec.rb +50 -80
- data/spec/source/environment.yml +1 -0
- data/spec/source/requests.yml +20 -0
- data/spec/source/responses/.gitkeep +0 -0
- data/spec/spec_helper.rb +3 -23
- data/spec/support/stubbed_requests.rb +45 -0
- metadata +75 -102
- checksums.yaml +0 -7
- data/lib/response_mate/oauth.rb +0 -17
data/.gitignore
CHANGED
data/.rspec
ADDED
data/Gemfile
CHANGED
@@ -3,3 +3,15 @@ source 'https://rubygems.org'
|
|
3
3
|
gemspec
|
4
4
|
|
5
5
|
gem 'coveralls', require: false
|
6
|
+
|
7
|
+
group :development, :test do
|
8
|
+
gem 'pry-debugger'
|
9
|
+
gem 'guard-rspec', require: false
|
10
|
+
gem 'guard-rubocop', require: false
|
11
|
+
end
|
12
|
+
|
13
|
+
group :test do
|
14
|
+
gem 'rspec', '~> 2.14.0'
|
15
|
+
gem 'simplecov', '~> 0.8.2'
|
16
|
+
gem 'fakeweb', '~> 1.2.8'
|
17
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
response_mate (0.
|
4
|
+
response_mate (0.2.0)
|
5
5
|
activesupport
|
6
6
|
addressable
|
7
7
|
awesome_print
|
@@ -10,86 +10,120 @@ PATH
|
|
10
10
|
faraday_middleware
|
11
11
|
highline
|
12
12
|
mustache
|
13
|
-
thor (~> 0.
|
13
|
+
thor (~> 0.19)
|
14
14
|
|
15
15
|
GEM
|
16
16
|
remote: https://rubygems.org/
|
17
17
|
specs:
|
18
|
-
activesupport (4.
|
19
|
-
i18n (~> 0.6, >= 0.6.
|
20
|
-
|
21
|
-
|
18
|
+
activesupport (4.1.4)
|
19
|
+
i18n (~> 0.6, >= 0.6.9)
|
20
|
+
json (~> 1.7, >= 1.7.7)
|
21
|
+
minitest (~> 5.1)
|
22
22
|
thread_safe (~> 0.1)
|
23
|
-
tzinfo (~>
|
24
|
-
addressable (2.3.
|
25
|
-
ast (
|
26
|
-
atomic (1.1.14)
|
23
|
+
tzinfo (~> 1.1)
|
24
|
+
addressable (2.3.6)
|
25
|
+
ast (2.0.0)
|
27
26
|
awesome_print (1.2.0)
|
28
|
-
|
27
|
+
celluloid (0.15.2)
|
28
|
+
timers (~> 1.1.0)
|
29
|
+
coderay (1.1.0)
|
29
30
|
colored (1.2)
|
31
|
+
columnize (0.8.9)
|
30
32
|
coveralls (0.7.0)
|
31
33
|
multi_json (~> 1.3)
|
32
34
|
rest-client
|
33
35
|
simplecov (>= 0.7)
|
34
36
|
term-ansicolor
|
35
37
|
thor
|
38
|
+
debugger (1.6.6)
|
39
|
+
columnize (>= 0.3.1)
|
40
|
+
debugger-linecache (~> 1.2.0)
|
41
|
+
debugger-ruby_core_source (~> 1.3.2)
|
42
|
+
debugger-linecache (1.2.0)
|
43
|
+
debugger-ruby_core_source (1.3.5)
|
36
44
|
diff-lcs (1.2.5)
|
37
45
|
docile (1.1.1)
|
38
46
|
fakefs (0.4.3)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
47
|
+
fakeweb (1.2.8)
|
48
|
+
faraday (0.9.0)
|
49
|
+
multipart-post (>= 1.2, < 3)
|
50
|
+
faraday_middleware (0.9.1)
|
51
|
+
faraday (>= 0.7.4, < 0.10)
|
52
|
+
ffi (1.9.3)
|
53
|
+
formatador (0.2.4)
|
54
|
+
guard (2.6.1)
|
55
|
+
formatador (>= 0.2.4)
|
56
|
+
listen (~> 2.7)
|
57
|
+
lumberjack (~> 1.0)
|
58
|
+
pry (>= 0.9.12)
|
59
|
+
thor (>= 0.18.1)
|
60
|
+
guard-rspec (4.2.9)
|
61
|
+
guard (~> 2.1)
|
62
|
+
rspec (>= 2.14, < 4.0)
|
63
|
+
guard-rubocop (1.1.0)
|
64
|
+
guard (~> 2.0)
|
65
|
+
rubocop (~> 0.20)
|
66
|
+
highline (1.6.21)
|
44
67
|
i18n (0.6.9)
|
68
|
+
json (1.8.1)
|
69
|
+
listen (2.7.5)
|
70
|
+
celluloid (>= 0.15.2)
|
71
|
+
rb-fsevent (>= 0.9.3)
|
72
|
+
rb-inotify (>= 0.9)
|
73
|
+
lumberjack (1.0.5)
|
45
74
|
method_source (0.8.2)
|
46
75
|
mime-types (2.0)
|
47
|
-
minitest (
|
76
|
+
minitest (5.3.5)
|
48
77
|
multi_json (1.8.2)
|
49
|
-
multipart-post (
|
78
|
+
multipart-post (2.0.0)
|
50
79
|
mustache (0.99.5)
|
51
|
-
parser (2.1.
|
52
|
-
ast (
|
80
|
+
parser (2.1.9)
|
81
|
+
ast (>= 1.1, < 3.0)
|
53
82
|
slop (~> 3.4, >= 3.4.5)
|
54
83
|
powerpack (0.0.9)
|
55
|
-
pry (0.9.12.
|
56
|
-
coderay (~> 1.0
|
84
|
+
pry (0.9.12.6)
|
85
|
+
coderay (~> 1.0)
|
57
86
|
method_source (~> 0.8)
|
58
87
|
slop (~> 3.4)
|
59
|
-
pry-
|
88
|
+
pry-debugger (0.2.2)
|
89
|
+
debugger (~> 1.3)
|
60
90
|
pry (~> 0.9.10)
|
61
|
-
|
62
|
-
pry (~> 0.9)
|
63
|
-
slop (~> 3.0)
|
64
|
-
rainbow (1.99.0)
|
91
|
+
rainbow (2.0.0)
|
65
92
|
rake (10.1.0)
|
93
|
+
rb-fsevent (0.9.4)
|
94
|
+
rb-inotify (0.9.4)
|
95
|
+
ffi (>= 0.5.0)
|
66
96
|
rest-client (1.6.7)
|
67
97
|
mime-types (>= 1.16)
|
68
98
|
rspec (2.14.1)
|
69
99
|
rspec-core (~> 2.14.0)
|
70
100
|
rspec-expectations (~> 2.14.0)
|
71
101
|
rspec-mocks (~> 2.14.0)
|
72
|
-
rspec-core (2.14.
|
73
|
-
rspec-expectations (2.14.
|
102
|
+
rspec-core (2.14.8)
|
103
|
+
rspec-expectations (2.14.5)
|
74
104
|
diff-lcs (>= 1.1.3, < 2.0)
|
75
|
-
rspec-mocks (2.14.
|
76
|
-
rubocop (0.
|
77
|
-
|
105
|
+
rspec-mocks (2.14.6)
|
106
|
+
rubocop (0.23.0)
|
107
|
+
json (>= 1.7.7, < 2)
|
108
|
+
parser (~> 2.1.9)
|
78
109
|
powerpack (~> 0.0.6)
|
79
|
-
rainbow (>= 1.1.
|
110
|
+
rainbow (>= 1.99.1, < 3.0)
|
111
|
+
ruby-progressbar (~> 1.4)
|
112
|
+
ruby-progressbar (1.5.1)
|
80
113
|
simplecov (0.8.2)
|
81
114
|
docile (~> 1.1.0)
|
82
115
|
multi_json
|
83
116
|
simplecov-html (~> 0.8.0)
|
84
117
|
simplecov-html (0.8.0)
|
85
|
-
slop (3.
|
118
|
+
slop (3.5.0)
|
86
119
|
term-ansicolor (1.2.2)
|
87
120
|
tins (~> 0.8)
|
88
|
-
thor (0.
|
89
|
-
thread_safe (0.
|
90
|
-
|
121
|
+
thor (0.19.1)
|
122
|
+
thread_safe (0.3.4)
|
123
|
+
timers (1.1.0)
|
91
124
|
tins (0.13.1)
|
92
|
-
tzinfo (
|
125
|
+
tzinfo (1.2.1)
|
126
|
+
thread_safe (~> 0.1)
|
93
127
|
|
94
128
|
PLATFORMS
|
95
129
|
ruby
|
@@ -98,10 +132,11 @@ DEPENDENCIES
|
|
98
132
|
bundler (~> 1.3)
|
99
133
|
coveralls
|
100
134
|
fakefs
|
101
|
-
|
102
|
-
|
103
|
-
|
135
|
+
fakeweb (~> 1.2.8)
|
136
|
+
guard-rspec
|
137
|
+
guard-rubocop
|
138
|
+
pry-debugger
|
104
139
|
rake
|
105
140
|
response_mate!
|
106
|
-
rspec (~> 2.14)
|
107
|
-
|
141
|
+
rspec (~> 2.14.0)
|
142
|
+
simplecov (~> 0.8.2)
|
data/Guardfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
rspec_options = {
|
2
|
+
cmd: "bundle exec rspec --order rand"
|
3
|
+
}
|
4
|
+
|
5
|
+
guard 'rspec', rspec_options do
|
6
|
+
watch(%r{^spec/.+_spec\.rb$})
|
7
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
8
|
+
watch('spec/spec_helper.rb') { "spec" }
|
9
|
+
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
end
|
12
|
+
|
13
|
+
#guard :rubocop, all_on_start: false do
|
14
|
+
#watch(%r{.+\.rb$})
|
15
|
+
#watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
16
|
+
#end
|
data/LICENSE
CHANGED
data/Rakefile
CHANGED
data/bin/response_mate
CHANGED
@@ -3,4 +3,12 @@
|
|
3
3
|
|
4
4
|
require 'response_mate'
|
5
5
|
|
6
|
-
|
6
|
+
begin
|
7
|
+
ResponseMate::CLI.start(ARGV)
|
8
|
+
rescue ResponseMate::OutputDirError
|
9
|
+
puts <<-OUT
|
10
|
+
Output directory does not exist, invoking setup..
|
11
|
+
Please retry after setup
|
12
|
+
OUT
|
13
|
+
ResponseMate::CLI.start(['setup'])
|
14
|
+
end
|
data/lib/response_mate/cli.rb
CHANGED
@@ -5,23 +5,17 @@ module ResponseMate
|
|
5
5
|
package_name 'response_mate'
|
6
6
|
|
7
7
|
desc 'record', 'Perform requests and record their output'
|
8
|
-
method_option :base_url, aliases: '-b'
|
9
8
|
method_option :requests_manifest, aliases: '-r'
|
10
|
-
method_option :keys, aliases: '-k', type: :array
|
9
|
+
method_option :keys, aliases: '-k', type: :array, default: []
|
11
10
|
def record
|
12
11
|
ResponseMate::Commands::Record.new(args, options).run
|
13
|
-
|
14
|
-
|
15
|
-
puts 'Output directory does not exist, invoking setup..'
|
16
|
-
puts 'Please retry after setup'
|
17
|
-
invoke :setup, []
|
12
|
+
rescue ResponseMate::KeysNotFound => e
|
13
|
+
puts "The requested keys: #{e.message} could not be found"
|
18
14
|
end
|
19
15
|
|
20
16
|
desc 'inspect [key1,key2]', 'Perform requests and print their output'
|
21
|
-
method_option :base_url, aliases: '-b'
|
22
17
|
method_option :requests_manifest, aliases: '-r'
|
23
|
-
method_option :interactive, type: :boolean, aliases:
|
24
|
-
method_option :print, type: :string, aliases: '-p', default: 'raw'
|
18
|
+
method_option :interactive, type: :boolean, aliases: '-i'
|
25
19
|
def inspect(*keys)
|
26
20
|
ResponseMate::Commands::Inspect.new(args, options).run
|
27
21
|
end
|
@@ -41,16 +35,11 @@ module ResponseMate
|
|
41
35
|
method_option :requests_manifest, aliases: '-r'
|
42
36
|
def list(type = 'requests')
|
43
37
|
ResponseMate::Commands::List.new(args, options).run
|
44
|
-
|
45
|
-
rescue ResponseMate::OutputDirError
|
46
|
-
puts 'Output directory does not exist, invoking setup..'
|
47
|
-
puts 'Please retry after setup'
|
48
|
-
invoke :setup, []
|
49
38
|
end
|
50
39
|
|
51
40
|
desc 'version', 'Print version information'
|
52
41
|
def version
|
53
|
-
puts "
|
42
|
+
puts "response_mate version #{ResponseMate::VERSION}"
|
54
43
|
end
|
55
44
|
map ['--version'] => :version
|
56
45
|
|
@@ -1,44 +1,24 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
attr_reader :inspector
|
7
|
-
attr_accessor :history
|
3
|
+
class ResponseMate::Commands::Inspect < ResponseMate::Commands::Base
|
4
|
+
attr_reader :inspector
|
5
|
+
attr_accessor :history
|
8
6
|
|
9
|
-
|
10
|
-
|
7
|
+
def initialize(args, options)
|
8
|
+
super(args, options)
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
@options[:manifest] = ResponseMate::Manifest.new(options[:requests_manifest])
|
11
|
+
@inspector = ResponseMate::Inspector.new(@options)
|
12
|
+
@history = []
|
13
|
+
end
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
args.each do |key|
|
22
|
-
inspector.inspect_key(key)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
15
|
+
def run
|
16
|
+
if args.empty?
|
17
|
+
return $stderr.puts 'At least one key has to be specified'.red
|
18
|
+
end
|
26
19
|
|
27
|
-
|
28
|
-
|
29
|
-
input = ask('response_mate> ')
|
30
|
-
case input
|
31
|
-
when 'history'
|
32
|
-
input = choose { |menu|
|
33
|
-
menu.prompt = 'Replay any?'
|
34
|
-
menu.choices(*([:no] + history))
|
35
|
-
}.to_s
|
36
|
-
else
|
37
|
-
history << input
|
38
|
-
end
|
39
|
-
inspector.inspect_interactive(input)
|
40
|
-
end
|
41
|
-
end
|
20
|
+
args.each do |key|
|
21
|
+
inspector.inspect_key(key)
|
42
22
|
end
|
43
23
|
end
|
44
24
|
end
|
@@ -1,52 +1,41 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
class ResponseMate::Commands::List < ResponseMate::Commands::Base
|
3
|
+
def run
|
4
|
+
environment = ResponseMate::Environment.new(options[:environment])
|
5
|
+
@manifest = ResponseMate::Manifest.new(options[:requests_manifest], environment)
|
2
6
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
menu.prompt = 'Which one?'
|
36
|
-
menu.choices(*choices)
|
37
|
-
}.to_s
|
38
|
-
end
|
39
|
-
|
40
|
-
if key
|
41
|
-
case action
|
42
|
-
when :record
|
43
|
-
ResponseMate::Recorder.new({ manifest: options[:manifest], keys: [key] }).
|
44
|
-
record
|
45
|
-
when :inspect
|
46
|
-
ResponseMate::Inspector.new(manifest: options[:manifest]).inspect_key(key)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
7
|
+
available_keys = @manifest.requests.map { |r| r.key.to_sym }
|
8
|
+
|
9
|
+
puts available_keys.join("\n") << "\n\n"
|
10
|
+
|
11
|
+
action = ask_action
|
12
|
+
return if action == :no
|
13
|
+
|
14
|
+
perform_action(action, ask_key(available_keys))
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def ask_action
|
20
|
+
choose do |menu|
|
21
|
+
menu.prompt = 'Want to perform any of the actions above?'
|
22
|
+
menu.choices(:record, :inspect, :no)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def ask_key(available_keys)
|
27
|
+
choose { |menu|
|
28
|
+
menu.prompt = 'Which one?'
|
29
|
+
menu.choices(*available_keys)
|
30
|
+
}.to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
def perform_action(action, key)
|
34
|
+
case action
|
35
|
+
when :record
|
36
|
+
ResponseMate::Recorder.new(manifest: @manifest).record([key])
|
37
|
+
when :inspect
|
38
|
+
ResponseMate::Inspector.new(manifest: @manifest).inspect_key(key)
|
50
39
|
end
|
51
40
|
end
|
52
41
|
end
|
@@ -3,22 +3,15 @@
|
|
3
3
|
module ResponseMate
|
4
4
|
module Commands
|
5
5
|
# Handles the invocation of the record command
|
6
|
-
class
|
7
|
-
def initialize(args, options)
|
8
|
-
super(args, options)
|
9
|
-
@options = options.dup
|
10
|
-
end
|
11
|
-
|
6
|
+
class Record < Base
|
12
7
|
def run
|
13
8
|
environment = ResponseMate::Environment.new(options[:environment])
|
14
|
-
|
15
|
-
manifest = ResponseMate::Manifest.
|
16
|
-
new(options[:requests_manifest], environment)
|
9
|
+
manifest = ResponseMate::Manifest.new(options[:requests_manifest], environment)
|
17
10
|
|
18
11
|
options[:manifest] = manifest
|
19
12
|
recorder = ResponseMate::Recorder.new(options)
|
20
13
|
|
21
|
-
recorder.record
|
14
|
+
recorder.record(options[:keys])
|
22
15
|
|
23
16
|
File.open(ResponseMate.configuration.output_dir + '.last_recording', 'w') do |f|
|
24
17
|
f << Time.current
|
@@ -2,40 +2,33 @@
|
|
2
2
|
|
3
3
|
# This class provides a layer above the HTTP client
|
4
4
|
class ResponseMate::Connection
|
5
|
-
|
6
5
|
delegate :params, to: :client
|
7
6
|
delegate(*(ResponseMate::ManifestParser::HTTP_VERBS), to: :client)
|
8
7
|
|
9
|
-
attr_accessor :client
|
8
|
+
attr_accessor :client
|
10
9
|
|
11
|
-
def initialize
|
12
|
-
@base_url = base_url
|
10
|
+
def initialize
|
13
11
|
@client = Faraday.new do |c|
|
14
12
|
c.use FaradayMiddleware::FollowRedirects, limit: 5
|
15
13
|
c.adapter Faraday.default_adapter
|
16
14
|
end
|
17
|
-
|
18
|
-
client.headers.merge(ResponseMate::DEFAULT_HEADERS)
|
19
|
-
client.url_prefix = base_url if base_url
|
20
15
|
end
|
21
16
|
|
22
17
|
def fetch(request)
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
uri = URI.parse(request[:url])
|
19
|
+
|
20
|
+
if request[:params]
|
21
|
+
query = request[:params].to_query
|
22
|
+
query = uri.query ? uri.query << '&' << query : query
|
23
|
+
uri.query = query
|
26
24
|
end
|
27
|
-
|
25
|
+
|
26
|
+
verb = request[:verb] || 'GET'
|
27
|
+
|
28
|
+
client.headers = request[:headers] if request[:headers]
|
29
|
+
client.send verb.downcase.to_sym, uri.to_s
|
28
30
|
rescue Faraday::Error::ConnectionFailed
|
29
31
|
puts "Is a server up and running at #{request[:path]}?".red
|
30
32
|
exit 1
|
31
33
|
end
|
32
|
-
|
33
|
-
def set_headers_from_manifest(manifest)
|
34
|
-
if manifest.default_headers
|
35
|
-
manifest.default_headers.each_pair do |k, v|
|
36
|
-
|
37
|
-
client.headers[ResponseMate::Helpers.headerize(k)] = v
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
34
|
end
|
data/lib/response_mate/core.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
# The main module of the tool contains configuration code and some
|
2
|
+
# The main module of the tool contains configuration code and some constants
|
3
3
|
module ResponseMate
|
4
4
|
class OutputDirError < StandardError; end
|
5
|
+
class KeysNotFound < StandardError; end
|
5
6
|
|
6
7
|
DEFAULT_HEADERS = {
|
7
8
|
'User-Agent' => 'Response-Mate'
|
@@ -12,12 +13,11 @@ module ResponseMate
|
|
12
13
|
end
|
13
14
|
|
14
15
|
class Configuration
|
15
|
-
attr_accessor :output_dir, :requests_manifest, :
|
16
|
+
attr_accessor :output_dir, :requests_manifest, :environment
|
16
17
|
|
17
18
|
def initialize
|
18
19
|
@output_dir = './output/responses/'
|
19
20
|
@requests_manifest = './requests.yml'
|
20
|
-
@oauth_manifest = './oauth.yml'
|
21
21
|
@environment = './environment.yml'
|
22
22
|
end
|
23
23
|
end
|
@@ -1,56 +1,24 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
class ResponseMate::Inspector
|
4
|
-
attr_accessor :conn, :
|
4
|
+
attr_accessor :conn, :manifest
|
5
5
|
|
6
6
|
def initialize(args = {})
|
7
7
|
@manifest = args[:manifest]
|
8
|
-
@oauth = ResponseMate::Oauth.new
|
9
|
-
@base_url = args[:base_url] || manifest.base_url
|
10
|
-
@print_type = args[:print] || 'raw'
|
11
8
|
|
12
|
-
|
13
|
-
@conn = ResponseMate::Connection.new(base_url)
|
14
|
-
@conn.set_headers_from_manifest(manifest)
|
15
|
-
else
|
16
|
-
@conn = ResponseMate::Connection.new
|
17
|
-
end
|
9
|
+
@conn = ResponseMate::Connection.new
|
18
10
|
end
|
19
11
|
|
20
12
|
def inspect_key(key, options = {})
|
21
13
|
request = manifest.requests.find { |r| r.key == key }
|
22
|
-
request = ResponseMate::Manifest.parse_request(request.request)
|
23
14
|
|
24
|
-
puts
|
25
|
-
|
26
|
-
|
27
|
-
print(conn.fetch(request))
|
28
|
-
end
|
29
|
-
|
30
|
-
def inspect_interactive(input)
|
31
|
-
request = ResponseMate::Manifest.parse_request(input)
|
32
|
-
print(conn.fetch(request))
|
33
|
-
end
|
34
|
-
|
35
|
-
def print(response)
|
36
|
-
__send__ "print_#{print_type}", response
|
37
|
-
end
|
38
|
-
|
39
|
-
def print_raw(response)
|
40
|
-
puts "\n"
|
41
|
-
status = "#{response.status} #{ResponseMate::Http::STATUS_CODES[response.status]}"
|
42
|
-
puts "HTTP/1.1 #{status}"
|
43
|
-
response.headers.each_pair do |k, v|
|
44
|
-
puts "#{ResponseMate::Helpers.headerize(k)}: #{v}"
|
45
|
-
end
|
46
|
-
puts response.body
|
15
|
+
puts request.to_cli_format
|
16
|
+
print_pretty(conn.fetch(request))
|
47
17
|
end
|
48
18
|
|
49
19
|
def print_pretty(response)
|
50
|
-
ap(
|
51
|
-
|
52
|
-
|
53
|
-
body: response.body
|
54
|
-
)
|
20
|
+
ap(status: response.status,
|
21
|
+
headers: response.headers,
|
22
|
+
body: response.body)
|
55
23
|
end
|
56
24
|
end
|