eac_rest 0.7.3 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eac_rest/api.rb +19 -0
- data/lib/eac_rest/entity.rb +51 -1
- data/lib/eac_rest/request.rb +4 -2
- data/lib/eac_rest/version.rb +1 -1
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 263dba755fa31847ff76531c4b4282f7dbcde55e1a422746311251d2705b5d07
|
4
|
+
data.tar.gz: b9e606feb6e48a217388a71f261a1b7f134ca21ff576ef87b68807169f96f7f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0848f0ad0b5c2eede6a2c166557caca924d1ae2e73cad1cf54720678a0c4b86fee1e9ed3e1364c2cafa1a1183a7703824eb575b8712988d81cf6bbc6b622abd
|
7
|
+
data.tar.gz: 65674debf48a454b8716e010360fa927e9ecdb86471539e20865dad151de462562ce3e07ec5f5aeb03819974b44b41a62a9cc41d311c1f91aeaddfbf6b8e9368
|
data/lib/eac_rest/api.rb
CHANGED
@@ -7,12 +7,21 @@ module EacRest
|
|
7
7
|
# Abstract methods
|
8
8
|
# * self.issue_get_url_suffix(provider_issue_id)
|
9
9
|
class Api
|
10
|
+
DEFAULT_ROOT_ENTITY_CLASS_NAME_SUFFIX = 'Root'
|
11
|
+
|
10
12
|
require_sub __FILE__, include_modules: true
|
11
13
|
attr_accessor :ssl_verify
|
12
14
|
common_constructor :root_url, :username, :password, default: [nil, nil] do
|
13
15
|
self.ssl_verify = true
|
14
16
|
end
|
15
17
|
|
18
|
+
# @param entity_class [Class]
|
19
|
+
# @param url_suffix [String]
|
20
|
+
# @return [EacRest::Entity]
|
21
|
+
def entity(entity_class, data_or_id, options = {})
|
22
|
+
entity_class.new(self, data_or_id, options)
|
23
|
+
end
|
24
|
+
|
16
25
|
def request(service_url_suffix, headers = {}, &body_data_proc)
|
17
26
|
r = ::EacRest::Request.new(build_service_url(service_url_suffix),
|
18
27
|
body_data_proc).ssl_verify(ssl_verify)
|
@@ -46,5 +55,15 @@ module EacRest
|
|
46
55
|
def build_service_url_suffix(suffix)
|
47
56
|
::Addressable::URI.parse(suffix)
|
48
57
|
end
|
58
|
+
|
59
|
+
# @return [EacRest::Entity]
|
60
|
+
def root_entity
|
61
|
+
@root_entity ||= root_entity_class.new(self, nil)
|
62
|
+
end
|
63
|
+
|
64
|
+
# @return [Class]
|
65
|
+
def root_entity_class
|
66
|
+
self.class.const_get(DEFAULT_ROOT_ENTITY_CLASS_NAME_SUFFIX)
|
67
|
+
end
|
49
68
|
end
|
50
69
|
end
|
data/lib/eac_rest/entity.rb
CHANGED
@@ -4,13 +4,63 @@ require 'eac_ruby_utils/core_ext'
|
|
4
4
|
|
5
5
|
module EacRest
|
6
6
|
class Entity
|
7
|
+
enable_abstract_methods
|
7
8
|
enable_simple_cache
|
8
|
-
|
9
|
+
enable_listable
|
10
|
+
lists.add_symbol :option, :parent
|
11
|
+
common_constructor :api, :data_or_id, :options, default: [{}] do
|
12
|
+
self.options = ::EacRest::Entity.lists.option.hash_keys_validate!(options)
|
13
|
+
end
|
9
14
|
|
10
15
|
class << self
|
11
16
|
def from_array_data(api, array_data, *args)
|
12
17
|
array_data.map { |item_data| new(api, item_data, *args) }
|
13
18
|
end
|
14
19
|
end
|
20
|
+
|
21
|
+
# @param entity_class [Class]
|
22
|
+
# @param url_suffix [String]
|
23
|
+
# @return [EacRest::Entity]
|
24
|
+
def child_entity(entity_class, data_or_id, options = {})
|
25
|
+
api.entity(entity_class, data_or_id, options.merge(OPTION_PARENT => self))
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [Hash]
|
29
|
+
def data
|
30
|
+
if internal_data.blank?
|
31
|
+
self.internal_data = data_or_id_data? ? data_or_id : data_from_id
|
32
|
+
end
|
33
|
+
|
34
|
+
internal_data
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [Boolean]
|
38
|
+
def data_or_id_data?
|
39
|
+
data_or_id.is_a?(::Hash)
|
40
|
+
end
|
41
|
+
|
42
|
+
# @return [Hash]
|
43
|
+
def data_from_id
|
44
|
+
raise_abstract_method __method__
|
45
|
+
end
|
46
|
+
|
47
|
+
# @return [Object]
|
48
|
+
def id
|
49
|
+
data_or_id_data? ? id_from_data : data_or_id
|
50
|
+
end
|
51
|
+
|
52
|
+
# @return [Object]
|
53
|
+
def id_from_data
|
54
|
+
raise_abstract_method __method__
|
55
|
+
end
|
56
|
+
|
57
|
+
# @return [EacRest::Entity, nil]
|
58
|
+
def parent_entity
|
59
|
+
options[OPTION_PARENT]
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
attr_accessor :internal_data
|
15
65
|
end
|
16
66
|
end
|
data/lib/eac_rest/request.rb
CHANGED
@@ -15,11 +15,13 @@ module EacRest
|
|
15
15
|
@internal_request = url
|
16
16
|
else
|
17
17
|
@internal_request = ::EacEnvs::Http::Request.new.url(url)
|
18
|
-
response_body_data_proc.if_present
|
18
|
+
response_body_data_proc.if_present do |v|
|
19
|
+
@internal_request = @internal_request.response_body_data_proc(v)
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
22
|
-
delegate :sanitized_verb, to: :internal_request
|
24
|
+
delegate :sanitized_verb, :url, to: :internal_request
|
23
25
|
|
24
26
|
{
|
25
27
|
auth: 0, body_data: 0, header: 1, headers: 0, ssl_verify: 0, verb: 0
|
data/lib/eac_rest/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eac_rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo H. Bogoni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eac_envs-http
|
@@ -16,14 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.3'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.3.1
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
29
|
+
version: '0.3'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.3.1
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: eac_fs
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|