faraday-log-subscriber 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +13 -0
- data/README.md +36 -0
- data/lib/faraday-log-subscriber.rb +2 -0
- data/lib/faraday/controller_runtime.rb +24 -0
- data/lib/faraday/log_subscriber.rb +57 -0
- metadata +146 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9d7e5460b895f155fd53e7470064ec0d1d45a27c
|
4
|
+
data.tar.gz: c2bceb0c8a152add6ddb34c8a96ef7739d3c4037
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 48875b2b7792c1234662c9e82414421e12ce2f97dc3d55c37a099e408448567acb59d1dac573d7cc6497ff3ba0bdc3d3076f360f98c60586a2c378389ae4eb11
|
7
|
+
data.tar.gz: 39e36421da6a5f6b514b070677cdb81fca8470404d657350d3b570ee8455d19de99910137996a4326c07ae8da93d0d96b008b747d88b0710897fe1efa9b17fe6
|
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2015 Plataformatec.
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# Faraday::Log::Subscriber
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/faraday/log/subscriber`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'faraday-log-subscriber'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install faraday-log-subscriber
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/faraday-log-subscriber.
|
36
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Faraday
|
2
|
+
module ControllerRuntime
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
protected
|
6
|
+
|
7
|
+
def append_info_to_payload(payload)
|
8
|
+
super
|
9
|
+
payload[:faraday_runtime] = Faraday::LogSubscriber.runtime
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def log_process_action(payload)
|
14
|
+
messages, runtime = super, payload[:faraday_runtime]
|
15
|
+
messages << ('Faraday: %.1fms' % runtime.to_f) if runtime
|
16
|
+
messages
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
ActiveSupport.on_load(:action_controller) do
|
23
|
+
include Faraday::ControllerRuntime
|
24
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Faraday
|
2
|
+
class LogSubscriber < ActiveSupport::LogSubscriber
|
3
|
+
HTTP_METHOD_COLORS = Hash.new(MAGENTA)
|
4
|
+
|
5
|
+
HTTP_METHOD_COLORS['POST'.freeze] = GREEN
|
6
|
+
HTTP_METHOD_COLORS['GET'.freeze] = BLUE
|
7
|
+
HTTP_METHOD_COLORS['PUT'.freeze] = YELLOW
|
8
|
+
HTTP_METHOD_COLORS['DELETE'.freeze] = RED
|
9
|
+
|
10
|
+
def self.runtime=(value)
|
11
|
+
Thread.current['faraday_runtime'] = value
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.runtime
|
15
|
+
Thread.current['faraday_runtime'] ||= 0
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.reset_runtime
|
19
|
+
rt, self.runtime = runtime, 0
|
20
|
+
rt
|
21
|
+
end
|
22
|
+
|
23
|
+
def http_cache(event)
|
24
|
+
payload = event.payload
|
25
|
+
|
26
|
+
status = payload[:cache_status]
|
27
|
+
name = "Faraday HTTP Cache [#{status}]"
|
28
|
+
request = payload[:env][:url]
|
29
|
+
|
30
|
+
name = color(name, MAGENTA, true)
|
31
|
+
request = color(request, nil, false)
|
32
|
+
|
33
|
+
info " #{name} #{request}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def request(event)
|
37
|
+
self.class.runtime += event.duration
|
38
|
+
|
39
|
+
env = event.payload
|
40
|
+
method = env[:method].to_s.upcase
|
41
|
+
status = env[:status]
|
42
|
+
name = format('%s %s [%s] (%.1fms)', 'Faraday', method, status, event.duration)
|
43
|
+
body = env.body
|
44
|
+
request = env[:url]
|
45
|
+
|
46
|
+
name = color(name, nil, true)
|
47
|
+
request = color(request, HTTP_METHOD_COLORS[method], true)
|
48
|
+
|
49
|
+
info " #{name} #{request}"
|
50
|
+
if !env.success? && body.present?
|
51
|
+
info " #{name} #{body}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
attach_to :faraday
|
56
|
+
end
|
57
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: faraday-log-subscriber
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lucas Mazza
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-14 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: '0.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday_middleware
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.9'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.0.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.10'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.10'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest-utils
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: A Log Subscriber for Faraday clients
|
112
|
+
email:
|
113
|
+
- opensource@plataformatec.com.br
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- LICENSE
|
119
|
+
- README.md
|
120
|
+
- lib/faraday-log-subscriber.rb
|
121
|
+
- lib/faraday/controller_runtime.rb
|
122
|
+
- lib/faraday/log_subscriber.rb
|
123
|
+
homepage: https://github.com/plataformatec/faraday-log-subscriber
|
124
|
+
licenses: []
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.4.5
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: A Log Subscriber for Faraday clients
|
146
|
+
test_files: []
|