eipiai 0.4.0 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ae6cef8a01a687e9de4ca1a6cf889b9ce3f476f
4
- data.tar.gz: bd8cd1327cb8b859c8b5f09518ccf0700fcbb3c5
3
+ metadata.gz: a3bfe7f33ca1682dcbcde9d21595b1bb6119bee8
4
+ data.tar.gz: 9e51991a96b67325b3add840f5512be6b769f4e5
5
5
  SHA512:
6
- metadata.gz: b5971360e6f2b6f1c220dab71e7ecb7cd647406477b25310fdffef98655db324450e930f4018596263fd72099423bf27d8733babf46e1392af8cd36d334ef59d
7
- data.tar.gz: cbf9e28a0ce0e4df1eba0465ba4bf18a7ef6f6455a3fda7536c19d9074bb1267b4cd7c05d6e88078c4a7e7038032c71c17737df7c26df48411dd62048970e1fb
6
+ metadata.gz: 3cab26999f86e06b1a37bbbd7fab0aa3c36a6bc199e3f325ca629b1e51625351c033f5450cca5279a88931a5bff02783010778814a83b187e8b5eee70e7d1056
7
+ data.tar.gz: a8f09782eb7b1d274509961a89f12546f30c6823fd462570200dc7186ccca1a288ff41d925be437bac77e9d5a39290e072efd3bb75c2c62647c993b6e7b28ef5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## [v0.4.0](https://github.com/blendle/eipiai/tree/v0.4.0) (2015-12-14)
4
+ [Full Changelog](https://github.com/blendle/eipiai/compare/v0.3.0...v0.4.0)
5
+
6
+ **Merged pull requests:**
7
+
8
+ - automated curies configuration [\#6](https://github.com/blendle/eipiai/pull/6) ([JeanMertz](https://github.com/JeanMertz))
9
+
3
10
  ## [v0.3.0](https://github.com/blendle/eipiai/tree/v0.3.0) (2015-12-13)
4
11
  [Full Changelog](https://github.com/blendle/eipiai/compare/v0.2.0...v0.3.0)
5
12
 
@@ -0,0 +1,3 @@
1
+ Given(/^the configuration "([^"]*)" is set to "([^"]*)"$/) do |config, value|
2
+ Eipiai.configuration.send("#{config}=", value)
3
+ end
@@ -10,6 +10,7 @@ include Eipiai::TestApp
10
10
  WebmachineApp = Webmachine::Application.new do |app|
11
11
  app.routes do
12
12
  add ['api'], Eipiai::ApiResource
13
+ add ['health'], Eipiai::HealthResource
13
14
 
14
15
  add ['items'], ItemsResource
15
16
  add ['item', :item_uid], ItemResource
@@ -28,7 +29,10 @@ def app
28
29
  WebmachineApp.adapter
29
30
  end
30
31
 
31
- Eipiai.configure do |config|
32
- config.base_uri = 'https://example.org'
33
- config.curie_uris = { b: 'https://api.example.org/rel/{rel}' }
32
+ Before do
33
+ Eipiai.configuration = Eipiai::Configuration.new
34
+ Eipiai.configure do |config|
35
+ config.base_uri = 'https://example.org'
36
+ config.curie_uris = { b: 'https://api.example.org/rel/{rel}' }
37
+ end
34
38
  end
@@ -17,6 +17,9 @@ Feature: Webmachine CRUD operations
17
17
  "api": {
18
18
  "href": "https://example.org/api"
19
19
  },
20
+ "health": {
21
+ "href": "https://example.org/health"
22
+ },
20
23
  "items": {
21
24
  "href": "https://example.org/items"
22
25
  },
@@ -35,6 +38,28 @@ Feature: Webmachine CRUD operations
35
38
  }
36
39
  """
37
40
 
41
+ Scenario: Get service health
42
+ When the client does a GET request to "/health"
43
+ Then the status code should be "200" (OK)
44
+ And the response should be JSON:
45
+ """json
46
+ {
47
+ "healthy": true
48
+ }
49
+ """
50
+
51
+ Scenario: Get unhealthy service health
52
+ Given the configuration "healthy" is set to "false"
53
+ When the client does a GET request to "/health"
54
+ Then the status code should be "503" (Service Unavailable)
55
+ And the response contains the "Retry-After" header with value "60"
56
+ And the response should be JSON:
57
+ """json
58
+ {
59
+ "healthy": false
60
+ }
61
+ """
62
+
38
63
  Scenario: Create resource
39
64
  Given the client provides the header "Content-Type: application/json"
40
65
  When the client does a POST request to the "items" resource with the following content:
@@ -0,0 +1,38 @@
1
+ # Eipiai
2
+ #
3
+ # The main module for the library.
4
+ #
5
+ module Eipiai
6
+ class << self
7
+ attr_accessor :configuration
8
+
9
+ # configure
10
+ #
11
+ # Configure the library using this `configure` method, as follows:
12
+ #
13
+ # Eipiai.configure do |config|
14
+ # config.curie_uris = { b: 'https://api.blendle.com/rel/{rel}' }
15
+ # end
16
+ #
17
+ # @return [void]
18
+ #
19
+ def configure
20
+ yield(configuration)
21
+ end
22
+ end
23
+
24
+ # Configuration
25
+ #
26
+ # The configuration store for the Eipiai library.
27
+ #
28
+ class Configuration
29
+ attr_accessor :base_uri, :curie_uris, :healthy
30
+
31
+ def initialize
32
+ @healthy = true
33
+ @curie_uris = {}
34
+ end
35
+ end
36
+
37
+ @configuration = Configuration.new
38
+ end
@@ -3,5 +3,5 @@
3
3
  # The current version of the Eipiai library.
4
4
  #
5
5
  module Eipiai
6
- VERSION = '0.4.0'
6
+ VERSION = '0.5.0'
7
7
  end
@@ -0,0 +1,81 @@
1
+ require 'eipiai/webmachine/resources/base'
2
+
3
+ require 'active_support/core_ext/string/inflections'
4
+ require 'json'
5
+
6
+ module Eipiai
7
+ # HealthCheck
8
+ #
9
+ # Class with a single method `healthy?`. Returns `true` by default.
10
+ #
11
+ class HealthCheck
12
+ # healthy?
13
+ #
14
+ # Can be overwritten with custom logic to determine health status.
15
+ #
16
+ # @return [true, false] health status of service
17
+ #
18
+ def healthy?
19
+ Eipiai.configuration.healthy == true
20
+ end
21
+
22
+ # to_hash
23
+ #
24
+ # Hash representation of the health status.
25
+ #
26
+ # @return [Hash] hash representation of health status
27
+ #
28
+ def to_hash
29
+ { 'healthy' => healthy? }
30
+ end
31
+ end
32
+
33
+ # ApiResource
34
+ #
35
+ # The base resource which can be included in regular Webmachine::Resource
36
+ # objects. It provides sensible defaults for a full-features REST API
37
+ # endpoint.
38
+ #
39
+ class HealthResource < Webmachine::Resource
40
+ include Resource
41
+
42
+ def allowed_methods
43
+ %w(GET)
44
+ end
45
+
46
+ def content_types_provided
47
+ [['application/json', :to_json]]
48
+ end
49
+
50
+ def service_available?
51
+ return true if healthy?
52
+
53
+ response.headers['Content-Type'] = 'application/json'
54
+ response.headers['Retry-After'] = '60'
55
+
56
+ response.body = to_json
57
+ false
58
+ end
59
+
60
+ def object
61
+ HealthCheck.new
62
+ end
63
+
64
+ def represented
65
+ object
66
+ end
67
+
68
+ private
69
+
70
+ # healthy?
71
+ #
72
+ # Returns true if `HealthCheck.new.healthy?` returns `true`, otherwise
73
+ # returns `false`.
74
+ #
75
+ # @return [true, false] health status of service
76
+ #
77
+ def healthy?
78
+ object.healthy?
79
+ end
80
+ end
81
+ end
@@ -6,4 +6,5 @@ require 'eipiai/webmachine/ext/request'
6
6
  require 'eipiai/webmachine/resources/api'
7
7
  require 'eipiai/webmachine/resources/base'
8
8
  require 'eipiai/webmachine/resources/collection'
9
+ require 'eipiai/webmachine/resources/health'
9
10
  require 'eipiai/webmachine/resources/singular'
data/lib/eipiai.rb CHANGED
@@ -1,41 +1,5 @@
1
+ require 'eipiai/configuration'
2
+
1
3
  require 'eipiai/roar'
2
4
  require 'eipiai/validation'
3
5
  require 'eipiai/webmachine'
4
-
5
- # Eipiai
6
- #
7
- # The main module for the library.
8
- #
9
- module Eipiai
10
- class << self
11
- attr_accessor :configuration
12
-
13
- # configure
14
- #
15
- # Configure the library using this `configure` method, as follows:
16
- #
17
- # Eipiai.configure do |config|
18
- # config.curie_uris = { b: 'https://api.blendle.com/rel/{rel}' }
19
- # end
20
- #
21
- # @return [void]
22
- #
23
- def configure
24
- yield(configuration)
25
- end
26
- end
27
-
28
- # Configuration
29
- #
30
- # The configuration store for the Eipiai library.
31
- #
32
- class Configuration
33
- attr_accessor :base_uri, :curie_uris
34
-
35
- def initialize
36
- @curie_uris = {}
37
- end
38
- end
39
-
40
- @configuration = Configuration.new
41
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eipiai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Mertz
@@ -236,12 +236,14 @@ files:
236
236
  - README.md
237
237
  - Rakefile
238
238
  - eipiai.gemspec
239
+ - features/step_definitions/steps.rb
239
240
  - features/support/app.rb
240
241
  - features/support/db.rb
241
242
  - features/support/env.rb
242
243
  - features/validation.feature
243
244
  - features/webmachine.feature
244
245
  - lib/eipiai.rb
246
+ - lib/eipiai/configuration.rb
245
247
  - lib/eipiai/roar.rb
246
248
  - lib/eipiai/roar/ext/hal.rb
247
249
  - lib/eipiai/roar/representers/api.rb
@@ -257,6 +259,7 @@ files:
257
259
  - lib/eipiai/webmachine/resources/api.rb
258
260
  - lib/eipiai/webmachine/resources/base.rb
259
261
  - lib/eipiai/webmachine/resources/collection.rb
262
+ - lib/eipiai/webmachine/resources/health.rb
260
263
  - lib/eipiai/webmachine/resources/singular.rb
261
264
  - script/bootstrap
262
265
  - script/documentation