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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 945584092ca9aed7a69937868f4d63f064372e74315c359f43d1fb8d6ec23546
4
- data.tar.gz: 44353ff6d28eb8515f75b79bf7a6b6e2eee0c8be20ff5866a45395ffe3e339a2
3
+ metadata.gz: 0fe5757eaf77cd67597c26aa58e150392aa661781cd19123f835aa503dad12fc
4
+ data.tar.gz: 9982b978e4718a87847522ef9b140a159f36d29379efe85e5c2d7be5c5bd34ca
5
5
  SHA512:
6
- metadata.gz: ffa21fcadef6f88f12f549b23cc8b844c4d8bda459e7e1e2d8824ae1ff137ae5ff55fa84b713da8e2d5e2652acc46eb41f22d0c7bf444833c5a47b641e5b8898
7
- data.tar.gz: e7828dd79341ea1b2af6002e4ae2d1420ab79a514c9b687f4cd0f64540f3ccd85f5596dcb3a8dac80d19b2971c80eebbe3e19aa055943386dc04aeee5f0ef8b0
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
- r = ::Addressable::URI.parse(suffix)
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
@@ -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
- private
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRest
4
- VERSION = '0.9.2'
4
+ VERSION = '0.10.0'
5
5
  end
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.9.2
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-07-22 00:00:00.000000000 Z
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