faraday-cli 0.5.1 → 0.6.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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/bin/faraday-cli +44 -18
- data/lib/faraday/cli/middleware/verbose_request.rb +10 -0
- data/lib/faraday/cli/middleware.rb +3 -0
- data/lib/faraday/cli.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7d7f7b331f42287d4e254f99ed969523bfa8b00
|
4
|
+
data.tar.gz: a0e11ea299acc38652d59ed5a31e03b250dfbbac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f02c69445e412156866be56c6f137b2d19783dd37315f559beac5efe1ca1ca52aff2dc23e194e93560d7b8b2fcd375e9c43ec0c6d7bc39d562c17d2127adca9d
|
7
|
+
data.tar.gz: b43111af4766aa36d744f4108d50bc72333f967752532ce6c3731735f1eb047eee65bfa554ec8a4ea238a96859d1fcc52c349acb708fadf8888059b24eabbb50
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.0
|
data/bin/faraday-cli
CHANGED
@@ -64,22 +64,27 @@ OptionParser.new do |o|
|
|
64
64
|
# CLI_OPTIONS[:proxy]= {host: host, port: port}
|
65
65
|
# end
|
66
66
|
|
67
|
-
o.on('-v','--verbose','Make the operation more talkative') do
|
67
|
+
o.on('-v', '--verbose', 'Make the operation more talkative') do
|
68
68
|
CLI_OPTIONS[:flags] << :verbose
|
69
69
|
end
|
70
70
|
|
71
|
-
o.on('-s', '--silent', "Silent mode (don't output anything)")
|
71
|
+
o.on('-s', '--silent', "Silent mode (don't output anything)") do
|
72
|
+
CLI_OPTIONS[:flags] << :silent
|
73
|
+
$stdout.reopen('/dev/null', 'a+')
|
74
|
+
$stderr.reopen('/dev/null', 'a+')
|
75
|
+
|
76
|
+
end
|
72
77
|
|
73
78
|
CLI_OPTIONS[:config_file_paths]= []
|
74
79
|
o.on('-K', '--config FILE_PATH', 'File path to the .faraday.rb if you want use other than default') do |file_path|
|
75
80
|
CLI_OPTIONS[:config_file_paths] << File.absolute_path(file_path)
|
76
81
|
end
|
77
82
|
|
78
|
-
o.on('-M','--middlewares','Show current middleware stack') do
|
83
|
+
o.on('-M', '--middlewares', 'Show current middleware stack') do
|
79
84
|
CLI_OPTIONS[:flags] << :show_middlewares
|
80
85
|
end
|
81
86
|
|
82
|
-
o.on('-W','--without_middlewares','Make request without consuming middleware file(s)') do
|
87
|
+
o.on('-W', '--without_middlewares', 'Make request without consuming middleware file(s)') do
|
83
88
|
CLI_OPTIONS[:flags] << :without_middlewares
|
84
89
|
end
|
85
90
|
|
@@ -91,18 +96,23 @@ end
|
|
91
96
|
|
92
97
|
ALLOWED_HTTP_METHODS = %w(get head post put patch delete options)
|
93
98
|
raise('invalid http method given') unless ALLOWED_HTTP_METHODS.include?(CLI_OPTIONS[:http_method])
|
99
|
+
is_verbose = !CLI_OPTIONS[:flags].include?(:silent) && CLI_OPTIONS[:flags].include?(:verbose)
|
94
100
|
|
95
101
|
connection = Faraday.new do |builder|
|
102
|
+
builder.use Faraday::Response::RaiseError
|
96
103
|
|
97
104
|
unless CLI_OPTIONS[:flags].include?(:without_middlewares)
|
98
105
|
Faraday::CLI::MiddlewareFetcher.extend!(builder, *CLI_OPTIONS[:config_file_paths])
|
99
106
|
end
|
100
107
|
|
101
108
|
builder.request(:multipart) if CLI_OPTIONS[:flags].include?(:multipart)
|
102
|
-
builder.response :logger if !CLI_OPTIONS[:flags].include?(:silent) && CLI_OPTIONS[:flags].include?(:verbose)
|
103
109
|
|
104
|
-
|
110
|
+
if is_verbose
|
111
|
+
builder.use Faraday::CLI::Middleware::VerboseRequest
|
112
|
+
builder.response :logger
|
113
|
+
end
|
105
114
|
|
115
|
+
builder.adapter(:net_http)
|
106
116
|
end
|
107
117
|
|
108
118
|
if CLI_OPTIONS[:flags].include?(:show_middlewares)
|
@@ -110,22 +120,38 @@ if CLI_OPTIONS[:flags].include?(:show_middlewares)
|
|
110
120
|
exit
|
111
121
|
end
|
112
122
|
|
113
|
-
|
123
|
+
FARADAY_ACTIVE_CONNECTION= connection
|
124
|
+
def active_connection
|
125
|
+
FARADAY_ACTIVE_CONNECTION
|
126
|
+
end
|
114
127
|
|
115
|
-
|
116
|
-
request.url(ARGV[0])
|
128
|
+
begin
|
117
129
|
|
118
|
-
CLI_OPTIONS[:
|
119
|
-
|
120
|
-
|
130
|
+
response = connection.public_send(CLI_OPTIONS[:http_method].downcase) do |request|
|
131
|
+
|
132
|
+
raise('Missing URL for request!') if ARGV[0].nil?
|
133
|
+
request.url(ARGV[0])
|
134
|
+
|
135
|
+
CLI_OPTIONS[:http_headers].each do |key, value|
|
136
|
+
request.headers[key]=value
|
137
|
+
end
|
138
|
+
|
139
|
+
CLI_OPTIONS[:params].each do |key, value|
|
140
|
+
request.params[key]=value
|
141
|
+
end
|
142
|
+
|
143
|
+
request.body = CLI_OPTIONS[:body] unless CLI_OPTIONS[:body].nil?
|
121
144
|
|
122
|
-
CLI_OPTIONS[:params].each do |key, value|
|
123
|
-
request.params[key]=value
|
124
145
|
end
|
125
146
|
|
126
|
-
|
147
|
+
$stdout.puts(Faraday::CLI::ResponseFormatter.format(response, *CLI_OPTIONS[:flags]))
|
127
148
|
|
128
|
-
|
149
|
+
rescue Faraday::Error => ex
|
150
|
+
$stdout.puts(ex.message)
|
151
|
+
exit(1)
|
152
|
+
|
153
|
+
rescue URI::InvalidURIError => ex
|
154
|
+
$stdout.puts(ex.message)
|
155
|
+
exit(1)
|
129
156
|
|
130
|
-
|
131
|
-
exit(1) if (400..599).include?(response.status)
|
157
|
+
end
|
data/lib/faraday/cli.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faraday-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -118,6 +118,8 @@ files:
|
|
118
118
|
- faraday-cli.gemspec
|
119
119
|
- lib/faraday/cli.rb
|
120
120
|
- lib/faraday/cli/client.rb
|
121
|
+
- lib/faraday/cli/middleware.rb
|
122
|
+
- lib/faraday/cli/middleware/verbose_request.rb
|
121
123
|
- lib/faraday/cli/middleware_fetcher.rb
|
122
124
|
- lib/faraday/cli/middleware_fetcher/container.rb
|
123
125
|
- lib/faraday/cli/response_formatter.rb
|
@@ -149,4 +151,3 @@ signing_key:
|
|
149
151
|
specification_version: 4
|
150
152
|
summary: Console line interface for faraday gem.
|
151
153
|
test_files: []
|
152
|
-
has_rdoc:
|