ruby-ant-server 0.7.1 → 0.7.2

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: 67b68263025555b3e1ee19ebf348e454c12fa5f193d087894c7681be696b6e5c
4
- data.tar.gz: 20f48f6e38ae463cb8bcc20052ebcc0317a2968e06d6e382d83fb118fc3f60dd
3
+ metadata.gz: c23b274800913526c9bd21f3d5153f7cdaa8c1ccbee688a0a9627eaa0d58775f
4
+ data.tar.gz: 904bca95ee34e8d6187b827e8dc46f009b4b409fb1355554929223481aa67b84
5
5
  SHA512:
6
- metadata.gz: 469da9f77d2224962e8bf2781e819d44beac795534838cb8a1858df483403c61cdd785414c915e8e4e5e0b597d150a089f82a1873986c8d781e249f2d236f2bd
7
- data.tar.gz: e5a29afcfab0acd598bdf60525053afbc6f025ceeb1d2b8937bdae1c3b8f566d9f89d3a33cf8ca42b2f05207dbddca8e5d79a9b12161e24a634472992b29a21f
6
+ metadata.gz: 5c209c719b33be8784cf1efb21d0dd6afab10f454813d2c93d19bc64949d461f523178ebcccfd06870c81b248e03d7f9b1847e0f9e18b620641365258b7cc7f2
7
+ data.tar.gz: d393682d18ad69334e804810296b7471c25080e7bb3687984569da6a8c57934ec9146c94778d3e55aa8687258be87d2a80d9314c6a7a44b9c2f0dc1a216a2208
@@ -15,29 +15,52 @@ module Ant
15
15
  @validator = Validator.build(configs)
16
16
  end
17
17
 
18
- %w[get post put delete patch].each do |method|
19
- define_method method do |path, data = {}|
20
- perform_request(method.to_sym, path, data)
21
- end
18
+ def get(path, data = {})
19
+ perform_request(:get, path, data)
20
+ end
21
+
22
+ def post(path, data = {})
23
+ perform_request(:post, path, data)
24
+ end
25
+
26
+ def put(path, data = {})
27
+ perform_request(:put, path, data)
28
+ end
29
+
30
+ def delete(path, data = {})
31
+ perform_request(:delete, path, data)
32
+ end
33
+
34
+ def patch(path, data = {})
35
+ perform_request(:patch, path, data)
36
+ end
37
+
38
+ def raw_get(path, data = {})
39
+ perform_raw_request(:get, path, data)
40
+ end
22
41
 
23
- define_method "raw_#{method}" do |path, data = {}|
24
- raw_request(method.to_sym, path, data)
25
- end
42
+ def raw_post(path, data = {})
43
+ perform_raw_request(:post, path, data)
26
44
  end
27
45
 
28
46
  private
29
47
 
30
- def raw_request(method, path, data)
48
+ def perform_raw_request(method, path, data)
31
49
  log_debug('Performing request', method: method, path: path, data: data)
32
- @session.perform_request(
33
- method,
34
- "#{@endpoint}#{path}",
35
- @format.pack(data)
36
- )
50
+ init_time = Time.now
51
+ uri = (path.start_with?('http') ? path : "#{@endpoint}#{path}")
52
+ result = @session.perform_request(method, uri,
53
+ @format.pack(data))
54
+ log_info('Request perfomed',
55
+ path: path,
56
+ server: @endpoint,
57
+ verb: method,
58
+ processing_time: (Time.now - init_time).to_f * 1000)
59
+ result
37
60
  end
38
61
 
39
62
  def perform_request(method, path, data)
40
- result = raw_request(method, path, data)
63
+ result = perform_raw_request(method, path, data)
41
64
  unpacked = @format.unpack(result)
42
65
  @validator.validate(unpacked)
43
66
  end
@@ -33,7 +33,6 @@ module Ant
33
33
  def configure_request(request)
34
34
  basic_auth(request, @config[:basic_auth]) if @config[:basic_auth]
35
35
  request[:verify] = @config[:verify] if @config.key?(:verify)
36
-
37
36
  end
38
37
 
39
38
  def perform_request(method, endpoint, data)
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ # TODO: Comming soon!
4
+
5
+ require 'ant/dry/resource_injector'
6
+
7
+ module Ant
8
+ module Configuration
9
+ # Allow to autoload configurations into ruby.
10
+ # It allows to implement new plugins.
11
+ class ServiceManager
12
+ extend Ant::DRY::ResourceInjector
13
+ def initialize(configs)
14
+ @configs = configs
15
+ end
16
+
17
+ def register_plugin(name); end
18
+ end
19
+ end
20
+ end
@@ -54,6 +54,9 @@ module Ant
54
54
  end
