spyke 1.0.2 → 1.1.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: 351feb9aa7e6aa5486ac90bfee67db3088e1bba3
4
- data.tar.gz: dce508b409ac67d45c30746a5608d3e0911d8475
3
+ metadata.gz: 454a7844a87f1ba6d9797d519a754a02b0ea6da0
4
+ data.tar.gz: 454dcbda6c25ccc881169c2c0e57bf0498add944
5
5
  SHA512:
6
- metadata.gz: cec924b0be7293242a30fd358de54aaa9c4d8357fccdc3dd5e1ba3b408f993d4b0d20fa9f81b57ff49fb8cbac7c43620a14d7ba0b5a35a7af505ecde76ac209b
7
- data.tar.gz: 5507ca04b4f70ca3a2c5d6b624029c23409414ae14adcfbfd15e55576c6c6c670a0c59ea3817f2e2d77d693adc54ba337c17926840e9008d48e6c38c17459958
6
+ metadata.gz: b5edf38fa1f17dbf4eac1daad618622b7e0bdfb451e6871a3087f2ee8b32bad74fc9ad06bbeb606136c10da059b5f08ad54b29bc537af38f1010cdf5550809b3
7
+ data.tar.gz: 4a5f406bcb26f80e40e9cfd341af96c0e2ee334add9c3db2f067ecb6a25a327e8a4af0abc64be5595c51a606ee0d2b8adac6410639d18ba20a0198f43fbe2cb2
data/README.md CHANGED
@@ -89,6 +89,23 @@ user.posts # => GET http://api.com/posts/for_user/3
89
89
  Post.find(4) # => GET http://api.com/posts/4
90
90
  ```
91
91
 
92
+ ### Logging/Debugging
93
+
94
+ Spyke comes with Faraday middleware for Rails that will output helpful
95
+ ActiveRecord-like output to the main log as well as keep a record of
96
+ request/responses in `/log/faraday.log`.
97
+
98
+ To use it, simply add it to the stack of middleware:
99
+
100
+ ```ruby
101
+ Spyke::Config.connection = Faraday.new(url: 'http://api.com') do |c|
102
+ c.request :json
103
+ c.use JSONParser
104
+ c.use Spyke::Middleware::RailsLogger if Rails.env.development?
105
+ c.use Faraday.default_adapter
106
+ end
107
+ ```
108
+
92
109
  ## Contributing
93
110
 
94
111
  If possible please take a look at the tests marked "wishlisted"!
data/lib/spyke.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'active_support/core_ext'
2
2
  require 'spyke/base'
3
+ require 'spyke/middleware/rails_logger' if defined?(Rails)
3
4
  require 'spyke/version'
4
5
 
5
6
  module Spyke
@@ -0,0 +1,34 @@
1
+ module Spyke
2
+ module Middleware
3
+ class RailsLogger < Faraday::Middleware
4
+ CLEAR = "\e[0m"
5
+ BOLD = "\e[1m"
6
+ MAGENTA = "\e[35m"
7
+
8
+ def call(env)
9
+ logger.formatter = -> (severity, datetime, progname, msg) { msg }
10
+
11
+ logger.debug "\n\n\n\n#{env[:method].upcase} #{env[:url]}"
12
+ logger.debug "\n Headers: #{env[:request_headers]}"
13
+ logger.debug "\n Body: #{env[:body]}" if env[:body]
14
+
15
+ @app.call(env).on_complete do
16
+ Rails.logger.debug " #{BOLD}#{MAGENTA}#{env[:method].upcase} #{env[:url]} [#{env[:status]}]#{CLEAR}"
17
+ logger.debug "\n\nCompleted #{env[:status]}"
18
+ logger.debug "\n Headers: #{env[:response_headers]}"
19
+ logger.debug "\n Body: #{truncate_binary_values env[:body]}" if env[:body]
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def logger
26
+ @logger ||= Logger.new Rails.root.join('log', 'faraday.log')
27
+ end
28
+
29
+ def truncate_binary_values(body)
30
+ body.gsub(/(data:)([^"]+)/, 'data:...')
31
+ end
32
+ end
33
+ end
34
+ end
data/lib/spyke/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Spyke
2
- VERSION = '1.0.2'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spyke
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Balvig
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-25 00:00:00.000000000 Z
11
+ date: 2014-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -260,6 +260,7 @@ files:
260
260
  - lib/spyke/config.rb
261
261
  - lib/spyke/exceptions.rb
262
262
  - lib/spyke/http.rb
263
+ - lib/spyke/middleware/rails_logger.rb
263
264
  - lib/spyke/orm.rb
264
265
  - lib/spyke/path.rb
265
266
  - lib/spyke/relation.rb