faraday-cli 0.2.0 → 0.3.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: fd56916e841f94acb051ef3bba61c781365b4a33
4
- data.tar.gz: 5e082dcee9e28df98d2f42d5a56b1c1c73424875
3
+ metadata.gz: e5ef5d377a91ad8e8eabdda498fcad557a29db2e
4
+ data.tar.gz: 9c35a33ccb6620728fd954a277ec5ee5d7eb7ff8
5
5
  SHA512:
6
- metadata.gz: a3829febeef5abbaa2b29f870e8a936c643a6ecea4c07621b076ca0ddcb8379af78f20aff2d78b66b18d4ce9b2363cfa25564fa3e595b67f4b9c5d302bcdd02a
7
- data.tar.gz: 3647c38fe784742544750f762687538c803ecca19801ec05900602cbedbe2e28fe9794732a5d0ebcebf0cb9bbff33a6608a84556783d512d2bb50d3ec72aeeac
6
+ metadata.gz: e6fa22cfa76b24c399d4d23a475c261645b561829e42425f42e86c32e915952be0e857dfaef085307789472e67fe46bec4457d284fbcbd6149d264807aa6f86f
7
+ data.tar.gz: c51b1ec867372bd33d75f993f6b00d18e4b1c13e13c99bc8aed6cf4f4563f88aa2467ec3a479d2995606a5ef380aab8b4aa2e9a48d132bdf4653ddad74ecb872
data/README.md CHANGED
@@ -21,21 +21,32 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
- #### Basic
24
+ ### CLI options
25
+
26
+ ```shell
27
+ Usage: faraday-cli [options] <url>
28
+ -V, --version Show version number and quit
29
+ -X, --request COMMAND Specify http request command to use
30
+ -H, --header HEADER:VALUE Pass custom header LINE to server (H)
31
+ -q, --query key=value Pass Query key values to use in the request
32
+ -d, --data PAYLOAD_STRING HTTP POST data (H)
33
+ --upload_file KEY=FILE_PATH[:CONTENT_TYPE]
34
+ Pass File upload io in the request pointing to the given file
35
+ -A, --user-agent STRING Send User-Agent STRING to server (H)
36
+ -o, --output FILE_PATH Write to FILE instead of stdout
37
+ -s, --silent Silent mode (don't output anything)
38
+ -c, --config FILE_PATH File path to the .faraday.rb if you want use other than default
39
+
40
+ faraday-cli http://www.google.com -q "q=hello world"
41
+ ```
25
42
 
26
- $ faraday-cli --help
27
- Usage: faraday-cli [options] <url>
28
- -V, --version Show version number and quit
29
- -X, --request COMMAND Specify http request command to use
30
- -H, --header HEADER:VALUE Pass custom header LINE to server (H)
31
- -q, --query key=value Pass Query key values to use in the request
32
-
33
- $ faraday-cli http://www.google.com -q "q=hello world"
43
+ ### Middleware use
34
44
 
35
- #### Advanced
45
+ You can use middlewares with ".faraday.rb" file.
46
+ Put any middleware related configuration into the file,
47
+ and use the 'use' method to include into the faraday connection.
36
48
 
37
- because it's faraday, you can use faraday middlewares as how you pleased
38
- just make a file with the following name: ".faraday.rb"
49
+ you can use any faraday middlewares as how you pleased.
39
50
 
40
51
  ```ruby
41
52
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
@@ -71,6 +71,10 @@ OptionParser.new do |o|
71
71
  CLI_OPTIONS[:config_file_paths] << File.realpath(file_path)
72
72
  end
73
73
 
74
+ o.on('-M','--middlewares','Show current middleware stack') do
75
+ CLI_OPTIONS[:flags] << :show_middlewares
76
+ end
77
+
74
78
  o.parse!
75
79
 
76
80
  end
@@ -88,6 +92,12 @@ connection = Faraday.new do |builder|
88
92
 
89
93
  end
90
94
 
95
+ if CLI_OPTIONS[:flags].include?(:show_middlewares)
96
+ $stdout.puts(connection.builder.handlers.map(&:inspect))
97
+ exit
98
+ end
99
+
100
+
91
101
  response = connection.public_send(CLI_OPTIONS[:http_method].downcase) do |request|
92
102
 
93
103
  request.url(ARGV[0])
@@ -5,29 +5,32 @@ module Faraday::CLI::MiddlewareFetcher
5
5
  require 'faraday/cli/middleware_fetcher/container'
6
6
 
7
7
  def extend!(faraday_connection_builder, *config_file_paths)
8
-
9
- file_name = '.faraday.rb'
10
8
  container = Faraday::CLI::MiddlewareFetcher::Container.new(faraday_connection_builder)
9
+ get_file_paths(config_file_paths).each { |file_path| container.merge!(file_path) }
10
+ end
11
11
 
12
+ protected
13
+
14
+ def get_file_paths(config_file_paths)
15
+ file_name = '{.faraday.rb,.faraday}'
12
16
  case
13
17
 
14
18
  when !config_file_paths.empty?
15
- config_file_paths.each { |path| container.merge!(path) }
19
+ config_file_paths
16
20
 
17
- when File.exist?(File.join(Dir.pwd, file_name))
18
- container.merge!(File.join(Dir.pwd, file_name))
21
+ when !(file_paths = Dir.glob(File.join(Dir.pwd, file_name))).empty?
22
+ file_paths
19
23
 
20
- when File.exist?(File.join(PWD.pwd, file_name))
21
- container.merge!(File.join(PWD.pwd, file_name))
24
+ when !(file_paths = Dir.glob(File.join(PWD.pwd, file_name))).empty?
25
+ file_paths
22
26
 
23
- when File.exist?(File.join(ENV['HOME'], file_name))
24
- container.merge!(File.join(ENV['HOME'], file_name))
27
+ when !(file_paths = Dir.glob(File.join(ENV['HOME'], file_name))).empty?
28
+ file_paths
25
29
 
26
30
  else
27
- nil
31
+ []
28
32
 
29
33
  end
30
-
31
34
  end
32
35
 
33
36
  end
@@ -1,6 +1,7 @@
1
1
  require 'forwardable'
2
2
  class Faraday::CLI::MiddlewareFetcher::Container
3
3
 
4
+ #TODO: remove support for adapter set
4
5
  extend Forwardable
5
6
  def_delegators :@builder, :use, :request, :response, :adapter
6
7
 
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.2.0
4
+ version: 0.3.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-18 00:00:00.000000000 Z
11
+ date: 2015-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -103,7 +103,6 @@ executables:
103
103
  extensions: []
104
104
  extra_rdoc_files: []
105
105
  files:
106
- - ".faraday.rb"
107
106
  - ".gitignore"
108
107
  - ".rspec"
109
108
  - ".travis.yml"
@@ -1,14 +0,0 @@
1
- class MW
2
-
3
- def initialize(app)
4
- @app = app
5
- end
6
-
7
- def call(env)
8
- puts env.object_id
9
- @app.call(env)
10
- end
11
-
12
- end
13
-
14
- use MW