ruby-ant-server 0.6.0 → 0.7.0

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: 6befcf2bfdc8e67ce383fb20467d1b1fd2fd608b0e7beac423aed30d7483a6e0
4
- data.tar.gz: 5420a89f2112d28f28c6e43cba260b2fbf6a525202e36c56544b5ca8a2453ada
3
+ metadata.gz: 200ecdea3b72455302beb4244be0d9131df3795befe6404de52e9b157f99888f
4
+ data.tar.gz: bea79e7e04b6354293f052c305e455903316b8b48e75c0e7508d8d42c59407b6
5
5
  SHA512:
6
- metadata.gz: 3b4644ce8168d792b9acd7275eb8ea1847d3114643f8362ad608582e94cb3630dae3aa8ae8523ffb8026aeabeaa4e92c27f8b620f4259afd9c2d38ee2a9b4d57
7
- data.tar.gz: 883d571e5fe1209590c36cb7c188ce8a4bafd055a0a4552609665d0b98ad4b1c3a9a3410e7b20ba3f94f3628457a5d40a249aea606ef6ef7954e2154f4b9221b
6
+ metadata.gz: 1d0e4a041fdd1a0bb53bd08e586f41914950d4423d0148dd8265fe2f942f9a894402a6c814059d1e05d01f4161a3e792985a200e3b7ec7d47dfaac081d7de821
7
+ data.tar.gz: ab45a3be16ba71ad1738b6ebd2ed16c327535b6f2556a093564118e287ccd8f6d541cd7b1d18efdf59b4d05b9f6b7581e2aa0558538c913b770455c99dccda72
@@ -15,32 +15,29 @@ module Ant
15
15
  @validator = Validator.build(configs)
16
16
  end
17
17
 
18
- def get(path, data = {})
19
- perform_request(:get, path, data)
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
22
+
23
+ define_method "raw_#{method}" do |path, data = {}|
24
+ raw_request(method.to_sym, path, data)
25
+ end
20
26
  end
21
27
 
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
28
+ private
33
29
 
34
- def patch(path, data = {})
35
- perform_request(:patch, path, data)
30
+ def raw_request(method, path, data)
31
+ log_debug('Performing request', method: method, path: path, data: data)
32
+ @session.perform_request(
33
+ method,
34
+ "#{@endpoint}#{path}",
35
+ @format.pack(data)
36
+ )
36
37
  end
37
38
 
38
- private
39
-
40
39
  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))
40
+ result = raw_request(method, path, data)
44
41
  unpacked = @format.unpack(result)
45
42
  @validator.validate(unpacked)
46
43
  end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../exceptions'
4
+
5
+ module Exceptions
6
+ module HTTP
7
+ class << self
8
+ EXCEPTION_TYPES = {
9
+ success: Ant::Exceptions::AntSuccess,
10
+ fail: Ant::Exceptions::AntFail,
11
+ error: Ant::Exceptions::AntError
12
+ }.freeze
13
+
14
+ def new_http_exception(class_name, http_code, type)
15
+ parent = exception_type(type)
16
+ http_exception_class = Class.new(parent) do
17
+ def initialize(message, object = {})
18
+ super(message, nil, object)
19
+ end
20
+
21
+ define_method 'http_code' do
22
+ http_code
23
+ end
24
+ end
25
+
26
+ const_set(class_name, http_exception_class)
27
+ end
28
+
29
+ private
30
+
31
+ def exception_type(type)
32
+ EXCEPTION_TYPES[type.to_sym]
33
+ end
34
+ end
35
+
36
+ http_codes = [
37
+ { code_name: 'Ok', code: 200, type: :success },
38
+ { code_name: 'Created', code: 201, type: :success },
39
+ { code_name: 'Accepted', code: 202, type: :success },
40
+ { code_name: 'NoContent', code: 204, type: :success },
41
+ { code_name: 'BadRequest', code: 400, type: :fail },
42
+ { code_name: 'Unauthorized', code: 401, type: :fail },
43
+ { code_name: 'Forbidden', code: 403, type: :fail },
44
+ { code_name: 'NotFound', code: 404, type: :fail },
45
+ { code_name: 'NotValid', code: 422, type: :fail }
46
+ ]
47
+
48
+ http_codes.each do |code|
49
+ Exceptions::HTTP.new_http_exception(
50
+ code[:code_name],
51
+ code[:code],
52
+ code[:type]
53
+ )
54
+ end
55
+ end
56
+ end
data/lib/ant/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ant
2
- VERSION = '0.6.0'.freeze
2
+ VERSION = '0.7.0'.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.6.0
4
+ version: 0.7.0
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-10-02 00:00:00.000000000 Z
11
+ date: 2018-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cute_logger
@@ -245,6 +245,7 @@ files:
245
245
  - lib/ant/nanoservice.rb
246
246
  - lib/ant/server/format.rb
247
247
  - lib/ant/server/grape.rb
248
+ - lib/ant/server/http_exceptions.rb
248
249
  - lib/ant/server/logger.rb
249
250
  - lib/ant/server/nanoservice/datasource/exceptions.rb
250
251
  - lib/ant/server/nanoservice/datasource/id_generators.rb