eac_rest 0.9.2 → 0.10.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 +2 -14
- data/lib/eac_rest/entity/data.rb +44 -0
- data/lib/eac_rest/entity/fetching.rb +20 -0
- data/lib/eac_rest/entity.rb +1 -32
- data/lib/eac_rest/helper.rb +34 -0
- data/lib/eac_rest/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fe5757eaf77cd67597c26aa58e150392aa661781cd19123f835aa503dad12fc
|
4
|
+
data.tar.gz: 9982b978e4718a87847522ef9b140a159f36d29379efe85e5c2d7be5c5bd34ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37fc4fd969a082152524de5313b08b9ae9f246b86725da8635365e9487cb6dde875b1aeff87852dd1016d2017b6edc59fadc7b8c4f221a399017be04f43f818b
|
7
|
+
data.tar.gz: 3486088ae1c66584166bae20afe57641eb7f1d4fe5ad27a5441989bc10dd0fd04c439a4effed9f6859b88c9eeced958988c05c8385bdd73e72be706c297b4052
|
data/lib/eac_rest/api.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_rest/helper'
|
3
4
|
require 'eac_rest/request'
|
4
5
|
require 'eac_ruby_utils/core_ext'
|
5
6
|
|
@@ -40,20 +41,7 @@ module EacRest
|
|
40
41
|
|
41
42
|
# @return [Addressable::URI]
|
42
43
|
def build_service_url(suffix)
|
43
|
-
|
44
|
-
return r if r.scheme.present?
|
45
|
-
|
46
|
-
s = build_service_url_suffix(suffix)
|
47
|
-
r = ::Addressable::URI.parse(root_url)
|
48
|
-
r.path += s.path
|
49
|
-
r.query_values = r.query_values(::Array).if_present([]) +
|
50
|
-
s.query_values(::Array).if_present([])
|
51
|
-
r
|
52
|
-
end
|
53
|
-
|
54
|
-
# @return [Addressable::URI]
|
55
|
-
def build_service_url_suffix(suffix)
|
56
|
-
::Addressable::URI.parse(suffix)
|
44
|
+
::EacRest::Helper.url_join(root_url, suffix)
|
57
45
|
end
|
58
46
|
|
59
47
|
# @return [EacRest::Entity]
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacRest
|
6
|
+
class Entity
|
7
|
+
module Data
|
8
|
+
common_concern
|
9
|
+
|
10
|
+
# @return [Hash]
|
11
|
+
def data
|
12
|
+
if internal_data.blank?
|
13
|
+
self.internal_data = data_or_id_data? ? data_or_id : data_from_id
|
14
|
+
end
|
15
|
+
|
16
|
+
internal_data
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Boolean]
|
20
|
+
def data_or_id_data?
|
21
|
+
data_or_id.is_a?(::Hash)
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [Hash]
|
25
|
+
def data_from_id
|
26
|
+
raise_abstract_method __method__
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Object]
|
30
|
+
def id
|
31
|
+
data_or_id_data? ? id_from_data : data_or_id
|
32
|
+
end
|
33
|
+
|
34
|
+
# @return [Object]
|
35
|
+
def id_from_data
|
36
|
+
raise_abstract_method __method__
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
attr_accessor :internal_data
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_rest/helper'
|
4
|
+
require 'eac_ruby_utils/core_ext'
|
5
|
+
|
6
|
+
module EacRest
|
7
|
+
class Entity
|
8
|
+
module Fetching
|
9
|
+
# @return [Addressable::URI]
|
10
|
+
def entity_root_url_suffix
|
11
|
+
parent_entity.if_present('', &:entity_root_url_suffix).to_uri
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [EacRest::Request]
|
15
|
+
def request(url_suffix)
|
16
|
+
api.request(::EacRest::Helper.url_join(entity_root_url_suffix, url_suffix))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/eac_rest/entity.rb
CHANGED
@@ -25,42 +25,11 @@ module EacRest
|
|
25
25
|
api.entity(entity_class, data_or_id, options.merge(OPTION_PARENT => self))
|
26
26
|
end
|
27
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
28
|
# @return [EacRest::Entity, nil]
|
58
29
|
def parent_entity
|
59
30
|
options[OPTION_PARENT]
|
60
31
|
end
|
61
32
|
|
62
|
-
|
63
|
-
|
64
|
-
attr_accessor :internal_data
|
33
|
+
require_sub __FILE__, include_modules: :include
|
65
34
|
end
|
66
35
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacRest
|
6
|
+
module Helper
|
7
|
+
# @param parts [Array<Addressable::URI>]
|
8
|
+
# @return [Addressable::URI]
|
9
|
+
def url_join(*parts)
|
10
|
+
left = parts.shift
|
11
|
+
left = url_join_pair(left, parts.shift) while parts.any?
|
12
|
+
left
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
# @param left [Addressable::URI]
|
18
|
+
# @param right [Addressable::URI]
|
19
|
+
# @return [Addressable::URI]
|
20
|
+
def url_join_pair(left, right)
|
21
|
+
r = ::Addressable::URI.parse(right)
|
22
|
+
return r if r.scheme.present?
|
23
|
+
|
24
|
+
s = ::Addressable::URI.parse(right)
|
25
|
+
r = ::Addressable::URI.parse(left)
|
26
|
+
r.path += s.path
|
27
|
+
r.query_values = r.query_values(::Array).if_present([]) +
|
28
|
+
s.query_values(::Array).if_present([])
|
29
|
+
r
|
30
|
+
end
|
31
|
+
|
32
|
+
extend self
|
33
|
+
end
|
34
|
+
end
|
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.10.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-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eac_envs-http
|
@@ -101,7 +101,10 @@ files:
|
|
101
101
|
- lib/eac_rest.rb
|
102
102
|
- lib/eac_rest/api.rb
|
103
103
|
- lib/eac_rest/entity.rb
|
104
|
+
- lib/eac_rest/entity/data.rb
|
105
|
+
- lib/eac_rest/entity/fetching.rb
|
104
106
|
- lib/eac_rest/error.rb
|
107
|
+
- lib/eac_rest/helper.rb
|
105
108
|
- lib/eac_rest/request.rb
|
106
109
|
- lib/eac_rest/response.rb
|
107
110
|
- lib/eac_rest/version.rb
|