eipiai 0.6.0 → 0.7.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/.gitignore +1 -4
 - data/.rubocop.yml +3 -0
 - data/.ruby-version +1 -0
 - data/.wercker.yml +8 -1
 - data/CHANGELOG.md +7 -0
 - data/Gemfile +1 -0
 - data/Rakefile +1 -0
 - data/eipiai.gemspec +1 -0
 - data/features/resources/api.feature +82 -0
 - data/features/resources/collection.feature +60 -0
 - data/features/resources/collection/get.feature +189 -0
 - data/features/resources/collection/post.feature +230 -0
 - data/features/resources/health.feature +27 -0
 - data/features/resources/singular.feature +86 -0
 - data/features/resources/singular/delete.feature +69 -0
 - data/features/resources/singular/get.feature +146 -0
 - data/features/resources/singular/post.feature +235 -0
 - data/features/resources/singular/put.feature +164 -0
 - data/features/step_definitions/steps.rb +10 -0
 - data/features/step_definitions/webmachine_steps.rb +58 -0
 - data/features/support/app.rb +14 -26
 - data/features/support/env.rb +1 -0
 - data/features/validation.feature +1 -0
 - data/features/webmachine.feature +1 -56
 - data/lib/eipiai.rb +1 -0
 - data/lib/eipiai/configuration.rb +1 -0
 - data/lib/eipiai/models.rb +1 -0
 - data/lib/eipiai/models/collection.rb +1 -0
 - data/lib/eipiai/models/representable.rb +6 -5
 - data/lib/eipiai/roar.rb +1 -0
 - data/lib/eipiai/roar/ext/hal.rb +3 -0
 - data/lib/eipiai/roar/representers/api.rb +17 -6
 - data/lib/eipiai/roar/representers/base.rb +1 -0
 - data/lib/eipiai/validation.rb +1 -0
 - data/lib/eipiai/validation/concerns/formatted_errors.rb +1 -0
 - data/lib/eipiai/validation/validators/base.rb +2 -1
 - data/lib/eipiai/validation/validators/sequel.rb +1 -0
 - data/lib/eipiai/version.rb +2 -1
 - data/lib/eipiai/webmachine.rb +2 -0
 - data/lib/eipiai/webmachine/ext/decision.rb +1 -0
 - data/lib/eipiai/webmachine/ext/request.rb +2 -1
 - data/lib/eipiai/webmachine/resources/api.rb +7 -3
 - data/lib/eipiai/webmachine/resources/base.rb +96 -19
 - data/lib/eipiai/webmachine/resources/collection.rb +4 -18
 - data/lib/eipiai/webmachine/resources/concerns/objectifiable.rb +1 -0
 - data/lib/eipiai/webmachine/resources/concerns/representable.rb +69 -0
 - data/lib/eipiai/webmachine/resources/health.rb +16 -10
 - data/lib/eipiai/webmachine/resources/singular.rb +45 -10
 - metadata +16 -4
 - data/features/support/db.rb +0 -8
 
| 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       1 
2 
     | 
    
         
             
            require 'eipiai/webmachine/resources/base'
         
     | 
| 
       2 
3 
     | 
    
         | 
| 
       3 
4 
     | 
    
         
             
            require 'active_support/core_ext/string/inflections'
         
     | 
| 
         @@ -6,7 +7,8 @@ require 'json' 
     | 
|
| 
       6 
7 
     | 
    
         
             
            module Eipiai
         
     | 
| 
       7 
8 
     | 
    
         
             
              # HealthCheck
         
     | 
| 
       8 
9 
     | 
    
         
             
              #
         
     | 
| 
       9 
     | 
    
         
            -
              # Class with a  
     | 
| 
      
 10 
     | 
    
         
            +
              # Class with a `#healthy?` method. If this method returns `true`, the service
         
     | 
| 
      
 11 
     | 
    
         
            +
              # is expected to be available and ready to serve requests.
         
     | 
| 
       10 
