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 +4 -4
- data/lib/blsk_ruby_core_api.rb +3 -2
- data/lib/consul/consul_service.rb +2 -2
- data/lib/decoractors/authenticate.rb +1 -1
- data/lib/decoractors/valid.rb +1 -1
- data/lib/model/model.rb +27 -0
- data/lib/rest/{rest_service.rb → rest_base.rb} +11 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3f4ebf6047ba0f37b3f1ae6512335e7332c5448f1425fe078ae10d69f175b6b
|
4
|
+
data.tar.gz: cbc8dc774fcac8b621b16e5eb439ab821a17c62c5c485bb04a3d4db256065cd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 54a7e52ef9610661491cf95ee294dd53738623802d7a776b86e0122a28d0b2662696d53dc4350c9f54b670ee9a520fa6ee47abb1a51ccc083c9a78935d1cbb1e
|
7
|
+
data.tar.gz: c6a0c1121d35afbd75ad2fb9fefb9b6d08b36d5472b08f14407e66db8cf0fe567b2d42b24d5bb329cf28110bde2d73c1c6021e936e0f962adf24ca053a636bb6
|
data/lib/blsk_ruby_core_api.rb
CHANGED
@@ -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/
|
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
|
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/
|
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
|
-
|
25
|
+
RestBase.start_consul_check_http(consul_check_route)
|
26
26
|
end
|
27
27
|
|
28
28
|
def stop
|
data/lib/decoractors/valid.rb
CHANGED
data/lib/model/model.rb
ADDED
@@ -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
|
28
|
+
class RestBase < RestApplication
|
29
29
|
extend ::RestConfiguration
|
30
30
|
extend ::RestResponseModel
|
31
31
|
|
32
32
|
before '/*' do
|
33
|
-
# puts 'before
|
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
|
+
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:
|