ruby-ant-server 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/ant.rb +4 -0
- data/lib/ant/client.rb +2 -0
- data/lib/ant/client/format/format.rb +22 -0
- data/lib/ant/client/format/json_format.rb +25 -0
- data/lib/ant/client/format/url_encoded.rb +21 -0
- data/lib/ant/client/format/xml_format.rb +0 -0
- data/lib/ant/client/rest_client.rb +49 -0
- data/lib/ant/client/session/base.rb +29 -0
- data/lib/ant/client/session/basic_auth.rb +11 -0
- data/lib/ant/client/session/ssl_client_certificate.rb +11 -0
- data/lib/ant/client/validator.rb +24 -0
- data/lib/ant/client/validator/jsend.rb +29 -0
- data/lib/ant/client/validator/no_validator.rb +13 -0
- data/lib/ant/dry/daemon.rb +31 -0
- data/lib/ant/dry/resource_injector.rb +63 -0
- data/lib/ant/exceptions.rb +44 -0
- data/lib/ant/server/format.rb +45 -0
- data/lib/ant/server/grape.rb +60 -0
- data/lib/ant/server/logger.rb +42 -0
- data/lib/ant/server/request_response.rb +36 -0
- data/lib/ant/server/response.rb +79 -0
- data/lib/ant/version.rb +3 -0
- metadata +248 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 41ee7dcbdca9427ffd33f13adb474decf81c6dc7a15b6e2737d7bf43bf047183
|
4
|
+
data.tar.gz: 8ae42f2484ab308f7f44856a5dd580c4d10b5711dffb49e9132483ee8eedcf43
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f04d0fb5168cb1834f87f2b4b4d28f48c8e85dc7ab64b594790c6f6790337782f33b78e23c2da01ccfffc313aecb823a2d39dfccbd912ce5781921e7e5a5665d
|
7
|
+
data.tar.gz: 07704b5849e8fb0a3c9a903d49d7d7f16719d1009b4bae03d8a11136013d7b01bfd126afe3a3ee85b9861316ad05a1553dd6f6014d7a09cdb531206a1afce153
|
data/lib/ant.rb
ADDED
data/lib/ant/client.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative 'json_format'
|
2
|
+
require_relative 'url_encoded'
|
3
|
+
|
4
|
+
module Ant
|
5
|
+
module Client
|
6
|
+
module Format
|
7
|
+
class << self
|
8
|
+
def build(config)
|
9
|
+
@formats ||= default_formats
|
10
|
+
@formats[config[:format]].new
|
11
|
+
end
|
12
|
+
|
13
|
+
def default_formats
|
14
|
+
{
|
15
|
+
json: JSONFormat,
|
16
|
+
url_encoded: URLEncodedFormat
|
17
|
+
}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Ant
|
4
|
+
module Client
|
5
|
+
module Format
|
6
|
+
class JSONFormat
|
7
|
+
def pack(data)
|
8
|
+
{
|
9
|
+
body: data.to_json,
|
10
|
+
headers: { 'Content-type' => 'application/json; charset=UTF-8',
|
11
|
+
'User-Agent' => 'Ruby Ant Client' }
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def unpack(data)
|
16
|
+
unformat(data.body)
|
17
|
+
end
|
18
|
+
|
19
|
+
def unformat(msg)
|
20
|
+
JSON.parse(msg, symbolize_names: true)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative 'json_format'
|
2
|
+
|
3
|
+
module Ant
|
4
|
+
module Client
|
5
|
+
module Format
|
6
|
+
class URLEncodedFormat < JSONFormat
|
7
|
+
def pack(data)
|
8
|
+
{
|
9
|
+
body: encode(data),
|
10
|
+
headers: { 'Content-type' =>
|
11
|
+
'application/x-www-form-urlencoded; charset=UTF-8' }
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def encode(data)
|
16
|
+
data.map { |k, v| "#{k}=#{v}" }.join('&')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
File without changes
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
require_relative 'session/base'
|
4
|
+
require_relative 'format/format'
|
5
|
+
require_relative 'validator'
|
6
|
+
|
7
|
+
module Ant
|
8
|
+
module Client
|
9
|
+
class RESTClient
|
10
|
+
def initialize(configs)
|
11
|
+
@session = Session.build(configs)
|
12
|
+
@config = configs
|
13
|
+
@format = Format.build(configs)
|
14
|
+
@endpoint = configs[:endpoint]
|
15
|
+
@validator = Validator.build(configs)
|
16
|
+
end
|
17
|
+
|
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
|
+
private
|
39
|
+
|
40
|
+
def perform_request(method, path, data)
|
41
|
+
log_debug('Performing request', method: method, path: path, data: data)
|
42
|
+
result = @session.perform_request(method, "#{@endpoint}#{path}",
|
43
|
+
@format.pack(data))
|
44
|
+
unpacked = @format.unpack(result)
|
45
|
+
@validator.validate(unpacked)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require_relative 'basic_auth'
|
3
|
+
|
4
|
+
module Ant
|
5
|
+
module Client
|
6
|
+
module Session
|
7
|
+
def self.build(config)
|
8
|
+
Base.new(config)
|
9
|
+
end
|
10
|
+
|
11
|
+
class Base
|
12
|
+
include HTTParty
|
13
|
+
include BasicAuth
|
14
|
+
def initialize(config)
|
15
|
+
@config = config
|
16
|
+
end
|
17
|
+
|
18
|
+
def configure_request(request)
|
19
|
+
basic_auth(request, @config[:basic_auth]) if @config[:basic_auth]
|
20
|
+
end
|
21
|
+
|
22
|
+
def perform_request(method, endpoint, data)
|
23
|
+
configure_request(data)
|
24
|
+
self.class.send(method, endpoint, data)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'validator/jsend'
|
2
|
+
require_relative 'validator/no_validator'
|
3
|
+
|
4
|
+
module Ant
|
5
|
+
module Client
|
6
|
+
module Validator
|
7
|
+
class << self
|
8
|
+
def build(config)
|
9
|
+
config[:validator] ||= :none
|
10
|
+
@validators ||= default_validators
|
11
|
+
@validators[config[:validator]].new
|
12
|
+
end
|
13
|
+
|
14
|
+
def default_validators
|
15
|
+
{
|
16
|
+
jsend: JSend,
|
17
|
+
empty: NoValidator,
|
18
|
+
none: NoValidator
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'ant'
|
2
|
+
module Ant
|
3
|
+
module Client
|
4
|
+
module Validator
|
5
|
+
class JSend
|
6
|
+
include Ant::Exceptions
|
7
|
+
EXCEPTION_LIST = {
|
8
|
+
'fail' => AntFail,
|
9
|
+
'error' => AntError,
|
10
|
+
'fatal' => AntError
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
def validate(response)
|
14
|
+
case response[:status]
|
15
|
+
when 'success'
|
16
|
+
response[:data]
|
17
|
+
when 'fail', 'error', 'fatal'
|
18
|
+
exception_klass = EXCEPTION_LIST[response[:status]]
|
19
|
+
raise exception_klass.new(response[:message],
|
20
|
+
response[:code],
|
21
|
+
response[:data])
|
22
|
+
else
|
23
|
+
raise(AntError, 'Unknown Error')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,31 @@
|
|
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
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Ant
|
2
|
+
module DRY
|
3
|
+
##
|
4
|
+
# Provides a method for sending external dependencies
|
5
|
+
# to classes, like database connections, configurations,
|
6
|
+
# and other objects that can vary but does not modify
|
7
|
+
# the class functionality.
|
8
|
+
# This class works a decorator to be just extended
|
9
|
+
# by classes
|
10
|
+
#
|
11
|
+
# class Controller
|
12
|
+
# extend ResourceInjector
|
13
|
+
# end
|
14
|
+
module ResourceInjector
|
15
|
+
# Initialices the resources value and returns the object.
|
16
|
+
# This method should not be used from the out context.
|
17
|
+
# Resources are grouped by key
|
18
|
+
def resources(key)
|
19
|
+
@resources ||= {}
|
20
|
+
@resources[key] ||= {}
|
21
|
+
@resources[key]
|
22
|
+
end
|
23
|
+
|
24
|
+
# Provides the interface for sending objects inside the class.
|
25
|
+
# The resources have a group and sub group.
|
26
|
+
# When no group is given, it will be added to the :root group
|
27
|
+
# ==== Examples
|
28
|
+
# Controller.inject(:magic_number, 42)
|
29
|
+
# Controller.inject(:databases, :database_conection, Sequel.connect)
|
30
|
+
def register(key, subkey, value = nil)
|
31
|
+
if value.nil?
|
32
|
+
value = subkey
|
33
|
+
subkey = key
|
34
|
+
key = :root
|
35
|
+
end
|
36
|
+
resources(key)[subkey] = value
|
37
|
+
end
|
38
|
+
|
39
|
+
# Provides the inside interface for fetching the objects that were
|
40
|
+
# previously provided from the external world.
|
41
|
+
# Also, when no subgroup is given, the key is fetched from :root
|
42
|
+
# ==== Examples
|
43
|
+
# class Controller
|
44
|
+
# def initialize
|
45
|
+
# @magic_number = self.class.resource(:magic_number)
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# def self.factory(id)
|
49
|
+
# db = resource(:databases, :database_conection)
|
50
|
+
# end
|
51
|
+
# end
|
52
|
+
def resource(key, subkey = nil)
|
53
|
+
if subkey.nil?
|
54
|
+
subkey = key
|
55
|
+
key = :root
|
56
|
+
end
|
57
|
+
res = resources(key)[subkey]
|
58
|
+
raise("Resource `#{key}::#{subkey}` Not Found") if res.nil?
|
59
|
+
res
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Ant
|
2
|
+
module Exceptions
|
3
|
+
##
|
4
|
+
# Exception used as standard error on this gem.
|
5
|
+
# @param message. This param is meant to be read by another developer
|
6
|
+
# It would be nice if the message were self descriptive
|
7
|
+
# enough so the developer won't need to ask the creator
|
8
|
+
# of the app for help.
|
9
|
+
# @param code. The code is similar to message, but for this case
|
10
|
+
# it is meant to be used for the program to handle
|
11
|
+
# exceptions and to make easier to identify the exception..
|
12
|
+
# The default is the exception class, so it won't change
|
13
|
+
# almost never.
|
14
|
+
# @param data. Contains additional data to detail the error.
|
15
|
+
class AntBaseException < StandardError
|
16
|
+
attr_reader :message, :code, :data
|
17
|
+
def initialize(message, code, data)
|
18
|
+
@message = message
|
19
|
+
@code = code
|
20
|
+
@data = data
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Is used to express a problem with the client's request.
|
26
|
+
class AntFail < AntBaseException
|
27
|
+
def initialize(message, code = nil, data = {})
|
28
|
+
code ||= self.class.name.split('::').last
|
29
|
+
super(message, code, data)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Is used to express an error that was found during the execution of the
|
35
|
+
# program but it also means that the invoked endpoint has not the power to
|
36
|
+
# fix it, so it will only complain.
|
37
|
+
class AntError < AntBaseException
|
38
|
+
def initialize(message, code = nil, data = {})
|
39
|
+
code ||= self.class.name.split('::').last
|
40
|
+
super(message, code, data)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ant
|
4
|
+
module Server
|
5
|
+
##
|
6
|
+
# See Exceptions module, since this is based on the exceptions too.
|
7
|
+
# This will wrap a json object into a standard format, where the response
|
8
|
+
# will contain some metadata about the status of the request
|
9
|
+
class Format
|
10
|
+
INTERNAL_SERVER_ERROR_CODE = 'INTERNAL_SERVER_ERROR'.freeze
|
11
|
+
INTERNAL_SERVER_ERROR_MESSAGE = 'Unexpected error ocurred!'.freeze
|
12
|
+
##
|
13
|
+
# success means there were no errors during the execution of the request
|
14
|
+
# it sends the result in the data field.
|
15
|
+
def success(response)
|
16
|
+
{ status: :success, data: response.result }
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# an error on the request. It gives the details of the error.
|
21
|
+
def fail(response)
|
22
|
+
error_format(:fail, response.code, response.message, response.data)
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# an error found while resolving the request.
|
27
|
+
def error(response)
|
28
|
+
error_format(:error, response.code, response.message, response.data)
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# an unhandled error ocurred during the execution of the request.
|
33
|
+
def fatal(_data)
|
34
|
+
error_format(:fatal, INTERNAL_SERVER_ERROR_CODE,
|
35
|
+
INTERNAL_SERVER_ERROR_MESSAGE, {})
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# helper to sumarize fatal and error status
|
40
|
+
def error_format(level, code, message, data)
|
41
|
+
{ status: level, code: code, message: message, data: data }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Ant
|
2
|
+
module Server
|
3
|
+
module GrapeDecorator
|
4
|
+
def self.handler
|
5
|
+
lambda do |env, level, ex|
|
6
|
+
params = env['api.endpoint'].params
|
7
|
+
request = env['api.endpoint'].request
|
8
|
+
pkg = RequestResponse.new(request: request, params: params)
|
9
|
+
pkg.exception = ex
|
10
|
+
Server::Response.logger.send(level, pkg)
|
11
|
+
Server::Response.format.send(level, pkg)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
HTTP_CODES = {
|
16
|
+
success: 200, fail: 400, error: 500, fatal: 500
|
17
|
+
}.freeze
|
18
|
+
|
19
|
+
def self.extract_http_code(exception, level)
|
20
|
+
default = HTTP_CODES[level] || 500
|
21
|
+
exception.respond_to?(:http_code) ? exception.http_code : default
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.configure_handlers(base)
|
25
|
+
Server::Response.resources(:exceptions).each do |exception_class, level|
|
26
|
+
base.rescue_from(exception_class) do |ex|
|
27
|
+
response = Ant::Server::GrapeDecorator.handler.call(env, level, ex)
|
28
|
+
http_code = Ant::Server::GrapeDecorator.extract_http_code(ex, level)
|
29
|
+
error!(response, http_code)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
base.rescue_from(:all) do |ex|
|
33
|
+
level = :fatal
|
34
|
+
response = Ant::Server::GrapeDecorator.handler.call(env, level, ex)
|
35
|
+
http_code = Ant::Server::GrapeDecorator.extract_http_code(ex, level)
|
36
|
+
error!(response, http_code)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.included(base)
|
41
|
+
base.formatter(:json, lambda do |response, _|
|
42
|
+
pkg = RequestResponse.new(request: {}, params: {})
|
43
|
+
pkg.result = response
|
44
|
+
Server::Response.format.send(:success, pkg).to_json
|
45
|
+
end)
|
46
|
+
configure_logger(base)
|
47
|
+
configure_handlers(base)
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.configure_logger(base)
|
51
|
+
base.after do
|
52
|
+
params = env['api.endpoint'].params
|
53
|
+
request = env['api.endpoint'].request
|
54
|
+
pkg = RequestResponse.new(request: request, params: params)
|
55
|
+
Server::Response.logger.access(pkg)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'cute_logger'
|
2
|
+
module Ant
|
3
|
+
module Server
|
4
|
+
class CuteLogger
|
5
|
+
def access_data(response)
|
6
|
+
{
|
7
|
+
path: response.path,
|
8
|
+
ip: response.ip,
|
9
|
+
verb: response.verb
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def access(response)
|
14
|
+
log_info('Requesting resource', access_data(response))
|
15
|
+
end
|
16
|
+
|
17
|
+
def success(response)
|
18
|
+
log_info('Success request', access_data(response))
|
19
|
+
end
|
20
|
+
|
21
|
+
def fail(response)
|
22
|
+
log_info('Fail Response',
|
23
|
+
access_data(response)
|
24
|
+
.merge(message: response.exception.message))
|
25
|
+
end
|
26
|
+
|
27
|
+
def error(response)
|
28
|
+
log_warn('Error dectected on response', access_data(response).merge(
|
29
|
+
error: response.exception
|
30
|
+
))
|
31
|
+
end
|
32
|
+
|
33
|
+
def fatal(response)
|
34
|
+
log_error('Unexpected error on response',
|
35
|
+
access_data(response).merge(
|
36
|
+
error: response.exception,
|
37
|
+
data: response.params
|
38
|
+
))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Ant
|
2
|
+
module Server
|
3
|
+
class RequestResponse
|
4
|
+
attr_reader :params, :exception, :result
|
5
|
+
attr_writer :exception, :result
|
6
|
+
def initialize(request:, params:)
|
7
|
+
@request = request
|
8
|
+
@params = params
|
9
|
+
end
|
10
|
+
|
11
|
+
def data
|
12
|
+
@exception.data
|
13
|
+
end
|
14
|
+
|
15
|
+
def code
|
16
|
+
@exception.code
|
17
|
+
end
|
18
|
+
|
19
|
+
def verb
|
20
|
+
@request.request_method
|
21
|
+
end
|
22
|
+
|
23
|
+
def ip
|
24
|
+
@request.ip
|
25
|
+
end
|
26
|
+
|
27
|
+
def message
|
28
|
+
@exception.message
|
29
|
+
end
|
30
|
+
|
31
|
+
def path
|
32
|
+
@request.url
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require_relative '../exceptions'
|
2
|
+
require_relative '../dry/resource_injector'
|
3
|
+
require_relative 'format'
|
4
|
+
require_relative 'logger'
|
5
|
+
require_relative 'request_response'
|
6
|
+
|
7
|
+
module Ant
|
8
|
+
module Server
|
9
|
+
##
|
10
|
+
# This module provides a function to wrap lambdas arround grape/sinatra
|
11
|
+
# You can mount this module as helper in your application and wrap the block
|
12
|
+
# with the method `process_request`
|
13
|
+
module Response
|
14
|
+
include Exceptions
|
15
|
+
extend DRY::ResourceInjector
|
16
|
+
|
17
|
+
class << self
|
18
|
+
attr_reader :logger, :format
|
19
|
+
|
20
|
+
def log_mode(mode)
|
21
|
+
@logger = resource(:loggers, mode)
|
22
|
+
end
|
23
|
+
|
24
|
+
def format_mode(mode)
|
25
|
+
@format = resource(:formats, mode)
|
26
|
+
end
|
27
|
+
|
28
|
+
def recover_from!(exception_class, level)
|
29
|
+
register(:exceptions, exception_class, level)
|
30
|
+
end
|
31
|
+
|
32
|
+
def configure_defaults!
|
33
|
+
recover_from!(Exceptions::AntFail, :fail)
|
34
|
+
recover_from!(Exceptions::AntError, :error)
|
35
|
+
register(:loggers, :cute_logger, Server::CuteLogger.new)
|
36
|
+
register(:formats, :jsend, Server::Format.new)
|
37
|
+
log_mode(:cute_logger)
|
38
|
+
format_mode(:jsend)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def exception_handler(exception)
|
43
|
+
Server::Response.resources(:exceptions).each do |klass, recover|
|
44
|
+
return recover if exception.is_a?(klass)
|
45
|
+
end
|
46
|
+
exception.is_a?(StandardError) ? :fatal : nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def handle(resolver, data)
|
50
|
+
if resolver
|
51
|
+
Server::Response.logger.send(resolver, data)
|
52
|
+
Server::Response.format.send(resolver, data)
|
53
|
+
else
|
54
|
+
Server::Response.logger.fatal(data)
|
55
|
+
raise(data.exception)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def process_request
|
60
|
+
data = RequestResponse.new(request: request, params: params)
|
61
|
+
resolver = :success
|
62
|
+
Server::Response.logger.access(data)
|
63
|
+
begin
|
64
|
+
raise(AntError, 'No implementation given') unless block_given?
|
65
|
+
data.result = yield
|
66
|
+
# rubocop: disable RescueException
|
67
|
+
rescue Exception => ex
|
68
|
+
# rubocop: enable RescueException
|
69
|
+
data.exception = ex
|
70
|
+
resolver = exception_handler(ex)
|
71
|
+
end
|
72
|
+
handle(resolver, data)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Allow backwards compatibility
|
79
|
+
Ant::Server::Response.configure_defaults!
|
data/lib/ant/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,248 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-ant-server
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gilberto Vargas
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cute_logger
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: grape
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: httparty
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '5.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '5.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.10'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.10'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: puma
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rack
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rack-minitest
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rake
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '10.0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '10.0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rdoc
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: simplecov
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: webmock
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
description: This gems can be used along a server app with jsonformat messages
|
196
|
+
email:
|
197
|
+
- tachoguitar@gmail.com
|
198
|
+
executables: []
|
199
|
+
extensions: []
|
200
|
+
extra_rdoc_files: []
|
201
|
+
files:
|
202
|
+
- lib/ant.rb
|
203
|
+
- lib/ant/client.rb
|
204
|
+
- lib/ant/client/format/format.rb
|
205
|
+
- lib/ant/client/format/json_format.rb
|
206
|
+
- lib/ant/client/format/url_encoded.rb
|
207
|
+
- lib/ant/client/format/xml_format.rb
|
208
|
+
- lib/ant/client/rest_client.rb
|
209
|
+
- lib/ant/client/session/base.rb
|
210
|
+
- lib/ant/client/session/basic_auth.rb
|
211
|
+
- lib/ant/client/session/ssl_client_certificate.rb
|
212
|
+
- lib/ant/client/validator.rb
|
213
|
+
- lib/ant/client/validator/jsend.rb
|
214
|
+
- lib/ant/client/validator/no_validator.rb
|
215
|
+
- lib/ant/dry/daemon.rb
|
216
|
+
- lib/ant/dry/resource_injector.rb
|
217
|
+
- lib/ant/exceptions.rb
|
218
|
+
- lib/ant/server/format.rb
|
219
|
+
- lib/ant/server/grape.rb
|
220
|
+
- lib/ant/server/logger.rb
|
221
|
+
- lib/ant/server/request_response.rb
|
222
|
+
- lib/ant/server/response.rb
|
223
|
+
- lib/ant/version.rb
|
224
|
+
homepage: https://github.com/KueskiEngineering/ruby-ant-server
|
225
|
+
licenses:
|
226
|
+
- MIT
|
227
|
+
metadata: {}
|
228
|
+
post_install_message:
|
229
|
+
rdoc_options: []
|
230
|
+
require_paths:
|
231
|
+
- lib
|
232
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - ">="
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0'
|
237
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
238
|
+
requirements:
|
239
|
+
- - ">="
|
240
|
+
- !ruby/object:Gem::Version
|
241
|
+
version: '0'
|
242
|
+
requirements: []
|
243
|
+
rubyforge_project:
|
244
|
+
rubygems_version: 2.7.3
|
245
|
+
signing_key:
|
246
|
+
specification_version: 4
|
247
|
+
summary: Implements ANT format on server applications
|
248
|
+
test_files: []
|