12 
     | 
    
         
             
              #
         
     | 
| 
       11 
13 
     | 
    
         
             
              class HealthCheck
         
     | 
| 
       12 
14 
     | 
    
         
             
                # healthy?
         
     | 
| 
         @@ -19,26 +21,30 @@ module Eipiai 
     | 
|
| 
       19 
21 
     | 
    
         
             
                  Eipiai.configuration.healthy == true
         
     | 
| 
       20 
22 
     | 
    
         
             
                end
         
     | 
| 
       21 
23 
     | 
    
         | 
| 
       22 
     | 
    
         
            -
                #  
     | 
| 
      
 24 
     | 
    
         
            +
                # to_h
         
     | 
| 
       23 
25 
     | 
    
         
             
                #
         
     | 
| 
       24 
26 
     | 
    
         
             
                # Hash representation of the health status.
         
     | 
| 
       25 
27 
     | 
    
         
             
                #
         
     | 
| 
       26 
28 
     | 
    
         
             
                # @return [Hash] hash representation of health status
         
     | 
| 
       27 
29 
     | 
    
         
             
                #
         
     | 
| 
       28 
     | 
    
         
            -
                def  
     | 
| 
      
 30 
     | 
    
         
            +
                def to_h
         
     | 
| 
       29 
31 
     | 
    
         
             
                  { 'healthy' => healthy? }
         
     | 
| 
       30 
32 
     | 
    
         
             
                end
         
     | 
| 
       31 
33 
     | 
    
         
             
              end
         
     | 
| 
       32 
34 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
              #  
     | 
| 
      
 35 
     | 
    
         
            +
              # HealthResource
         
     | 
| 
       34 
36 
     | 
    
         
             
              #
         
     | 
| 
       35 
     | 
    
         
            -
              #  
     | 
| 
       36 
     | 
    
         
            -
              #  
     | 
| 
       37 
     | 
    
         
            -
              #  
     | 
| 
      
 37 
     | 
    
         
            +
              # Provides basic health checking of the API. This resource can be configured
         
     | 
| 
      
 38 
     | 
    
         
            +
              # to validate a working service, and return the correct availability to the
         
     | 
| 
      
 39 
     | 
    
         
            +
              # client.
         
     | 
| 
       38 
40 
     | 
    
         
             
              #
         
     | 
| 
       39 
41 
     | 
    
         
             
              class HealthResource < Webmachine::Resource
         
     | 
| 
       40 
42 
     | 
    
         
             
                include Resource
         
     | 
| 
       41 
43 
     | 
    
         | 
| 
      
 44 
     | 
    
         
            +
                def top_level_relation?
         
     | 
| 
      
 45 
     | 
    
         
            +
                  true
         
     | 
| 
      
 46 
     | 
    
         
            +
                end
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
       42 
48 
     | 
    
         
             
                def allowed_methods
         
     | 
| 
       43 
49 
     | 
    
         
             
                  %w(GET)
         
     | 
| 
       44 
50 
     | 
    
         
             
                end
         
     | 
| 
         @@ -51,7 +57,7 @@ module Eipiai 
     | 
|
| 
       51 
57 
     | 
    
         
             
                  return true if healthy?
         
     | 
| 
       52 
58 
     | 
    
         | 
| 
       53 
59 
     | 
    
         
             
                  response.headers['Content-Type'] = 'application/json'
         
     | 
| 
       54 
     | 
    
         
            -
                  response.headers['Retry-After'] 
     | 
| 
      
 60 
     | 
    
         
            +
                  response.headers['Retry-After']  = '60'
         
     | 
| 
       55 
61 
     | 
    
         | 
| 
       56 
62 
     | 
    
         
             
                  response.body = to_json
         
     | 
| 
       57 
63 
     | 
    
         
             
                  false
         
     | 
| 
         @@ -65,8 +71,8 @@ module Eipiai 
     | 
|
| 
       65 
71 
     | 
    
         | 
| 
       66 
72 
     | 
    
         
             
                # healthy?
         
     | 
