faraday-cli 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65b179f90f061bf3461ab30bea1a8c336eeec630
4
- data.tar.gz: 60dfd772c68e2f907d063437a65edede32740651
3
+ metadata.gz: a7d7f7b331f42287d4e254f99ed969523bfa8b00
4
+ data.tar.gz: a0e11ea299acc38652d59ed5a31e03b250dfbbac
5
5
  SHA512:
6
- metadata.gz: 8d1f2be329eb7ad8d0e926bbb00bc6116fa9fb8bb298b662ed9e74bbbfa4be9a9b3df0d24ab9154727132f886c67ac667f816985225591542cab3805ba1a36d8
7
- data.tar.gz: 158bee6daa08f7ee9c96d3309bcc9320055d5e78415213ec9b8db16401aab492a7942e0da55655af2312d88841678caeec1055c192edcab1ad695463be9eb463
6
+ metadata.gz: f02c69445e412156866be56c6f137b2d19783dd37315f559beac5efe1ca1ca52aff2dc23e194e93560d7b8b2fcd375e9c43ec0c6d7bc39d562c17d2127adca9d
7
+ data.tar.gz: b43111af4766aa36d744f4108d50bc72333f967752532ce6c3731735f1eb047eee65bfa554ec8a4ea238a96859d1fcc52c349acb708fadf8888059b24eabbb50
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.1
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)") { CLI_OPTIONS[:flags] << :silent }
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
- builder.adapter(:net_http)
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
- response = connection.public_send(CLI_OPTIONS[:http_method].downcase) do |request|
123
+ FARADAY_ACTIVE_CONNECTION= connection
124
+ def active_connection
125
+ FARADAY_ACTIVE_CONNECTION
126
+ end
114
127
 
115
- raise('Missing URL for request!') if ARGV[0].nil?
116
- request.url(ARGV[0])
128
+ begin
117
129
 
118
- CLI_OPTIONS[:http_headers].each do |key, value|
119
- request.headers[key]=value
120
- end
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
- request.body = CLI_OPTIONS[:body] unless CLI_OPTIONS[:body].nil?
147
+ $stdout.puts(Faraday::CLI::ResponseFormatter.format(response, *CLI_OPTIONS[:flags]))
127
148
 
128
- end
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
- $stdout.puts Faraday::CLI::ResponseFormatter.format(response,*CLI_OPTIONS[:flags]) unless CLI_OPTIONS[:flags].include?(:silent)
131
- exit(1) if (400..599).include?(response.status)
157
+ end
@@ -0,0 +1,10 @@
1
+ require 'yaml'
2
+ class Faraday::CLI::Middleware::VerboseRequest < Faraday::Middleware
3
+
4
+ def call(request_env)
5
+ $stdout.puts(YAML.dump(request_env),"\n")
6
+
7
+ @app.call(request_env)
8
+ end
9
+
10
+ end
@@ -0,0 +1,3 @@
1
+ module Faraday::CLI::Middleware
2
+ require 'faraday/cli/middleware/verbose_request'
3
+ end
data/lib/faraday/cli.rb CHANGED
@@ -3,6 +3,7 @@ module Faraday::CLI
3
3
 
4
4
  require 'faraday/cli/version'
5
5
  require 'faraday/cli/client'
6
+ require 'faraday/cli/middleware'
6
7
  require 'faraday/cli/response_formatter'
7
8
  require 'faraday/cli/middleware_fetcher'
8
9
 
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.5.1
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-23 00:00:00.000000000 Z
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: