shutl_resource 1.8.0 → 1.8.2

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: d4e6e89f181b62bd4c7d217a7f303f6f0a573607
4
- data.tar.gz: befdafe23b0daf80bc0d393094babfca05ded320
3
+ metadata.gz: 500c2ab1f17cb6cf8130a6add480df375ddb3820
4
+ data.tar.gz: 15799d11ac8846e9451b9ac4c1f1c265cf971137
5
5
  SHA512:
6
- metadata.gz: 120c5ca58f3a0b3caa7ddd3898f8ae5d018127dc64adee99e3411fc6ad25c3465d301447ab25f7ec0c8b88d37d3acd3791440d8b576ebd6932599128f800bd83
7
- data.tar.gz: b9c40de77edc47756c0e10f97435cfab8d530b5435426bcf72a655e7736fd9e945057b8ec5c3dfc75c185a4354c1c6f1f1d6fbcfea241d508dedbf7c29698174
6
+ metadata.gz: 98e554b684023c9a6ab7f74039d1e1d7152f4839d90272c723b2ca411ddc3f23665e53f0cca6d100d770612c6cef57f63c0e4ea7c0f791f6dc9a88a8f6754ae4
7
+ data.tar.gz: c2355f511c325103a30888fb5285af2759c199184686bcba8f873f7c0478eb681c3b3b7b11787072cc1607c257dd8e749d6683b9895493bb12785c42f9c52a05
data/.rspec CHANGED
@@ -1,4 +1,2 @@
1
1
  --color
2
- --drb
3
- --debug
4
2
  --tag ~@slow
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.1
1
+ 2.2.3
@@ -1,8 +1,6 @@
1
1
  require 'forwardable'
2
2
 
3
- module Faraday
4
- class Middleware
5
- class DefaultLogger < Faraday::Middleware
3
+ class DefaultLogger < Faraday::Middleware
6
4
  extend Forwardable
7
5
 
8
6
  def_delegators :@logger, :debug, :info, :warn, :error, :fatal
@@ -18,30 +16,30 @@ module Faraday
18
16
  def call(env)
19
17
  start_time = Time.now
20
18
  info request_info(env)
21
- debug request_debug(env)
19
+ request_debug(env)
22
20
 
23
21
  @app.call(env).on_complete do
24
22
  end_time = Time.now
25
23
  response_time = end_time - start_time
26
24
  info response_info(env, response_time)
27
- debug response_debug(env)
25
+ response_debug(env)
28
26
  end
29
27
  end
30
28
 
31
29
  private
32
30
 
33
31
  def request_info(env)
34
- " Started %s request to: %s" % [ env[:method].to_s.upcase, env[:url] ]
32
+ "Started %s request to: %s" % [ env[:method].to_s.upcase, env[:url] ]
35
33
  end
36
34
 
37
35
  def response_info(env, response_time)
38
- " Response from %s; Status: %d; Time: %.1fms" % [ env[:url], env[:status], (response_time * 1_000.0) ]
36
+ "Response from %s; Status: %d; Time: %.1fms" % [ env[:url], env[:status], (response_time * 1_000.0) ]
39
37
  end
40
38
 
41
39
  def request_debug(env)
42
40
  request_headers = obfuscate_auth env[:request_headers]
43
41
 
44
- debug_message("Request", request_headers, env[:body])
42
+ debug_request_response("Request", request_headers, env[:body])
45
43
  end
46
44
 
47
45
  def obfuscate_auth(headers)
@@ -54,25 +52,18 @@ module Faraday
54
52
  end
55
53
 
56
54
  def response_debug(env)
57
- debug_message("Response", env[:response_headers], env[:body])
55
+ debug_request_response("Response", env[:response_headers], env[:body])
58
56
  end
59
57
 
60
- def debug_message(name, headers, body)
61
- <<-MESSAGE.gsub(/^ +([^ ])/m, ' \\1')
62
- #{name} Headers:
63
- ----------------
64
- #{format_headers(headers)}
65
-
66
- #{name} Body:
67
- -------------
68
- #{body}
69
- MESSAGE
58
+ def debug_request_response(name, headers, body)
59
+ debug "#{name} headers: #{JSON.generate headers}"
60
+ debug "#{name} body: #{format_body body}"
70
61
  end
71
62
 
72
- def format_headers(headers)
73
- length = headers.map {|k,v| k.to_s.size }.max
74
- headers.map { |name, value| " #{name.to_s.ljust(length)} : #{value}" }.join("\n")
63
+ def format_body(body)
64
+ return '' unless body
65
+ JSON.generate JSON.parse Array(body).join("\n")
66
+ rescue JSON::ParserError
67
+ Array(body).join("\n").gsub /\n/, '\n'
75
68
  end
76
69
  end
77
- end
78
- end
@@ -1,5 +1,5 @@
1
1
  module Shutl
2
2
  module Resource
3
- VERSION = '1.8.0'
3
+ VERSION = '1.8.2'
4
4
  end
5
5
  end
@@ -26,8 +26,6 @@ Gem::Specification.new do |gem|
26
26
 
27
27
  gem.add_development_dependency 'rake'
28
28
  gem.add_development_dependency 'rspec', '~> 2.11.0'
29
- gem.add_development_dependency 'debugger' if $platform.to_s == 'ruby'
30
- gem.add_development_dependency 'ruby-debug' if $platform.to_s == 'java'
31
29
 
32
30
  gem.add_development_dependency 'webmock', '~> 1.8.7'
33
31
  end
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+ require 'stringio'
3
+ require 'logger'
4
+
5
+ describe DefaultLogger do
6
+
7
+ def conn(logger, logger_options={})
8
+ rubbles = ['Barney', 'Betty', 'Bam Bam']
9
+
10
+ Faraday.new do |b|
11
+ b.use DefaultLogger, logger: @logger
12
+ b.adapter :test do |stubs|
13
+ stubs.get('/hello') { [200, {'Content-Type' => 'text/html'}, 'hello'] }
14
+ stubs.post('/ohai') { [200, {'Content-Type' => 'text/html'}, 'fred'] }
15
+ stubs.get('/ohno') { [200, {'Content-Type' => 'text/html'}, 'wilma'] }
16
+ stubs.post('/ohyes') { [200, {'Content-Type' => 'text/html'}, 'pebbles'] }
17
+ stubs.get('/rubbles') { [200, {'Content-Type' => 'application/json'}, rubbles] }
18
+ end
19
+ end
20
+ end
21
+
22
+ before do
23
+ @io = StringIO.new
24
+ @logger = Logger.new(@io)
25
+ @logger.level = Logger::DEBUG
26
+
27
+ @conn = conn(@logger)
28
+ @resp = @conn.get '/hello', nil, :accept => 'text/html'
29
+ end
30
+
31
+ it "still returns output" do
32
+ expect(@resp.body).to eq 'hello'
33
+ end
34
+
35
+ it "logss method and url" do
36
+ expect(@io.string).to match 'Started GET request to:'
37
+ end
38
+
39
+ it "logss request headers" do
40
+ expect(@io.string).to match %("Accept":"text/html")
41
+ end
42
+
43
+ it "logs response headers" do
44
+ expect(@io.string).to match %("Content-Type":"text/html")
45
+ end
46
+
47
+ it "logs request body" do
48
+ app = conn(@logger, :bodies => { :request => true })
49
+ app.post '/ohyes', 'name=Tamago', :accept => 'text/html'
50
+
51
+ expect(@io.string).to match %(name=Tamago)
52
+ end
53
+
54
+ it "logs response body" do
55
+ app = conn(@logger, :bodies => { :response => true })
56
+ app.get '/ohno', :accept => 'text/html'
57
+
58
+ expect(@io.string).to match %(wilma)
59
+ end
60
+
61
+ it "logs request and response body" do
62
+ app = conn(@logger, :bodies => true)
63
+ app.post '/ohyes', 'name=Ebi', :accept => 'text/html'
64
+
65
+ expect(@io.string).to match %(name=Ebi)
66
+ expect(@io.string).to match %(pebbles)
67
+ end
68
+
69
+ it "logs response body object" do
70
+ app = conn(@logger, :bodies => true)
71
+ app.get '/rubbles', nil, :accept => 'text/html'
72
+
73
+ expect(@io.string).to match %([\"Barney\", \"Betty\", \"Bam Bam\"]\n)
74
+ end
75
+
76
+ it 'obfuscates the token in the header' do
77
+ app = conn(@logger, :bodies => true)
78
+ @conn.post '/ohai', 'name=Toro', :accept => 'text/html', :authorization => 'Bearer 1234567890'
79
+
80
+ expect(@io.string).to_not match %(1234567890)
81
+ end
82
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shutl_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Rouchy
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2015-09-11 00:00:00.000000000 Z
16
+ date: 2015-09-15 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: shutl_auth
@@ -113,20 +113,6 @@ dependencies:
113
113
  - - "~>"
114
114
  - !ruby/object:Gem::Version
115
115
  version: 2.11.0
116
- - !ruby/object:Gem::Dependency
117
- name: debugger
118
- requirement: !ruby/object:Gem::Requirement
119
- requirements:
120
- - - ">="
121
- - !ruby/object:Gem::Version
122
- version: '0'
123
- type: :development
124
- prerelease: false
125
- version_requirements: !ruby/object:Gem::Requirement
126
- requirements:
127
- - - ">="
128
- - !ruby/object:Gem::Version
129
- version: '0'
130
116
  - !ruby/object:Gem::Dependency
131
117
  name: webmock
132
118
  requirement: !ruby/object:Gem::Requirement
@@ -177,6 +163,7 @@ files:
177
163
  - shutl_resource.gemspec
178
164
  - spec/configuration_spec.rb
179
165
  - spec/configured_base_uri_spec.rb
166
+ - spec/default_logger_spec.rb
180
167
  - spec/dynamic_resource_spec.rb
181
168
  - spec/error_spec.rb
182
169
  - spec/remote_url_spec.rb
@@ -205,13 +192,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
192
  version: '0'
206
193
  requirements: []
207
194
  rubyforge_project:
208
- rubygems_version: 2.2.2
195
+ rubygems_version: 2.4.5.1
209
196
  signing_key:
210
197
  specification_version: 4
211
198
  summary: Manage Shutl Rest resource. Parse/Serialize JSON
212
199
  test_files:
213
200
  - spec/configuration_spec.rb
214
201
  - spec/configured_base_uri_spec.rb
202
+ - spec/default_logger_spec.rb
215
203
  - spec/dynamic_resource_spec.rb
216
204
  - spec/error_spec.rb
217
205
  - spec/remote_url_spec.rb