faraday-verbose_ws_wrapper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 68f92cf8c6145a5f3ef7c114d7c97cb96626a4330b40025847b7c1e9332d3e08
4
+ data.tar.gz: 687f464c1360f5a37e13d11a8b7152638b6c315c984a852547497b24c56b838e
5
+ SHA512:
6
+ metadata.gz: bb384a47db930911cc668156d77efacdad0d91534cb73e23e692a14c4182765518ea81b5efa8d1f3d7e2fcba5104164a18213fc8bd6a174f02dee3210c705a72
7
+ data.tar.gz: cfd1cbcf3203f403bb246d256579f9b80f2630e9fb0fb754878360899d3de4bfba40e207ea5309229a3f4bf944368d9ccdac66c6ef8e9176db08f62962a6874b
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ * Initial release.
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 masciugo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Faraday Verbose Ws Wrapper
2
+
3
+ [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/masciugo/faraday-verbose_ws_wrapper/ci)](https://github.com/masciugo/faraday-verbose_ws_wrapper/actions?query=branch%3Amain)
4
+ [![Gem](https://img.shields.io/gem/v/faraday-verbose_ws_wrapper.svg?style=flat-square)](https://rubygems.org/gems/faraday-verbose_ws_wrapper)
5
+ [![License](https://img.shields.io/github/license/masciugo/faraday-verbose_ws_wrapper.svg?style=flat-square)](LICENSE.md)
6
+
7
+ faraday middleware to make Rails logger more verbose.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'faraday-verbose_ws_wrapper'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```shell
20
+ bundle install
21
+ ```
22
+
23
+ Or install it yourself as:
24
+
25
+ ```shell
26
+ gem install faraday-verbose_ws_wrapper
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ```ruby
32
+ require 'faraday/verbose_ws_wrapper'
33
+
34
+ # TODO
35
+ ```
36
+
37
+ ## Development
38
+
39
+ After checking out the repo, run `bin/setup` to install dependencies.
40
+
41
+ Then, run `bin/test` to run the tests.
42
+
43
+ To install this gem onto your local machine, run `rake build`.
44
+
45
+ To release a new version, make a commit with a message such as "Bumped to 0.0.2" and then run `rake release`.
46
+ See how it works [here](https://bundler.io/guides/creating_gem.html#releasing-the-gem).
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/masciugo/faraday-verbose_ws_wrapper).
51
+
52
+ ## License
53
+
54
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faraday
4
+ module VerboseWsWrapper
5
+ # This class provides the main implementation for your middleware.
6
+ # Your middleware can implement any of the following methods:
7
+ # * on_request - called when the request is being prepared
8
+ # * on_complete - called when the response is being processed
9
+ #
10
+ # Optionally, you can also override the following methods from Faraday::Middleware
11
+ # * initialize(app, options = {}) - the initializer method
12
+ # * call(env) - the main middleware invocation method.
13
+ # This already calls on_request and on_complete, so you normally don't need to override it.
14
+ # You may need to in case you need to "wrap" the request or need more control
15
+ # (see "retry" middleware: https://github.com/lostisland/faraday/blob/main/lib/faraday/request/retry.rb#L142).
16
+ # IMPORTANT: Remember to call `@app.call(env)` or `super` to not interrupt the middleware chain!
17
+ class Middleware < Faraday::Middleware
18
+
19
+ attr_writer :tag, :log_body, :color
20
+
21
+ def initialize(env, tag, options = {})
22
+ options.reverse_merge!({log_body: false})
23
+ super(env)
24
+ self.tag = tag
25
+ self.log_body = options[:log_body]
26
+ self.color = options[:color] || :gray
27
+ end
28
+
29
+ def call(env)
30
+ req_id = env.request_headers["X-Request-ID"] = SecureRandom.uuid
31
+ tags = [@tag.send(@color).bold]
32
+ tags << req_id.send(@color) unless Rails.env.development?
33
+ Rails.logger.tagged tags do
34
+ msg = ">> #{env.method} #{env.url}".send(@color)
35
+ msg += " body: #{env.body.to_json}" if @log_body
36
+ Rails.logger.info { msg }
37
+ @app.call(env).on_complete do |env|
38
+ raise 'request and response has differnet X-Request-ID header' if req_id != env.response_headers['X-Request-ID']
39
+ Rails.logger.info { "<< #{env.status} in #{env.response_headers['X-Runtime'].to_f * 1000 } ms" }
40
+ Rails.logger.debug { "<< #{env.response.body}" }
41
+ end
42
+ end
43
+ end
44
+
45
+ # # This method will be called when the request is being prepared.
46
+ # # You can alter it as you like, accessing things like request_body, request_headers, and more.
47
+ # # Refer to Faraday::Env for a list of accessible fields:
48
+ # # https://github.com/lostisland/faraday/blob/main/lib/faraday/options/env.rb
49
+ # #
50
+ # # @param env [Faraday::Env] the environment of the request being processed
51
+ # def on_request(env)
52
+ # # Do something with the request environment...
53
+ # # This method is optional.
54
+ # end
55
+
56
+ # # This method will be called when the response is being processed.
57
+ # # You can alter it as you like, accessing things like response_body, response_headers, and more.
58
+ # # Refer to Faraday::Env for a list of accessible fields:
59
+ # # https://github.com/lostisland/faraday/blob/main/lib/faraday/options/env.rb
60
+ # #
61
+ # # @param env [Faraday::Env] the environment of the response being processed.
62
+ # def on_complete(env)
63
+ # # Do something with the response environment...
64
+ # # This method is optional.
65
+ # end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Faraday
4
+ module VerboseWsWrapper
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'verbose_ws_wrapper/middleware'
4
+ require_relative 'verbose_ws_wrapper/version'
5
+
6
+ module Faraday
7
+ # This will be your middleware main module, though the actual middleware implementation will go
8
+ # into Faraday::VerboseWsWrapper::Middleware for the correct namespacing.
9
+ module VerboseWsWrapper
10
+ # Faraday allows you to register your middleware for easier configuration.
11
+ # This step is totally optional, but it basically allows users to use a
12
+ # custom symbol (in this case, `:verbose_ws_wrapper`), to use your middleware in their connections.
13
+ # After calling this line, the following are both valid ways to set the middleware in a connection:
14
+ # * conn.use Faraday::VerboseWsWrapper::Middleware
15
+ # * conn.use :verbose_ws_wrapper
16
+ # Without this line, only the former method is valid.
17
+ # Faraday::Middleware.register_middleware(verbose_ws_wrapper: Faraday::VerboseWsWrapper::Middleware)
18
+
19
+ # Alternatively, you can register your middleware under Faraday::Request or Faraday::Response.
20
+ # This will allow to load your middleware using the `request` or `response` methods respectively.
21
+ #
22
+ # Load middleware with conn.request :verbose_ws_wrapper
23
+ Faraday::Request.register_middleware(verbose_ws_wrapper: Faraday::VerboseWsWrapper::Middleware)
24
+ #
25
+ # Load middleware with conn.response :verbose_ws_wrapper
26
+ # Faraday::Response.register_middleware(verbose_ws_wrapper: Faraday::VerboseWsWrapper::Middleware)
27
+ end
28
+ end
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: faraday-verbose_ws_wrapper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - masciugo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-11-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.10'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.0'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '13.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '13.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: simplecov
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: 0.21.0
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.21.0
89
+ - !ruby/object:Gem::Dependency
90
+ name: rubocop
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 1.31.0
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 1.31.0
103
+ - !ruby/object:Gem::Dependency
104
+ name: rubocop-packaging
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 0.5.0
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.5.0
117
+ - !ruby/object:Gem::Dependency
118
+ name: rubocop-performance
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '1.0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '1.0'
131
+ - !ruby/object:Gem::Dependency
132
+ name: rubocop-rspec
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '2.0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '2.0'
145
+ description: 'faraday middleware to make Rails logger more verbose.
146
+
147
+ '
148
+ email:
149
+ - masciugo@gmail.com
150
+ executables: []
151
+ extensions: []
152
+ extra_rdoc_files: []
153
+ files:
154
+ - CHANGELOG.md
155
+ - LICENSE.md
156
+ - README.md
157
+ - lib/faraday/verbose_ws_wrapper.rb
158
+ - lib/faraday/verbose_ws_wrapper/middleware.rb
159
+ - lib/faraday/verbose_ws_wrapper/version.rb
160
+ homepage: https://github.com/masciugo/faraday-verbose_ws_wrapper
161
+ licenses:
162
+ - MIT
163
+ metadata:
164
+ bug_tracker_uri: https://github.com/masciugo/faraday-verbose_ws_wrapper/issues
165
+ changelog_uri: https://github.com/masciugo/faraday-verbose_ws_wrapper/blob/v0.1.0/CHANGELOG.md
166
+ documentation_uri: http://www.rubydoc.info/gems/faraday-verbose_ws_wrapper/0.1.0
167
+ homepage_uri: https://github.com/masciugo/faraday-verbose_ws_wrapper
168
+ rubygems_mfa_required: 'true'
169
+ source_code_uri: https://github.com/masciugo/faraday-verbose_ws_wrapper
170
+ wiki_uri: https://github.com/masciugo/faraday-verbose_ws_wrapper/wiki
171
+ post_install_message:
172
+ rdoc_options: []
173
+ require_paths:
174
+ - lib
175
+ required_ruby_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: '2.6'
180
+ - - "<"
181
+ - !ruby/object:Gem::Version
182
+ version: '4'
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ requirements: []
189
+ rubygems_version: 3.3.11
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: faraday middleware to make Rails logger more verbose
193
+ test_files: []