blsk_ruby_core_api 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 951752d03f54da4ddbf6d0b906bbe453332912625b091bab48c7c7e37e5e25bb
4
- data.tar.gz: d720cdadec8d3028824975157e60e2399622cd9191b807e9d87bb8891728a626
3
+ metadata.gz: b3f4ebf6047ba0f37b3f1ae6512335e7332c5448f1425fe078ae10d69f175b6b
4
+ data.tar.gz: cbc8dc774fcac8b621b16e5eb439ab821a17c62c5c485bb04a3d4db256065cd8
5
5
  SHA512:
6
- metadata.gz: 5cb52c3820d425bea73fef1efc672ef581a35cf06cec8a2e63ad519260b63f6455379f9be9f310d195af414058c31f9332ef17d102005a1d0a818609a29ee367
7
- data.tar.gz: fe0eda37e2478952eb4589c96debca2dbb0afceb80076381cda00e983545b85b01251bb03431aae3d4dd44f6fb1bf6e4978f2e75de4b1100a1986a063f5d801e
6
+ metadata.gz: 54a7e52ef9610661491cf95ee294dd53738623802d7a776b86e0122a28d0b2662696d53dc4350c9f54b670ee9a520fa6ee47abb1a51ccc083c9a78935d1cbb1e
7
+ data.tar.gz: c6a0c1121d35afbd75ad2fb9fefb9b6d08b36d5472b08f14407e66db8cf0fe567b2d42b24d5bb329cf28110bde2d73c1c6021e936e0f962adf24ca053a636bb6
@@ -4,9 +4,10 @@ require 'request_store'
4
4
 
5
5
  require_relative 'application_configuration'
6
6
  require_relative 'app_service'
7
- require_relative 'rest/rest_service'
7
+ require_relative 'rest/rest_base'
8
8
  require_relative 'decoractors/authenticate'
9
9
  require_relative 'decoractors/valid'
10
+ require_relative 'model/model'
10
11
  # Dir["#{File.dirname(__FILE__)}/**/*.rb"].each {|file| require file }
11
12
 
12
13
 
@@ -23,7 +24,7 @@ class Application
23
24
  return Sinatra.new {
24
25
  rests.each {|a| use a}
25
26
  not_found do
26
- JSON RestService.error_response('EntityNotFound')
27
+ JSON RestBase.error_response('EntityNotFound')
27
28
  end
28
29
  }
29
30
  end
@@ -1,7 +1,7 @@
1
1
  require 'diplomat'
2
2
  require_relative '../ioc/injector'
3
3
  require_relative 'consul_configuration'
4
- require_relative '../rest/rest_service'
4
+ require_relative '../rest/rest_base'
5
5
 
6
6
  class ConsulService
7
7
  extend ConsulConfiguration
@@ -22,7 +22,7 @@ class ConsulService
22
22
 
23
23
  # start url for consul to check health
24
24
  consul_check_route = "/" + consul_service_data[:check][:http].split('/').last
25
- RestService.start_consul_check_http(consul_check_route)
25
+ RestBase.start_consul_check_http(consul_check_route)
26
26
  end
27
27
 
28
28
  def stop
@@ -1,4 +1,4 @@
1
- require_relative '../rest/rest_service'
1
+ require_relative '../rest/rest_base'
2
2
  require_relative '../security/security_context_holder'
3
3
 
4
4
  module Authenticator
@@ -1,4 +1,4 @@
1
- require_relative '../rest/rest_service'
1
+ require_relative '../rest/rest_base'
2
2
 
3
3
  module Validator
4
4
  def validate params={}
@@ -0,0 +1,27 @@
1
+ require 'dry-types'
2
+ require 'dry-struct'
3
+ require 'dry-validation'
4
+
5
+ class Model < Dry::Struct
6
+ include Dry::Types.module
7
+ transform_keys(&:to_sym)
8
+
9
+ @@validation_schema
10
+
11
+ def self.validates &blk
12
+ @@validation_schema = Dry::Validation.Schema &blk
13
+ end
14
+
15
+ def validate
16
+ @@validation_schema.call(attributes).inspect
17
+ end
18
+
19
+ def to clazz
20
+ clazz.new attributes
21
+ end
22
+
23
+ def to_json
24
+ attributes
25
+ end
26
+
27
+ end
@@ -25,13 +25,22 @@ class RestApplication < Sinatra::Base
25
25
  end
26
26
  end
27
27
 
28
- class RestService < RestApplication
28
+ class RestBase < RestApplication
29
29
  extend ::RestConfiguration
30
30
  extend ::RestResponseModel
31
31
 
32
32
  before '/*' do
33
- # puts 'before any route ...'
33
+ # puts 'before routes - set local thread'
34
34
  RequestStore.store[:user] = "Nhuan Lai" #get the user by access_token
35
+
36
+ if request.env['CONTENT_TYPE'] == 'application/json'
37
+ body_content = JSON.load(request.body)
38
+ request['body'] = JSON.parse( body_content ) unless body_content.nil?
39
+ end
40
+ end
41
+
42
+ after '/*' do
43
+ response.body = response.body.to_json
35
44
  end
36
45
 
37
46
  # Health Check for Consul, run when start Consul
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blsk_ruby_core_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fusin Thang
@@ -268,11 +268,12 @@ files:
268
268
  - lib/decoractors/valid.rb
269
269
  - lib/ioc/container.rb
270
270
  - lib/ioc/injector.rb
271
+ - lib/model/model.rb
272
+ - lib/rest/rest_base.rb
271
273
  - lib/rest/rest_common_error.rb
272
274
  - lib/rest/rest_configuration.rb
273
275
  - lib/rest/rest_error_handler.rb
274
276
  - lib/rest/rest_response_model.rb
275
- - lib/rest/rest_service.rb
276
277
  - lib/security/security_context_holder.rb
277
278
  homepage: http://rubygems.org/gems/blsk_ruby_core_api
278
279
  licenses: