eac_rest 0.9.1 → 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: 4928b33d7bd23461123a99c7b751c783d9d51ccd913235779741dea434b29825
4
- data.tar.gz: 23d57beb8de80b2b082c10aaa9788843d16c296d81b959700108c5f73dd00784
3
+ metadata.gz: 0fe5757eaf77cd67597c26aa58e150392aa661781cd19123f835aa503dad12fc
4
+ data.tar.gz: 9982b978e4718a87847522ef9b140a159f36d29379efe85e5c2d7be5c5bd34ca
5
5
  SHA512:
6
- metadata.gz: eaf826d3d48054a9c3dfb1ae2c39bd2568dfd7474e00c0852b2f6683a82ec82a0995e77ccadc66d36be924b8192187bc419ce79b980e17e890b32441cb42f641
7
- data.tar.gz: 82cd50f1374a0863b776544c061c42b6053299dca5233592c85a1be79ceb3f30b0fa3d0ac1a33c22c529cc965449ad57693c71660c7167437c5b1c8752ac1ef5
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
@@ -19,6 +19,8 @@ module EacRest
19
19
  internal_response.send(method_name, *args, &block)
20
20
  rescue ::EacEnvs::Http::Error
21
21
  raise ::EacRest::Error
22
+ rescue ::EacEnvs::Http::Response
23
+ raise self
22
24
  end
23
25
  end
24
26
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRest
4
- VERSION = '0.9.1'
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.1
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-06-11 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
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.4'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.4.1
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,6 +27,9 @@ dependencies:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0.4'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.4.1
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: eac_fs
29
35
  requirement: !ruby/object:Gem::Requirement
@@ -44,20 +50,20 @@ dependencies:
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '0.117'
53
+ version: '0.119'
48
54
  - - ">="
49
55
  - !ruby/object:Gem::Version
50
- version: 0.117.1
56
+ version: 0.119.1
51
57
  type: :runtime
52
58
  prerelease: false
53
59
  version_requirements: !ruby/object:Gem::Requirement
54
60
  requirements:
55
61
  - - "~>"
56
62
  - !ruby/object:Gem::Version
57
- version: '0.117'
63
+ version: '0.119'
58
64
  - - ">="
59
65
  - !ruby/object:Gem::Version
60
- version: 0.117.1
66
+ version: 0.119.1
61
67
  - !ruby/object:Gem::Dependency
62
68
  name: aranha-parsers
63
69
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +101,10 @@ files:
95
101
  - lib/eac_rest.rb
96
102
  - lib/eac_rest/api.rb
97
103
  - lib/eac_rest/entity.rb
104
+ - lib/eac_rest/entity/data.rb
105
+ - lib/eac_rest/entity/fetching.rb
98
106
  - lib/eac_rest/error.rb
107
+ - lib/eac_rest/helper.rb
99
108
  - lib/eac_rest/request.rb
100
109
  - lib/eac_rest/response.rb
101
110
  - lib/eac_rest/version.rb