apia 3.0.3 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/apia/argument_set.rb +7 -0
- data/lib/apia/notifications.rb +29 -0
- data/lib/apia/rack.rb +11 -1
- data/lib/apia/request.rb +3 -1
- 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: e5db442aede360ce867a790d610a1fd52ca99149fae66d7122d18061cb2ac389
|
4
|
+
data.tar.gz: 30d3c64645a15f11b6e2d96326e987f31b0623e500a56c49194e80589e7303d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70b9295d1b016210832c30b2d233683efa045797c5113e80bd959dfa6a6888c414f3a60e01ded946f63d50d51cd79cdae58514c2d8b483bfec29be71a89b83bd
|
7
|
+
data.tar.gz: af2fa9e9322ed357a2074336a2e536d8ebb3c955692bd1b6a85812fe788fc4d5f19b0b1ecc57ce99c82b118fb7b5024a276d54edbb3560ab594b718c80e88ccd
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0
|
1
|
+
3.1.0
|
data/lib/apia/argument_set.rb
CHANGED
@@ -122,6 +122,13 @@ module Apia
|
|
122
122
|
@source.key?(key.to_sym)
|
123
123
|
end
|
124
124
|
|
125
|
+
# Return whether the argument set has no arguments within?
|
126
|
+
#
|
127
|
+
# @return [Boolean]
|
128
|
+
def empty?
|
129
|
+
@source.empty?
|
130
|
+
end
|
131
|
+
|
125
132
|
# Validate an argument set and return any errors as appropriate
|
126
133
|
#
|
127
134
|
# @param argument [Apia::Argument]
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Apia
|
4
|
+
class Notifications
|
5
|
+
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def handlers
|
9
|
+
@handlers ||= []
|
10
|
+
end
|
11
|
+
|
12
|
+
def notify(event, args = {})
|
13
|
+
handlers.each do |handler|
|
14
|
+
handler.call(event, args)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_handler(&block)
|
19
|
+
handlers.push(block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def clear_handlers
|
23
|
+
@handlers = nil
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/apia/rack.rb
CHANGED
@@ -4,6 +4,7 @@ require 'json'
|
|
4
4
|
require 'apia/rack_error'
|
5
5
|
require 'apia/request'
|
6
6
|
require 'apia/response'
|
7
|
+
require 'apia/notifications'
|
7
8
|
|
8
9
|
module Apia
|
9
10
|
class Rack
|
@@ -91,19 +92,28 @@ module Apia
|
|
91
92
|
request.endpoint = route.endpoint
|
92
93
|
request.route = route
|
93
94
|
|
95
|
+
start_time = Time.now
|
94
96
|
response = request.endpoint.execute(request)
|
97
|
+
end_time = Time.now
|
98
|
+
|
99
|
+
Apia::Notifications.notify(:request, { request: request, response: response, time: (end_time - start_time).to_f })
|
100
|
+
|
95
101
|
response.rack_triplet
|
96
102
|
rescue ::StandardError => e
|
97
103
|
if e.is_a?(RackError) || e.is_a?(Apia::ManifestError)
|
98
104
|
return e.triplet
|
99
105
|
end
|
100
106
|
|
107
|
+
request_or_nil = defined?(request) ? request : nil
|
108
|
+
|
101
109
|
api.definition.exception_handlers.call(e, {
|
102
110
|
env: env,
|
103
111
|
api: api,
|
104
|
-
request:
|
112
|
+
request: request_or_nil
|
105
113
|
})
|
106
114
|
|
115
|
+
Apia::Notifications.notify(:request_error, { exception: e, request: request_or_nil, api: api, env: env })
|
116
|
+
|
107
117
|
if development?
|
108
118
|
return triplet_for_exception(e)
|
109
119
|
end
|
data/lib/apia/request.rb
CHANGED
@@ -50,7 +50,9 @@ module Apia
|
|
50
50
|
def parse_json_from_string(body)
|
51
51
|
return {} if body.empty?
|
52
52
|
|
53
|
-
JSON.parse(body)
|
53
|
+
response = JSON.parse(body)
|
54
|
+
response = {} unless response.is_a?(Hash)
|
55
|
+
response
|
54
56
|
rescue JSON::ParserError => e
|
55
57
|
raise InvalidJSONError, e.message
|
56
58
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Cooke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- lib/apia/lookup_environment.rb
|
117
117
|
- lib/apia/manifest_errors.rb
|
118
118
|
- lib/apia/mock_request.rb
|
119
|
+
- lib/apia/notifications.rb
|
119
120
|
- lib/apia/object.rb
|
120
121
|
- lib/apia/object_set.rb
|
121
122
|
- lib/apia/pagination_object.rb
|