api_client 0.5.15 → 0.5.16
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/CHANGELOG.md +4 -0
- data/README.md +11 -0
- data/lib/api_client/connection/middlewares/request/logger.rb +41 -7
- data/lib/api_client/version.rb +1 -1
- data/spec/api_client/base_spec.rb +1 -1
- data/spec/api_client/connection/request/logger_spec.rb +4 -5
- metadata +3 -6
- data/spec/support/fake_logger.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37901cb1987dc20c32b8853eedfabab968bf3b0e
|
4
|
+
data.tar.gz: fd064629bf64b68239f8957e3bbfa44eb2fde456
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af89fc9e078b61a8a368e9ef777c5373fff8740e47cd67e40b1fb4a6a0724a1b6e581cf61df0cd14d8d2262be8bb405310fe31940aeb1974e1350e81f9154d8d
|
7
|
+
data.tar.gz: 13154f7651b172e8a647488583d89371873a64322c8ebc3bb55bc4c3fbdd070bab169982c424371ae288f058e5822f809dd5da50e47880a36be273cec8a0239d
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -143,6 +143,17 @@ ApiClient::Base.
|
|
143
143
|
get('/stuff.json') # => returns a parsed Array object
|
144
144
|
```
|
145
145
|
|
146
|
+
## Logging
|
147
|
+
|
148
|
+
To log requests set the `ApiClient.logger`. To log request payloads and headers set level to `Logger::DEBUG`
|
149
|
+
|
150
|
+
```ruby
|
151
|
+
require 'logger'
|
152
|
+
ApiClient.logger = Logger.new('api_client.log')
|
153
|
+
ApiClient.logger.level = Logger::INFO
|
154
|
+
|
155
|
+
```
|
156
|
+
|
146
157
|
Copyright
|
147
158
|
---------
|
148
159
|
|
@@ -1,17 +1,51 @@
|
|
1
1
|
require "logger"
|
2
|
-
class ApiClient::Connection::Middlewares::Request::Logger < Faraday::Middleware
|
3
2
|
|
3
|
+
class ApiClient::Connection::Middlewares::Request::Logger < Faraday::Middleware
|
4
4
|
def call(env)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
debug_lines = []
|
6
|
+
should_log_details = @logger.level <= ::Logger::DEBUG
|
7
|
+
|
8
|
+
gather_request_debug_lines(env, debug_lines) if should_log_details
|
9
|
+
|
10
|
+
start = current_stamp_millisec
|
11
|
+
response = @app.call(env)
|
12
|
+
taken_sec = (current_stamp_millisec - start) / 1000.0
|
13
|
+
|
14
|
+
gather_response_debug_lines(response, taken_sec, debug_lines) if response && should_log_details
|
15
|
+
|
16
|
+
if should_log_details
|
17
|
+
@logger.debug { debug_lines.join("\n") }
|
18
|
+
else
|
19
|
+
@logger.info { "#{env[:method].to_s.upcase} #{env[:url]}: #{"%.4f" % taken_sec} seconds" }
|
20
|
+
end
|
21
|
+
|
22
|
+
response
|
10
23
|
end
|
11
24
|
|
12
25
|
def initialize(app, logger = nil)
|
13
26
|
@logger = logger || ::Logger.new(STDOUT)
|
14
|
-
@app
|
27
|
+
@app = app
|
15
28
|
end
|
16
29
|
|
30
|
+
private
|
31
|
+
|
32
|
+
def gather_request_debug_lines(env, debug_lines)
|
33
|
+
debug_lines << "> #{env[:method].to_s.upcase} #{env[:url]}"
|
34
|
+
env[:request_headers].each { |k, v| debug_lines << "> #{k}: #{v}" }
|
35
|
+
debug_lines << "> "
|
36
|
+
debug_lines << "> #{env[:body]}\n> " if env[:body] && env[:body] != ""
|
37
|
+
debug_lines
|
38
|
+
end
|
39
|
+
|
40
|
+
def gather_response_debug_lines(response, taken_sec, debug_lines)
|
41
|
+
debug_lines << "< responded in #{"%.4f" % taken_sec} seconds with HTTP #{response.status}"
|
42
|
+
response.headers.each { |k, v| debug_lines << "< #{k}: #{v}" }
|
43
|
+
debug_lines << "< "
|
44
|
+
debug_lines << "< #{response.body}\n> " if response.body && response.body != ""
|
45
|
+
debug_lines
|
46
|
+
end
|
47
|
+
|
48
|
+
def current_stamp_millisec
|
49
|
+
Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
|
50
|
+
end
|
17
51
|
end
|
data/lib/api_client/version.rb
CHANGED
@@ -46,7 +46,7 @@ describe ApiClient::Base do
|
|
46
46
|
|
47
47
|
it "inspects subobjects properly" do
|
48
48
|
subject.update(:id => 1, :sub => [1,2])
|
49
|
-
subject.inspect.should == '#<ApiClient::Base id: 1, sub: [1, 2]
|
49
|
+
subject.inspect.should == '#<ApiClient::Base id: 1, sub: #<Hashie::Array [1, 2]>>'
|
50
50
|
end
|
51
51
|
|
52
52
|
it "makes sure id is the first key" do
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe ApiClient::Connection::Middlewares::Request::Logger do
|
4
|
-
|
5
4
|
it "adds a oauth header to the request" do
|
6
|
-
app
|
7
|
-
|
5
|
+
app = double
|
6
|
+
io = StringIO.new
|
7
|
+
logger = Logger.new(io)
|
8
8
|
instance = ApiClient::Connection::Middlewares::Request::Logger.new(app, logger)
|
9
9
|
env = {
|
10
10
|
:url => "http://api.twitter.com",
|
@@ -13,7 +13,6 @@ describe ApiClient::Connection::Middlewares::Request::Logger do
|
|
13
13
|
}
|
14
14
|
app.should_receive(:call).with(env)
|
15
15
|
instance.call(env)
|
16
|
-
|
16
|
+
io.string.should match("GET http://api.twitter.com")
|
17
17
|
end
|
18
|
-
|
19
18
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcin Bunsch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -145,7 +145,6 @@ files:
|
|
145
145
|
- spec/api_client/scope_spec.rb
|
146
146
|
- spec/api_client/utils_spec.rb
|
147
147
|
- spec/spec_helper.rb
|
148
|
-
- spec/support/fake_logger.rb
|
149
148
|
- spec/support/matchers.rb
|
150
149
|
homepage: https://github.com/futuresimple/api_client
|
151
150
|
licenses: []
|
@@ -166,7 +165,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
165
|
version: '0'
|
167
166
|
requirements: []
|
168
167
|
rubyforge_project: api_client
|
169
|
-
rubygems_version: 2.6.
|
168
|
+
rubygems_version: 2.6.13
|
170
169
|
signing_key:
|
171
170
|
specification_version: 3
|
172
171
|
summary: API client builder
|
@@ -191,6 +190,4 @@ test_files:
|
|
191
190
|
- spec/api_client/scope_spec.rb
|
192
191
|
- spec/api_client/utils_spec.rb
|
193
192
|
- spec/spec_helper.rb
|
194
|
-
- spec/support/fake_logger.rb
|
195
193
|
- spec/support/matchers.rb
|
196
|
-
has_rdoc:
|