| 
       67 
73 
     | 
    
         
             
                #
         
     | 
| 
       68 
     | 
    
         
            -
                # Returns true if `HealthCheck 
     | 
| 
       69 
     | 
    
         
            -
                #  
     | 
| 
      
 74 
     | 
    
         
            +
                # Returns true if `HealthCheck#healthy?` returns `true`, otherwise returns
         
     | 
| 
      
 75 
     | 
    
         
            +
                # `false`.
         
     | 
| 
       70 
76 
     | 
    
         
             
                #
         
     | 
| 
       71 
77 
     | 
    
         
             
                # @return [true, false] health status of service
         
     | 
| 
       72 
78 
     | 
    
         
             
                #
         
     | 
| 
         @@ -1,3 +1,4 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            # frozen_string_literal: true
         
     | 
| 
       1 
2 
     | 
    
         
             
            require 'eipiai/webmachine/resources/base'
         
     | 
| 
       2 
3 
     | 
    
         | 
| 
       3 
4 
     | 
    
         
             
            require 'active_support/core_ext/object/blank'
         
     | 
| 
         @@ -16,32 +17,30 @@ module Eipiai 
     | 
|
| 
       16 
17 
     | 
    
         
             
              #
         
     | 
| 
       17 
18 
     | 
    
         
             
              module SingularResource
         
     | 
| 
       18 
19 
     | 
    
         
             
                def allowed_methods
         
     | 
| 
       19 
     | 
    
         
            -
                  %w(GET PUT DELETE)
         
     | 
| 
      
 20 
     | 
    
         
            +
                  %w(GET POST PUT DELETE)
         
     | 
| 
       20 
21 
     | 
    
         
             
                end
         
     | 
| 
       21 
22 
     | 
    
         | 
| 
       22 
23 
     | 
    
         
             
                def resource_exists?
         
     | 
| 
       23 
24 
     | 
    
         
             
                  object.present?
         
     | 
| 
       24 
25 
     | 
    
         
             
                end
         
     | 
| 
       25 
26 
     | 
    
         | 
| 
      
 27 
     | 
    
         
            +
                def create_path
         
     | 
| 
      
 28 
     | 
    
         
            +
                  request.uri.path
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
       26 
31 
     | 
    
         
             
                def delete_resource
         
     | 
| 
       27 
32 
     | 
    
         
             
                  object.destroy
         
     | 
| 
      
 33 
     | 
    
         
            +
                  @object = nil
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
       28 
35 
     | 
    
         
             
                  true
         
     | 
| 
       29 
36 
     | 
    
         
             
                end
         
     | 
| 
       30 
37 
     | 
    
         | 
| 
       31 
38 
     | 
    
         
             
                def from_json
         
     | 
| 
       32 
     | 
    
         
            -
                   
     | 
| 
       33 
     | 
    
         
            -
                  new_object.save
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
                  response.headers['Location'] = request.uri.to_s
         
     | 
| 
       36 
     | 
    
         
            -
                  exists ? 204 : 201
         
     | 
| 
      
 39 
     | 
    
         
            +
                  request.put? ? put_from_json : post_from_json
         
     | 
| 
       37 
40 
     | 
    
         
             
                end
         
     | 
| 
       38 
41 
     | 
    
         | 
| 
       39 
42 
     | 
    
         
             
                private
         
     | 
| 
       40 
43 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
                def params
         
     | 
| 
       42 
     | 
    
         
            -
                  @merged_params ||= super.merge('uid' => object_uid)
         
     | 
| 
       43 
     | 
    
         
            -
                end
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
44 
     | 
    
         
             
                def object
         
     | 
| 
       46 
45 
     | 
    
         
             
                  @object ||= object_class.first(uid: object_uid) if object_class
         
     | 
| 
       47 
46 
     | 
    
         
             
                end
         
     | 
| 
         @@ -49,5 +48,41 @@ module Eipiai 
     | 
|
| 
       49 
