faraday-sunset 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +57 -0
- data/lib/faraday-sunset.rb +1 -0
- data/lib/faraday/sunset.rb +64 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ca7a69dd039247efb627b578875fcc563caa08b5
|
4
|
+
data.tar.gz: e9bf16a1868e2ad2cf37716a30e708559f9abbb8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4619ad82d7c72aeee7acb90c8c8ab1cad4919d234247f0dce99bf4a52075ce24f29aec26f2ac85e971cb9656760ea010296880c47c13d0d7e52c50118e6cea5a
|
7
|
+
data.tar.gz: 2644f3e42f0ba14b4193ae9e82d01b2d35f0a69348b3b654e77874e6f685b49430cea63e394551873c13488cc4a3657a22f89db10b6f21cb4fe5a29a33cf47f4
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2017 WeWork Projects
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# Faraday Sunset
|
2
|
+
|
3
|
+
[![Build Status][travis-image]][travis-url]
|
4
|
+
[![Coverage Status][coveralls-image]][coveralls-url]
|
5
|
+
[![MIT License][license-image]][license-url]
|
6
|
+
|
7
|
+
Watch out for Sunset headers on HTTP responses, as they signify the deprecation (and eventual removal) of an endpoint.
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Add gem to Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'faraday-sunset'
|
15
|
+
```
|
16
|
+
|
17
|
+
Enabling Sunset detection is as simple as referencing the middleware in your Faraday connection block:
|
18
|
+
|
19
|
+
``` ruby
|
20
|
+
connection = Faraday::Connection.new(url: '...') do |conn|
|
21
|
+
conn.response :sunset, active_support: true
|
22
|
+
# or
|
23
|
+
conn.response :sunset, logger: Rails.logger
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
You can [configure `ActiveSupport::Deprecation`](TODO LINK TO DOCS) to warn in a few different ways, or pass in any object that acts a bit like a Rack logger, Rails logger, or anything with a `warn` method that takes a string.
|
28
|
+
|
29
|
+
## Requirements
|
30
|
+
|
31
|
+
- **Ruby:** v2.2 - v2.4
|
32
|
+
- **Faraday:** v0.8 - v0.13
|
33
|
+
|
34
|
+
## TODO
|
35
|
+
|
36
|
+
- [ ] Surface `Link` with rel=sunset as per Sunset RFC draft 03
|
37
|
+
|
38
|
+
## Testing
|
39
|
+
|
40
|
+
To run tests and modify locally, you'll want to `bundle install` in this directory.
|
41
|
+
|
42
|
+
```
|
43
|
+
bundle exec rspec
|
44
|
+
```
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at [philsturgeon/faraday-sunset](https://github.com/philsturgeon/faraday-sunset). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
49
|
+
|
50
|
+
[coveralls-image]:https://coveralls.io/repos/github/philsturgeon/faraday-sunset/badge.svg?branch=master
|
51
|
+
[coveralls-url]:https://coveralls.io/github/philsturgeon/faraday-sunset?branch=master
|
52
|
+
|
53
|
+
[travis-url]:https://travis-ci.org/philsturgeon/faraday-sunset
|
54
|
+
[travis-image]: https://travis-ci.org/philsturgeon/faraday-sunset.svg?branch=master
|
55
|
+
|
56
|
+
[license-url]: LICENSE
|
57
|
+
[license-image]: http://img.shields.io/badge/license-MIT-000000.svg?style=flat-square
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'faraday/sunset'
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Faraday
|
4
|
+
class Sunset < Faraday::Middleware
|
5
|
+
class NoOutputForWarning < StandardError; end
|
6
|
+
|
7
|
+
# Initialize the middleware
|
8
|
+
#
|
9
|
+
# @param [Type] app describe app
|
10
|
+
# @param [Hash] options = {}
|
11
|
+
# @return void
|
12
|
+
def initialize(app, active_support: nil, logger: nil)
|
13
|
+
super(app)
|
14
|
+
@active_support = active_support
|
15
|
+
@logger = logger
|
16
|
+
end
|
17
|
+
|
18
|
+
# @param [Faraday::Env] no idea what this does
|
19
|
+
# @return [Faraday::Response] response from the middleware
|
20
|
+
def call(env)
|
21
|
+
@app.call(env).on_complete do |response_env|
|
22
|
+
datetime = sunset_header(response_env.response_headers)
|
23
|
+
report_deprecated_usage(env, datetime) unless datetime.nil?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
# Check to see if there is a Sunset header, which contains deprecation date
|
30
|
+
#
|
31
|
+
# @param [Faraday::Response] response object with headers and whatnot
|
32
|
+
# @return [DateTime|nil] date time object of the expected deprecation date
|
33
|
+
def sunset_header(headers)
|
34
|
+
return if headers[:sunset].nil?
|
35
|
+
DateTime.parse(headers[:sunset])
|
36
|
+
end
|
37
|
+
|
38
|
+
def report_deprecated_usage(env, datetime)
|
39
|
+
if datetime > DateTime.now
|
40
|
+
warning = "Endpoint #{env.url} is deprecated for removal on #{datetime.iso8601}"
|
41
|
+
else
|
42
|
+
warning = "Endpoint #{env.url} was deprecated for removal on #{datetime.iso8601} and could be removed AT ANY TIME"
|
43
|
+
end
|
44
|
+
send_warning!(warning)
|
45
|
+
end
|
46
|
+
|
47
|
+
def send_warning!(warning)
|
48
|
+
warned = false
|
49
|
+
if @active_support
|
50
|
+
ActiveSupport::Deprecation.warn(warning)
|
51
|
+
warned = true
|
52
|
+
end
|
53
|
+
if @logger && @logger.respond_to?(:warn)
|
54
|
+
@logger.warn(warning)
|
55
|
+
warned = true
|
56
|
+
end
|
57
|
+
unless warned
|
58
|
+
raise NoOutputForWarning, "Pass active_support: true, or logger: ::Logger.new when registering middleware"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
Faraday::Response.register_middleware sunset: Faraday::Sunset
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: faraday-sunset
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Phil Sturgeon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-05 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.9.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0.14'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.9.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.14'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: appraisal
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: activesupport
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: coveralls
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0.7'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0.7'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: bundler
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '1.14'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '1.14'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rspec
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '3.5'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '3.5'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: simplecov
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0.15'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - "~>"
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0.15'
|
117
|
+
description: Faraday middleware that sniffs responses for Sunset headers
|
118
|
+
email:
|
119
|
+
- me@philsturgeon.uk
|
120
|
+
executables: []
|
121
|
+
extensions: []
|
122
|
+
extra_rdoc_files: []
|
123
|
+
files:
|
124
|
+
- LICENSE
|
125
|
+
- README.md
|
126
|
+
- lib/faraday-sunset.rb
|
127
|
+
- lib/faraday/sunset.rb
|
128
|
+
homepage: https://github.com/philsturgeon/faraday-sunset
|
129
|
+
licenses:
|
130
|
+
- MIT
|
131
|
+
metadata: {}
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
require_paths:
|
135
|
+
- lib
|
136
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: 2.2.0
|
141
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
requirements: []
|
147
|
+
rubyforge_project:
|
148
|
+
rubygems_version: 2.6.8
|
149
|
+
signing_key:
|
150
|
+
specification_version: 4
|
151
|
+
summary: Automatically detect deprecated HTTP endpoints
|
152
|
+
test_files: []
|