eipiai 0.7.0 → 0.8.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 +27 -0
- data/Rakefile +7 -13
- data/TODO.md +13 -0
- data/eipiai.gemspec +2 -1
- data/features/resources/api.feature +1 -0
- data/features/resources/collection.feature +1 -0
- data/features/resources/health.feature +17 -0
- data/features/resources/singular.feature +1 -0
- data/features/step_definitions/webmachine_steps.rb +1 -1
- data/lib/eipiai.rb +3 -3
- data/lib/eipiai/representers.rb +7 -0
- data/lib/eipiai/{roar/representers → representers}/api.rb +1 -1
- data/lib/eipiai/{roar/representers → representers}/base.rb +0 -0
- data/lib/eipiai/{roar/ext → representers/ext/roar}/hal.rb +0 -0
- data/lib/eipiai/resources.rb +14 -0
- data/lib/eipiai/{webmachine/resources → resources}/api.rb +16 -2
- data/lib/eipiai/{webmachine/resources → resources}/base.rb +30 -2
- data/lib/eipiai/{webmachine/resources → resources}/collection.rb +1 -1
- data/lib/eipiai/{webmachine/resources → resources}/concerns/objectifiable.rb +0 -0
- data/lib/eipiai/{webmachine/resources → resources}/concerns/representable.rb +0 -0
- data/lib/eipiai/{webmachine/ext → resources/ext/webmachine}/decision.rb +0 -0
- data/lib/eipiai/{webmachine/ext → resources/ext/webmachine}/request.rb +0 -0
- data/lib/eipiai/{webmachine/resources → resources}/health.rb +5 -1
- data/lib/eipiai/{webmachine/resources → resources}/singular.rb +1 -1
- data/lib/eipiai/validators.rb +5 -0
- data/lib/eipiai/{validation/validators → validators}/base.rb +0 -0
- data/lib/eipiai/{validation → validators}/concerns/formatted_errors.rb +0 -0
- data/lib/eipiai/{validation/validators → validators}/sequel.rb +1 -1
- data/lib/eipiai/version.rb +1 -1
- data/script/test +3 -1
- metadata +38 -23
- data/lib/eipiai/roar.rb +0 -7
- data/lib/eipiai/validation.rb +0 -5
- data/lib/eipiai/webmachine.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3caaef63d30433d05c9c5dff0b84ca61f641f1b8
|
4
|
+
data.tar.gz: 274f803c8f29821db1379cfeb87b3ad78642d828
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb59e4936e0cfeb9c76e6e86aba56122866a729641c780e08dc5dc6599937fc3dafc24ff02a3071fdbdd869e84330217915b412535b1fa84288c49f2c18f6a67
|
7
|
+
data.tar.gz: 4e0b204b1adc63678bbd9c2a854f25d3a6f6bcf0c39936486ca722e2e6e8d2da20554a46d3a59fb63b9ed2e026811cfc8ebd2648911a73c89a5012e04ff5952e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,32 @@
|
|
1
1
|
# CHANGELOG
|
2
2
|
|
3
|
+
## [unreleased](https://github.com/blendle/eipiai/tree/unreleased) (2016-05-04)
|
4
|
+
[Full Changelog](https://github.com/blendle/eipiai/compare/v0.7.0...unreleased)
|
5
|
+
|
6
|
+
**Closed issues:**
|
7
|
+
|
8
|
+
- make HealthCheck a singleton [\#19](https://github.com/blendle/eipiai/issues/19)
|
9
|
+
|
10
|
+
## [v0.7.0](https://github.com/blendle/eipiai/tree/v0.7.0) (2016-05-03)
|
11
|
+
[Full Changelog](https://github.com/blendle/eipiai/compare/v0.6.0...v0.7.0)
|
12
|
+
|
13
|
+
**Closed issues:**
|
14
|
+
|
15
|
+
- api.json should be opt-in, not out-out [\#13](https://github.com/blendle/eipiai/issues/13)
|
16
|
+
- Rewrite auto API generator to use some kind of template [\#11](https://github.com/blendle/eipiai/issues/11)
|
17
|
+
- Rename `handle\_post\_response` [\#5](https://github.com/blendle/eipiai/issues/5)
|
18
|
+
|
19
|
+
**Merged pull requests:**
|
20
|
+
|
21
|
+
- add new testing setup [\#23](https://github.com/blendle/eipiai/pull/23) ([JeanMertz](https://github.com/JeanMertz))
|
22
|
+
- correctly handle PUT and POST on existing resources [\#22](https://github.com/blendle/eipiai/pull/22) ([JeanMertz](https://github.com/JeanMertz))
|
23
|
+
- Tweaks and fixes v2 [\#21](https://github.com/blendle/eipiai/pull/21) ([JeanMertz](https://github.com/JeanMertz))
|
24
|
+
- add `service\_available?` check by default [\#18](https://github.com/blendle/eipiai/pull/18) ([JeanMertz](https://github.com/JeanMertz))
|
25
|
+
- add Eipiai::Resource::Representable module for resources [\#17](https://github.com/blendle/eipiai/pull/17) ([JeanMertz](https://github.com/JeanMertz))
|
26
|
+
- minor tweaks and fixes [\#16](https://github.com/blendle/eipiai/pull/16) ([JeanMertz](https://github.com/JeanMertz))
|
27
|
+
- Update Rubocop auto-correct issues [\#15](https://github.com/blendle/eipiai/pull/15) ([JeanMertz](https://github.com/JeanMertz))
|
28
|
+
- Introduce options to better define resource link relations [\#14](https://github.com/blendle/eipiai/pull/14) ([JeanMertz](https://github.com/JeanMertz))
|
29
|
+
|
3
30
|
## [v0.6.0](https://github.com/blendle/eipiai/tree/v0.6.0) (2015-12-18)
|
4
31
|
[Full Changelog](https://github.com/blendle/eipiai/compare/v0.5.1...v0.6.0)
|
5
32
|
|
data/Rakefile
CHANGED
@@ -3,24 +3,18 @@ require 'bundler/gem_tasks'
|
|
3
3
|
require 'cucumber/rake/task'
|
4
4
|
require 'rubocop/rake_task'
|
5
5
|
require 'yard-doctest'
|
6
|
+
require 'github_changelog_generator/task'
|
6
7
|
|
7
8
|
task default: %w(rubocop features yard:doctest)
|
8
9
|
|
9
10
|
RuboCop::RakeTask.new
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
--bug-labels=type/bug,bug
|
18
|
-
--enhancement-labels=type/enhancement,enhancement
|
19
|
-
--future-release=unreleased
|
20
|
-
--no-verbose
|
21
|
-
)
|
22
|
-
|
23
|
-
sh %(github_changelog_generator #{args.join(' ')})
|
12
|
+
GitHubChangelogGenerator::RakeTask.new :changelog do |c|
|
13
|
+
c.user = 'blendle'
|
14
|
+
c.project = 'eipiai'
|
15
|
+
c.header = '# CHANGELOG'
|
16
|
+
c.future_release = 'unreleased'
|
17
|
+
c.release_branch = 'master'
|
24
18
|
end
|
25
19
|
|
26
20
|
YARD::Doctest::RakeTask.new do |task|
|
data/TODO.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# TODO
|
2
|
+
|
3
|
+
Some notes and snippets on things we might want to do in the future:
|
4
|
+
|
5
|
+
* [IRBWebmachine](https://github.com/generalassembly/irwebmachine)
|
6
|
+
|
7
|
+
Could potentially improve debugging. Hasn't been updated in a while, it looks
|
8
|
+
like some issues where created about it not working anymore. Duplicate some of
|
9
|
+
the basic functionality?
|
10
|
+
|
11
|
+
* [http://dry-rb.org](http://dry-rb.org)
|
12
|
+
|
13
|
+
Some useful gems. Validation? Types?
|
data/eipiai.gemspec
CHANGED
@@ -23,9 +23,10 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_runtime_dependency 'webmachine'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler'
|
26
|
-
spec.add_development_dependency 'cucumber'
|
27
26
|
spec.add_development_dependency 'cucumber-blendle-steps'
|
27
|
+
spec.add_development_dependency 'cucumber'
|
28
28
|
spec.add_development_dependency 'database_cleaner'
|
29
|
+
spec.add_development_dependency 'github_changelog_generator'
|
29
30
|
spec.add_development_dependency 'pry'
|
30
31
|
spec.add_development_dependency 'rack-test'
|
31
32
|
spec.add_development_dependency 'rack'
|
@@ -52,6 +52,7 @@ Feature: Request entrypoint of API
|
|
52
52
|
|
53
53
|
When the client does a GET request to "/api"
|
54
54
|
Then the status code should be "200" (OK)
|
55
|
+
And the response contains the "Etag" header with value ""6566f445b1a56bc846ef9b95d5d79656""
|
55
56
|
And the response should be HAL/JSON:
|
56
57
|
"""json
|
57
58
|
{
|
@@ -18,6 +18,7 @@ Feature: Request a collection of resources
|
|
18
18
|
When the client provides the header "Accept: application/json"
|
19
19
|
And the client does a GET request to the "items" resource
|
20
20
|
Then the status code should be "200" (OK)
|
21
|
+
And the response contains the "Cache-Control" header with value "no-cache, no-store, must-revalidate, private"
|
21
22
|
And the response should be JSON:
|
22
23
|
"""json
|
23
24
|
{
|
@@ -25,3 +25,20 @@ Feature: Request entrypoint of API
|
|
25
25
|
"healthy": false
|
26
26
|
}
|
27
27
|
"""
|
28
|
+
|
29
|
+
Scenario: Return 503 on resources for an unhealthy service
|
30
|
+
Given the configuration "healthy" is set to "false"
|
31
|
+
And the following top-level resource at "/items":
|
32
|
+
"""ruby
|
33
|
+
class ItemsResource < Webmachine::Resource
|
34
|
+
include Eipiai::Resource
|
35
|
+
|
36
|
+
def object
|
37
|
+
{}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
"""
|
41
|
+
When the client does a GET request to the "items" resource
|
42
|
+
Then the status code should be "503" (Service Unavailable)
|
43
|
+
And the response contains the "Retry-After" header with value "60"
|
44
|
+
And the response contains the "Cache-Control" header with value "no-cache, no-store, must-revalidate, private"
|
@@ -19,6 +19,7 @@ Feature: Working with singular resources (GET, POST, PUT, DELETE)
|
|
19
19
|
When the client provides the header "Accept: application/json"
|
20
20
|
And the client does a GET request to the "item" resource with the template variable "item_uid" set to "hello"
|
21
21
|
Then the status code should be "200" (OK)
|
22
|
+
And the response contains the "Cache-Control" header with value "no-cache, no-store, must-revalidate, private"
|
22
23
|
And the response should be JSON:
|
23
24
|
"""json
|
24
25
|
{
|
data/lib/eipiai.rb
CHANGED
File without changes
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'webmachine'
|
3
|
+
|
4
|
+
require 'eipiai/resources/concerns/objectifiable'
|
5
|
+
require 'eipiai/resources/concerns/representable'
|
6
|
+
|
7
|
+
require 'eipiai/resources/ext/webmachine/decision'
|
8
|
+
require 'eipiai/resources/ext/webmachine/request'
|
9
|
+
|
10
|
+
require 'eipiai/resources/api'
|
11
|
+
require 'eipiai/resources/base'
|
12
|
+
require 'eipiai/resources/collection'
|
13
|
+
require 'eipiai/resources/health'
|
14
|
+
require 'eipiai/resources/singular'
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'eipiai/
|
2
|
+
require 'eipiai/resources/base'
|
3
3
|
|
4
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
4
5
|
require 'active_support/core_ext/string/inflections'
|
5
6
|
require 'json'
|
6
7
|
|
@@ -22,15 +23,28 @@ module Eipiai
|
|
22
23
|
class ApiResource < Webmachine::Resource
|
23
24
|
include Resource
|
24
25
|
|
26
|
+
# `etag` is set once, and then re-used throughout the lifecycle of the
|
27
|
+
# application. Only a restart of the web server will reset its value.
|
28
|
+
#
|
29
|
+
mattr_accessor :etag
|
30
|
+
|
25
31
|
def top_level_relation?
|
26
32
|
true
|
27
33
|
end
|
28
34
|
|
35
|
+
def service_available?
|
36
|
+
true
|
37
|
+
end
|
38
|
+
|
39
|
+
def generate_etag
|
40
|
+
self.class.etag ||= Digest::MD5.hexdigest(to_json)
|
41
|
+
end
|
42
|
+
|
29
43
|
def allowed_methods
|
30
44
|
%w(GET)
|
31
45
|
end
|
32
46
|
|
33
|
-
def
|
47
|
+
def cache_control_header_value
|
34
48
|
'public, max-age=600, s-maxage=86400'
|
35
49
|
end
|
36
50
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'eipiai/
|
3
|
-
require 'eipiai/
|
2
|
+
require 'eipiai/resources/singular'
|
3
|
+
require 'eipiai/resources/collection'
|
4
4
|
|
5
5
|
require 'active_support/core_ext/string/inflections'
|
6
6
|
require 'json'
|
@@ -75,9 +75,23 @@ module Eipiai
|
|
75
75
|
[]
|
76
76
|
end
|
77
77
|
|
78
|
+
# service_available?
|
79
|
+
#
|
80
|
+
# If the service is unavailable, this method should return false. By
|
81
|
+
# default, this method calls the `HealthCheck#healthy?` method, which in
|
82
|
+
# turn returns `true` or `false`, depending on the state of the service and
|
83
|
+
# its dependencies.
|
84
|
+
#
|
85
|
+
# When the service is unavailable, the `Cache-Control` header is set to not
|
86
|
+
# allow any caching by proxies/clients, and sets the `Retry-After` header to
|
87
|
+
# tell the client to retry again in 60 seconds.
|
88
|
+
#
|
89
|
+
# @return [true, false]
|
90
|
+
#
|
78
91
|
def service_available?
|
79
92
|
return true if Eipiai::HealthCheck.new.healthy?
|
80
93
|
|
94
|
+
response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate, private'
|
81
95
|
response.headers['Retry-After'] = '60'
|
82
96
|
false
|
83
97
|
end
|
@@ -138,6 +152,10 @@ module Eipiai
|
|
138
152
|
true
|
139
153
|
end
|
140
154
|
|
155
|
+
def finish_request
|
156
|
+
response.headers['Cache-Control'] = cache_control_header_value
|
157
|
+
end
|
158
|
+
|
141
159
|
# params
|
142
160
|
#
|
143
161
|
# Given a string in JSON format, returns the hash representation of that
|
@@ -225,6 +243,16 @@ module Eipiai
|
|
225
243
|
|
226
244
|
private
|
227
245
|
|
246
|
+
# cache_control_header_value
|
247
|
+
#
|
248
|
+
# The default Cache-Control header value served by all resources.
|
249
|
+
#
|
250
|
+
# @return String default Cache-Control header value
|
251
|
+
#
|
252
|
+
def cache_control_header_value
|
253
|
+
'no-cache, no-store, must-revalidate, private'
|
254
|
+
end
|
255
|
+
|
228
256
|
def json_error_body(errors)
|
229
257
|
response.headers['Content-Type'] = 'application/json'
|
230
258
|
response.body = FormattedErrors.parse(errors).to_json
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
require 'eipiai/
|
2
|
+
require 'eipiai/resources/base'
|
3
3
|
|
4
4
|
require 'active_support/core_ext/string/inflections'
|
5
5
|
require 'json'
|
@@ -63,6 +63,10 @@ module Eipiai
|
|
63
63
|
false
|
64
64
|
end
|
65
65
|
|
66
|
+
def finish_request
|
67
|
+
response.headers['Cache-Control'] = 'no-cache, no-store, must-revalidate, private'
|
68
|
+
end
|
69
|
+
|
66
70
|
def object
|
67
71
|
HealthCheck.new
|
68
72
|
end
|
File without changes
|
File without changes
|
data/lib/eipiai/version.rb
CHANGED
data/script/test
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eipiai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean Mertz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name: cucumber
|
84
|
+
name: cucumber-blendle-steps
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: cucumber
|
98
|
+
name: cucumber
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: github_changelog_generator
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: pry
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -236,6 +250,7 @@ files:
|
|
236
250
|
- Gemfile
|
237
251
|
- README.md
|
238
252
|
- Rakefile
|
253
|
+
- TODO.md
|
239
254
|
- eipiai.gemspec
|
240
255
|
- features/resources/api.feature
|
241
256
|
- features/resources/collection.feature
|
@@ -258,25 +273,25 @@ files:
|
|
258
273
|
- lib/eipiai/models.rb
|
259
274
|
- lib/eipiai/models/collection.rb
|
260
275
|
- lib/eipiai/models/representable.rb
|
261
|
-
- lib/eipiai/
|
262
|
-
- lib/eipiai/
|
263
|
-
- lib/eipiai/
|
264
|
-
- lib/eipiai/roar/
|
265
|
-
- lib/eipiai/
|
266
|
-
- lib/eipiai/
|
267
|
-
- lib/eipiai/
|
268
|
-
- lib/eipiai/
|
276
|
+
- lib/eipiai/representers.rb
|
277
|
+
- lib/eipiai/representers/api.rb
|
278
|
+
- lib/eipiai/representers/base.rb
|
279
|
+
- lib/eipiai/representers/ext/roar/hal.rb
|
280
|
+
- lib/eipiai/resources.rb
|
281
|
+
- lib/eipiai/resources/api.rb
|
282
|
+
- lib/eipiai/resources/base.rb
|
283
|
+
- lib/eipiai/resources/collection.rb
|
284
|
+
- lib/eipiai/resources/concerns/objectifiable.rb
|
285
|
+
- lib/eipiai/resources/concerns/representable.rb
|
286
|
+
- lib/eipiai/resources/ext/webmachine/decision.rb
|
287
|
+
- lib/eipiai/resources/ext/webmachine/request.rb
|
288
|
+
- lib/eipiai/resources/health.rb
|
289
|
+
- lib/eipiai/resources/singular.rb
|
290
|
+
- lib/eipiai/validators.rb
|
291
|
+
- lib/eipiai/validators/base.rb
|
292
|
+
- lib/eipiai/validators/concerns/formatted_errors.rb
|
293
|
+
- lib/eipiai/validators/sequel.rb
|
269
294
|
- lib/eipiai/version.rb
|
270
|
-
- lib/eipiai/webmachine.rb
|
271
|
-
- lib/eipiai/webmachine/ext/decision.rb
|
272
|
-
- lib/eipiai/webmachine/ext/request.rb
|
273
|
-
- lib/eipiai/webmachine/resources/api.rb
|
274
|
-
- lib/eipiai/webmachine/resources/base.rb
|
275
|
-
- lib/eipiai/webmachine/resources/collection.rb
|
276
|
-
- lib/eipiai/webmachine/resources/concerns/objectifiable.rb
|
277
|
-
- lib/eipiai/webmachine/resources/concerns/representable.rb
|
278
|
-
- lib/eipiai/webmachine/resources/health.rb
|
279
|
-
- lib/eipiai/webmachine/resources/singular.rb
|
280
295
|
- script/bootstrap
|
281
296
|
- script/documentation
|
282
297
|
- script/test
|
@@ -299,7 +314,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
299
314
|
version: '0'
|
300
315
|
requirements: []
|
301
316
|
rubyforge_project:
|
302
|
-
rubygems_version: 2.
|
317
|
+
rubygems_version: 2.6.4
|
303
318
|
signing_key:
|
304
319
|
specification_version: 4
|
305
320
|
summary: Opinionated JSON-API stack to get the job done.
|
data/lib/eipiai/roar.rb
DELETED
data/lib/eipiai/validation.rb
DELETED
data/lib/eipiai/webmachine.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'webmachine'
|
3
|
-
|
4
|
-
require 'eipiai/webmachine/ext/decision'
|
5
|
-
require 'eipiai/webmachine/ext/request'
|
6
|
-
|
7
|
-
require 'eipiai/webmachine/resources/concerns/objectifiable'
|
8
|
-
require 'eipiai/webmachine/resources/concerns/representable'
|
9
|
-
|
10
|
-
require 'eipiai/webmachine/resources/api'
|
11
|
-
require 'eipiai/webmachine/resources/base'
|
12
|
-
require 'eipiai/webmachine/resources/collection'
|
13
|
-
require 'eipiai/webmachine/resources/health'
|
14
|
-
require 'eipiai/webmachine/resources/singular'
|