problem_details 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/README.md +60 -3
- data/Rakefile +52 -5
- data/VERSION +1 -0
- data/lib/problem_details.rb +1 -1
- data/lib/problem_details/version.rb +1 -1
- data/problem_details.gemspec +11 -5
- metadata +4 -8
- data/.gitignore +0 -12
- data/.rspec +0 -3
- data/.travis.yml +0 -6
- data/Gemfile +0 -7
- data/bin/console +0 -14
- data/bin/setup +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aaa20fce362b636679a35cc9090c974bf3e36924
|
4
|
+
data.tar.gz: 5ac0e4fb420f456e79f4a7bc1d6477a47fd6d3f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 979bec626f82c894b774b16902c7ede02caa1074aec7fd189cf24351630730fd67bffbd905682c10c8d1d52946732d5ef87f4114351235e92c6c948baf9b20b3
|
7
|
+
data.tar.gz: 9a41b0fef22b7ce25316e8ec1374c09ee494b3ffd68ee5768733735b0d58cb0000b13068fef2dc060e1f000e77c9b9172dfb99ac60118dc06463898eb0501dfe
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
## 0.2.0 / 2018-03-20
|
2
|
+
|
3
|
+
### Enhancements:
|
4
|
+
* Introduce a new gem, `sinatra-problem_details`, the Sinatra problem detail extention.
|
5
|
+
|
6
|
+
## 0.1.0 / 2018-03-26
|
7
|
+
|
8
|
+
* First release
|
9
|
+
* Initial implementation of `problem_details`
|
10
|
+
* Rails renderer feature by `problem_details-rails`
|
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
# ProblemDetails [![Build Status](https://travis-ci.org/nikushi/problem_details.svg?branch=master)](https://travis-ci.org/nikushi/problem_details)
|
1
|
+
# ProblemDetails [![Build Status](https://travis-ci.org/nikushi/problem_details.svg?branch=master)](https://travis-ci.org/nikushi/problem_details) [![Gem Version](https://badge.fury.io/rb/problem_details.svg)](https://badge.fury.io/rb/problem_details)
|
2
2
|
|
3
3
|
ProblemDetails is an implementation of [RFC7807 Problem Details for HTTP APIs](https://tools.ietf.org/html/rfc7807).
|
4
4
|
|
5
5
|
The RFC defines a "problem detail" as a way to inform errors to clients as machine readable form in a HTTP response
|
6
6
|
to avoid the need to define new error response formats for HTTP APIs.
|
7
7
|
|
8
|
-
This library also works with Rails, by the `problem` renderer that helps to respond with the problem detail form.
|
8
|
+
This library also works with Rails and Sinatra, by the `problem` renderer that helps to respond with the problem detail form.
|
9
9
|
|
10
10
|
Currently only JSON serialization is supported.
|
11
11
|
|
@@ -28,6 +28,12 @@ Or if you use with Rails, add below line instead.
|
|
28
28
|
gem 'problem_details-rails'
|
29
29
|
```
|
30
30
|
|
31
|
+
With Sinatra, add below line instead.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
gem 'sinatra-problem_details'
|
35
|
+
```
|
36
|
+
|
31
37
|
And then execute:
|
32
38
|
|
33
39
|
$ bundle
|
@@ -40,6 +46,9 @@ And then execute:
|
|
40
46
|
require 'problem_details'
|
41
47
|
|
42
48
|
ProblemDetails::Document.new(status: 404).to_json
|
49
|
+
|
50
|
+
# Or status code symbol can be specified as well.
|
51
|
+
ProblemDetails::Document.new(status: :not_found).to_json
|
43
52
|
```
|
44
53
|
|
45
54
|
will produce:
|
@@ -103,7 +112,7 @@ will produce(note that `balance` and `accounts` are extention members):
|
|
103
112
|
|
104
113
|
### With Rails
|
105
114
|
|
106
|
-
Once `
|
115
|
+
Once `problem_details-rails` gem is installed into a Rails system, a problem can be rendered with the problem detail form with `Content-Type: application/problem+json`.
|
107
116
|
|
108
117
|
For example, respond with validation error messages:
|
109
118
|
|
@@ -139,6 +148,54 @@ Content-Type: application/problem+json; charset=utf-8
|
|
139
148
|
}
|
140
149
|
```
|
141
150
|
|
151
|
+
### With Sinatra
|
152
|
+
|
153
|
+
Install `sinatra-problems_details` into a sinatra app, a problem is be rendered as well with `Content-Type: application/problem+json`.
|
154
|
+
|
155
|
+
#### Classic Application
|
156
|
+
|
157
|
+
```ruby
|
158
|
+
require 'sinatra'
|
159
|
+
require 'sinatra-problem_details'
|
160
|
+
|
161
|
+
get '/' do
|
162
|
+
status 400
|
163
|
+
problem foo: 'bar'
|
164
|
+
end
|
165
|
+
```
|
166
|
+
|
167
|
+
#### Modular Application
|
168
|
+
|
169
|
+
```ruby
|
170
|
+
require 'sinatra/base'
|
171
|
+
require 'sinatra-problem_details'
|
172
|
+
|
173
|
+
class MyApp < Sinatra::Base
|
174
|
+
register Sinatra::ProblemDetails
|
175
|
+
|
176
|
+
get '/' do
|
177
|
+
status 400
|
178
|
+
problem foo: 'bar'
|
179
|
+
end
|
180
|
+
end
|
181
|
+
```
|
182
|
+
|
183
|
+
#### Response
|
184
|
+
|
185
|
+
The sinatra apps defined in the previous sections will render:
|
186
|
+
|
187
|
+
```
|
188
|
+
HTTP/1.1 400 Bad Request
|
189
|
+
Content-Type: application/problem+json
|
190
|
+
|
191
|
+
{
|
192
|
+
"type": "about:blank",
|
193
|
+
"title": "Bad Request",
|
194
|
+
"status": 400,
|
195
|
+
"foo": "bar"
|
196
|
+
}
|
197
|
+
}
|
198
|
+
```
|
142
199
|
|
143
200
|
## Development
|
144
201
|
|
data/Rakefile
CHANGED
@@ -6,6 +6,23 @@ require 'rspec/core/rake_task'
|
|
6
6
|
# For multiple gems
|
7
7
|
# ref https://github.com/bkeepers/dotenv/blob/master/Rakefile
|
8
8
|
|
9
|
+
# === helpers ===
|
10
|
+
def source_version
|
11
|
+
@source_version ||= File.read(File.expand_path("../VERSION", __FILE__)).strip
|
12
|
+
end
|
13
|
+
|
14
|
+
# == release ====
|
15
|
+
desc "Commits the version"
|
16
|
+
task :commit_version do
|
17
|
+
sh <<-SH
|
18
|
+
gsed -i "s/.*VERSION.*/ VERSION = '#{source_version}'/" lib/problem_details/version.rb
|
19
|
+
gsed -i "s/.*VERSION.*/ VERSION = '#{source_version}'/" problem_details-rails/lib/problem_details/rails/version.rb
|
20
|
+
gsed -i "s/.*VERSION.*/ VERSION = '#{source_version}'/" sinatra-problem_details/lib/sinatra/problem_details/version.rb
|
21
|
+
SH
|
22
|
+
|
23
|
+
sh "git commit --allow-empty -a -m '#{source_version} release'"
|
24
|
+
end
|
25
|
+
|
9
26
|
namespace 'problem_details' do
|
10
27
|
Bundler::GemHelper.install_tasks name: 'problem_details'
|
11
28
|
end
|
@@ -17,17 +34,47 @@ namespace 'problem_details-rails' do
|
|
17
34
|
def tag_version; end # noop
|
18
35
|
end
|
19
36
|
|
20
|
-
ProblemDetailsRailsGemHelper.install_tasks name: 'problem_details-rails'
|
37
|
+
ProblemDetailsRailsGemHelper.install_tasks dir: File.join(__dir__, 'problem_details-rails'), name: 'problem_details-rails'
|
38
|
+
end
|
39
|
+
|
40
|
+
namespace 'sinatra-problem_details' do
|
41
|
+
class SinatraProblemDetailsGemHelper < Bundler::GemHelper
|
42
|
+
def guard_already_tagged; end # noop
|
43
|
+
|
44
|
+
def tag_version; end # noop
|
45
|
+
end
|
46
|
+
|
47
|
+
SinatraProblemDetailsGemHelper.install_tasks dir: File.join(__dir__, 'sinatra-problem_details'), name: 'sinatra-problem_details'
|
21
48
|
end
|
22
49
|
|
23
50
|
desc 'build gem'
|
24
|
-
task build: ['problem_details:build', 'problem_details-rails:build']
|
51
|
+
task build: ['problem_details:build', 'problem_details-rails:build', 'sinatra-problem_details:build']
|
25
52
|
|
26
53
|
desc 'build and install'
|
27
|
-
task install: ['problem_details:install', 'problem_details-rails:install']
|
54
|
+
task install: ['problem_details:install', 'problem_details-rails:install', 'sinatra-problem_details:build']
|
28
55
|
|
29
56
|
desc 'release'
|
30
|
-
task release: ['problem_details:release', 'problem_details-rails:release']
|
57
|
+
task release: ['problem_details:release', 'problem_details-rails:release', 'sinatra-problem_details:build']
|
31
58
|
|
32
59
|
RSpec::Core::RakeTask.new(:spec)
|
33
|
-
task default: :
|
60
|
+
task default: 'spec:all'
|
61
|
+
|
62
|
+
namespace :spec do
|
63
|
+
dirs = %w(
|
64
|
+
.
|
65
|
+
problem_details-rails
|
66
|
+
sinatra-problem_details
|
67
|
+
)
|
68
|
+
|
69
|
+
desc "Run all specs"
|
70
|
+
task :all do
|
71
|
+
dirs.each do |d|
|
72
|
+
Dir.chdir(d) do
|
73
|
+
Bundler.with_clean_env do
|
74
|
+
sh 'bundle --quiet'
|
75
|
+
sh 'bundle exec rake spec'
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
data/lib/problem_details.rb
CHANGED
data/problem_details.gemspec
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
version = File.read(File.expand_path('VERSION', __dir__)).strip
|
4
|
+
|
3
5
|
lib = File.expand_path('lib', __dir__)
|
4
6
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
require 'problem_details/version'
|
6
7
|
|
7
8
|
Gem::Specification.new do |spec|
|
8
9
|
spec.name = 'problem_details'
|
9
|
-
spec.version =
|
10
|
+
spec.version = version
|
10
11
|
spec.authors = ['Nobuhiro Nikushi']
|
11
12
|
spec.email = ['deneb.ge@gmail.com']
|
12
13
|
|
@@ -15,9 +16,14 @@ Gem::Specification.new do |spec|
|
|
15
16
|
spec.homepage = 'https://github.com/nikushi/problem_details'
|
16
17
|
spec.license = 'MIT'
|
17
18
|
|
18
|
-
spec.files =
|
19
|
-
|
20
|
-
|
19
|
+
spec.files = Dir['lib/**/*.rb'] + %w[
|
20
|
+
CHANGELOG.md
|
21
|
+
LICENSE.txt
|
22
|
+
README.md
|
23
|
+
Rakefile
|
24
|
+
problem_details.gemspec
|
25
|
+
VERSION
|
26
|
+
]
|
21
27
|
spec.require_paths = ['lib']
|
22
28
|
|
23
29
|
spec.add_runtime_dependency 'rack'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: problem_details
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nobuhiro Nikushi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -73,15 +73,11 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
-
-
|
77
|
-
- ".rspec"
|
78
|
-
- ".travis.yml"
|
79
|
-
- Gemfile
|
76
|
+
- CHANGELOG.md
|
80
77
|
- LICENSE.txt
|
81
78
|
- README.md
|
82
79
|
- Rakefile
|
83
|
-
-
|
84
|
-
- bin/setup
|
80
|
+
- VERSION
|
85
81
|
- lib/problem_details.rb
|
86
82
|
- lib/problem_details/document.rb
|
87
83
|
- lib/problem_details/version.rb
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require 'bundler/setup'
|
4
|
-
require 'problem_details'
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require 'irb'
|
14
|
-
IRB.start(__FILE__)
|