spyke 1.0.2 → 1.1.0
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/README.md +17 -0
- data/lib/spyke.rb +1 -0
- data/lib/spyke/middleware/rails_logger.rb +34 -0
- data/lib/spyke/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 454a7844a87f1ba6d9797d519a754a02b0ea6da0
|
4
|
+
data.tar.gz: 454dcbda6c25ccc881169c2c0e57bf0498add944
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
@@ -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
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
|
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
|
+
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
|