55
55
 
56
56
  def self.configure_logger(base)
57
+ base.before do
58
+ params[:__init_time] = Time.now
59
+ end
57
60
  base.after do
58
61
  params = env['api.endpoint'].params
59
62
  request = env['api.endpoint'].request
@@ -6,7 +6,8 @@ module Ant
6
6
  {
7
7
  path: response.path,
8
8
  ip: response.ip,
9
- verb: response.verb
9
+ verb: response.verb,
10
+ processing_time: (Time.now - response.params[:__init_time]).to_f * 1000
10
11
  }
11
12
  end
12
13
 
@@ -1,11 +1,12 @@
1
1
  module Ant
2
2
  module Server
3
3
  class RequestResponse
4
- attr_reader :params, :exception, :result
5
- attr_writer :exception, :result
4
+ attr_reader :params, :exception, :result, :start_timestamp
5
+ attr_writer :exception, :result, :start_timestamp
6
6
  def initialize(request:, params:)
7
7
  @request = request
8
8
  @params = params
9
+ @start_timestamp = Time.now
9
10
  end
10
11
 
11
12
  def data
@@ -29,7 +30,7 @@ module Ant
29
30
  end
30
31
 
31
32
  def path
32
- @request.url
33
+ @request.env['PATH_INFO']
33
34
  end
34
35
  end
35
36
  end
@@ -1,3 +1,3 @@
1
1
  module Ant
2
- VERSION = '0.7.1'.freeze
2
+ VERSION = '0.7.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-ant-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gilberto Vargas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-02 00:00:00.000000000 Z
11
+ date: 2019-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cute_logger
@@ -239,7 +239,7 @@ files:
239
239
  - lib/ant/client/validator.rb
240
240
  - lib/ant/client/validator/jsend.rb
241
241
  - lib/ant/client/validator/no_validator.rb
242
- - lib/ant/dry/daemon.rb
242
+ - lib/ant/configs/service_manager.rb
243
243
  - lib/ant/dry/resource_injector.rb
244
244
  - lib/ant/exceptions.rb
245
245
  - lib/ant/http_exceptions.rb
@@ -251,23 +251,15 @@ files:
251
251
  - lib/ant/server/nanoservice/datasource/id_generators.rb
252
252
  - lib/ant/server/nanoservice/datasource/json_repository.rb
253
253
  - lib/ant/server/nanoservice/datasource/model.rb
254
- - lib/ant/server/nanoservice/datasource/mongo.rb
255
254
  - lib/ant/server/nanoservice/datasource/repository.rb
256
255
  - lib/ant/server/nanoservice/datasource/sequel.rb
257
256
  - lib/ant/server/nanoservice/factory.rb
258
- - lib/ant/server/nanoservice/schema.rb
259
- - lib/ant/server/nanoservice/validator.rb
260
- - lib/ant/server/nanoservice/validators/date.rb
261
- - lib/ant/server/nanoservice/validators/numeric.rb
262
- - lib/ant/server/nanoservice/validators/relation.rb
263
- - lib/ant/server/nanoservice/validators/text.rb
264
257
  - lib/ant/server/request_response.rb
265
258
  - lib/ant/server/response.rb
266
259
  - lib/ant/ssl.rb
267
260
  - lib/ant/ssl/certificate.rb
268
261
  - lib/ant/ssl/configuration.rb
269
262
  - lib/ant/ssl/inventory.rb
270
- - lib/ant/ssl/revocation_list.rb
271
263
  - lib/ant/version.rb
272
264
  homepage: https://github.com/KueskiEngineering/ruby-ant-server
273
265
  licenses:
@@ -1,31 +0,0 @@
1
- module Ant
2
- module DRY
3
- class Daemon
4
- def initialize(wait_time, attach, proc)
5
- @proc = proc
6
- @wait_time = wait_time
7
- @attach = attach
8
- @finish = false
9
- end
10
-
11
- def task
12
- loop do
13
- begin
14
- @proc.exec
15
- rescue StandarError => ex
16
- log_error('Unexpected error', error: ex)
17
- end
18
- sleep(@wait_time)
19
- end
20
- end
21
-
22
- def run
23
- if @attach
24
- task
25
- else
26
- Thread.new(&:task)
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,15 +0,0 @@
1
- class Schema
2
- def initialize
3
- @fields = []
4
- @constraints = []
5
- end
6
-
7
- def add_column(options)
8
- end
9
-
10
- def generate_sequel_migration
11
- end
12
-
13
- def validate(data)
14
- end
15
- end
File without changes
@@ -1,7 +0,0 @@
1
- module Ant
2
- module SSL
3
- class Configuration
4
-
5
- end
6
- end
7
- end