48 
     | 
    
         
             
                def object_uid
         
     | 
| 
       50 
49 
     | 
    
         
             
                  request.path_info[:"#{object_class_name.downcase}_uid"]
         
     | 
| 
       51 
50 
     | 
    
         
             
                end
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                alias uid object_uid
         
     | 
| 
      
 53 
     | 
    
         
            +
             
     | 
| 
      
 54 
     | 
    
         
            +
                # put_from_json
         
     | 
| 
      
 55 
     | 
    
         
            +
                #
         
     | 
| 
      
 56 
     | 
    
         
            +
                # When `from_json` is called, and the request is using the `PUT` method,
         
     | 
| 
      
 57 
     | 
    
         
            +
                # this method is called.
         
     | 
| 
      
 58 
     | 
    
         
            +
                #
         
     | 
| 
      
 59 
     | 
    
         
            +
                # Deletes the existing record, if it exists, and saves the newly created
         
     | 
| 
      
 60 
     | 
    
         
            +
                # record. Triggers `handle_post_or_put_with_optional_content`, with
         
     | 
| 
      
 61 
     | 
    
         
            +
                # `created` set to `true` unless the new record replaced an old one.
         
     | 
| 
      
 62 
     | 
    
         
            +
                #
         
     | 
| 
      
 63 
     | 
    
         
            +
                # @return [Integer] either 200, 201 or 204. See `#handle_post_or_put_with_optional_content`
         
     | 
| 
      
 64 
     | 
    
         
            +
                #
         
     | 
| 
      
 65 
     | 
    
         
            +
                def put_from_json
         
     | 
| 
      
 66 
     | 
    
         
            +
                  delete_resource if (exists = object.present?)
         
     | 
| 
      
 67 
     | 
    
         
            +
                  new_object.save
         
     | 
| 
      
 68 
     | 
    
         
            +
             
     | 
| 
      
 69 
     | 
    
         
            +
                  handle_post_or_put_with_optional_content(created: exists.blank?)
         
     | 
| 
      
 70 
     | 
    
         
            +
                end
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
                # post_from_json
         
     | 
| 
      
 73 
     | 
    
         
            +
                #
         
     | 
| 
      
 74 
     | 
    
         
            +
                # When `from_json` is called, and the request is using the `POST` method,
         
     | 
| 
      
 75 
     | 
    
         
            +
                # this method is called.
         
     | 
| 
      
 76 
     | 
    
         
            +
                #
         
     | 
| 
      
 77 
     | 
    
         
            +
                # calls #save on the existing object, and triggers
         
     | 
| 
      
 78 
     | 
    
         
            +
                # `handle_post_or_put_with_optional_content`, with `created` set to `false`.
         
     | 
| 
      
 79 
     | 
    
         
            +
                #
         
     | 
| 
      
 80 
     | 
    
         
            +
                # @return [Integer] either 200, 201 or 204. See `#handle_post_or_put_with_optional_content`
         
     | 
| 
      
 81 
     | 
    
         
            +
                #
         
     | 
| 
      
 82 
     | 
    
         
            +
                def post_from_json
         
     | 
| 
      
 83 
     | 
    
         
            +
                  object.save
         
     | 
| 
      
 84 
     | 
    
         
            +
             
     | 
| 
      
 85 
     | 
    
         
            +
                  handle_post_or_put_with_optional_content(created: false)
         
     | 
| 
      
 86 
     | 
    
         
            +
                end
         
     | 
| 
       52 
87 
     | 
    
         
             
              end
         
     | 
| 
       53 
88 
     | 
    
         
             
            end
         
     | 
    
        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.7.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:  
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2016-05-03 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: activesupport
         
     | 
| 
         @@ -230,15 +230,26 @@ files: 
     | 
|
| 
       230 
230 
     | 
    
         
             
            - ".gitignore"
         
     | 
| 
       231 
231 
     | 
    
         
             
            - ".hubbit.yml"
         
     | 
| 
       232 
232 
     | 
    
         
             
            - ".rubocop.yml"
         
     | 
| 
      
 233 
     | 
    
         
            +
            - ".ruby-version"
         
     | 
| 
       233 
234 
     | 
    
         
             
            - ".wercker.yml"
         
     | 
| 
       234 
235 
     | 
    
         
             
            - CHANGELOG.md
         
     | 
| 
       235 
236 
     | 
    
         
             
            - Gemfile
         
     | 
| 
       236 
237 
     | 
    
         
             
            - README.md
         
     | 
| 
       237 
238 
     | 
    
         
             
            - Rakefile
         
     | 
| 
       238 
239 
     | 
    
         
             
            - eipiai.gemspec
         
     | 
| 
      
 240 
     | 
    
         
            +
            - features/resources/api.feature
         
     | 
| 
      
 241 
     | 
    
         
            +
            - features/resources/collection.feature
         
     | 
| 
      
 242 
     | 
    
         
            +
            - features/resources/collection/get.feature
         
     | 
| 
      
 243 
     | 
    
         
            +
            - features/resources/collection/post.feature
         
     | 
| 
      
 244 
     | 
    
         
            +
            - features/resources/health.feature
         
     | 
| 
      
 245 
     | 
    
         
            +
            - features/resources/singular.feature
         
     | 
| 
      
 246 
     | 
    
         
            +
            - features/resources/singular/delete.feature
         
     | 
| 
      
 247 
     | 
    
         
            +
            - features/resources/singular/get.feature
         
     | 
| 
      
 248 
     | 
    
         
            +
            - features/resources/singular/post.feature
         
     | 
| 
      
 249 
     | 
    
         
            +
            - features/resources/singular/put.feature
         
     | 
| 
       239 
250 
     | 
    
         
             
            - features/step_definitions/steps.rb
         
     | 
| 
      
 251 
     | 
    
         
            +
            - features/step_definitions/webmachine_steps.rb
         
     | 
| 
       240 
252 
     | 
    
         
             
            - features/support/app.rb
         
     | 
| 
       241 
     | 
    
         
            -
            - features/support/db.rb
         
     | 
| 
       242 
253 
     | 
    
         
             
            - features/support/env.rb
         
     | 
| 
       243 
254 
     | 
    
         
             
            - features/validation.feature
         
     | 
| 
       244 
255 
     | 
    
         
             
            - features/webmachine.feature
         
     | 
| 
         @@ -263,6 +274,7 @@ files: 
     | 
|
| 
       263 
274 
     | 
    
         
             
            - lib/eipiai/webmachine/resources/base.rb
         
     | 
| 
       264 
275 
     | 
    
         
             
            - lib/eipiai/webmachine/resources/collection.rb
         
     | 
| 
       265 
276 
     | 
    
         
             
            - lib/eipiai/webmachine/resources/concerns/objectifiable.rb
         
     | 
| 
      
 277 
     | 
    
         
            +
            - lib/eipiai/webmachine/resources/concerns/representable.rb
         
     | 
| 
       266 
278 
     | 
    
         
             
            - lib/eipiai/webmachine/resources/health.rb
         
     | 
| 
       267 
279 
     | 
    
         
             
            - lib/eipiai/webmachine/resources/singular.rb
         
     | 
| 
       268 
280 
     | 
    
         
             
            - script/bootstrap
         
     | 
| 
         @@ -287,7 +299,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       287 
299 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       288 
300 
     | 
    
         
             
            requirements: []
         
     | 
| 
       289 
301 
     | 
    
         
             
            rubyforge_project: 
         
     | 
| 
       290 
     | 
    
         
            -
            rubygems_version: 2. 
     | 
| 
      
 302 
     | 
    
         
            +
            rubygems_version: 2.5.1
         
     | 
| 
       291 
303 
     | 
    
         
             
            signing_key: 
         
     | 
| 
       292 
304 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       293 
305 
     | 
    
         
             
            summary: Opinionated JSON-API stack to get the job done.
         
     |