scorpio 0.6.3 → 0.6.4

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: 82437b6c802e013a8b001d837d74fc53df3a79a036308402baa958473282e2da
4
- data.tar.gz: 5d27bec750c90aba761158e41e8a3396af9bf08a0ca1bb03ad6fe5d88f12b139
3
+ metadata.gz: ad4505d3bd4e9dc299b95b21ce5305e7864200fb0481be3f2600f75c3476f73d
4
+ data.tar.gz: 613abb854fffaf49a45f8c9e19a0f150f0fef9b7500e50cf20dc2a6f58023347
5
5
  SHA512:
6
- metadata.gz: 077caed57f2e2d38c46f7b56f17328f732929404ba1bed3a6bead041cb6449dabe61b32ca7c1fc6bc0b30eac9c8c1b0a58ebf47f9aa74ff852595243213b3b2e
7
- data.tar.gz: d995f27814a468e9652de92b5b7e4579a3ca0626798be1cf56b155a5bb83dcbf38e60158c225ecc55c455672fb1d5efb4327615725da5745e1cd5ef26802399b
6
+ metadata.gz: 26cd883ee719f0e2683ac53c1be85d9296c90b92e80a799d938cf361c431ca486dd4e6a2db73539d7f133fa162fd104f85f4d9c9ec89b7f74e2187e8218b543b
7
+ data.tar.gz: 945afcb210c0b0ea8801393a3586b83045f82bcb94724021e3c69a6320ba32c23ddbeb6652644a6c3ea063830550f97e3001e661251662a8e6d976bc2cfdce62
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # v0.6.4
2
+
3
+ - JSI ~> v0.8.1
4
+ - OpenAPI::Operation#each_link_page
5
+
1
6
  # v0.6.3
2
7
 
3
8
  - JSI = v0.8.0
data/README.md CHANGED
@@ -172,11 +172,9 @@ pet_by_id = pet_store_doc.operations['getPetById'].run(petId: pet['id'])
172
172
 
173
173
  # unlike ResourceBase instances above, JSI instances have stricter
174
174
  # equality and the pets returned from different operations are not
175
- # equal, though the underlying JSON instance is.
175
+ # equal, because they are in different JSON documents.
176
176
  pet_by_id == pet
177
177
  # => false
178
- pet_by_id.jsi_instance == pet.jsi_instance
179
- # => true
180
178
 
181
179
  # let's name the pet after ourself
182
180
  pet.name = ENV['USER']
@@ -210,7 +208,7 @@ A class which subclasses Scorpio::ResourceBase directly (such as PetStore::Resou
210
208
 
211
209
  A model representing a resource needs to be configured, minimally, with:
212
210
 
213
- - the OpenAPI document for the REST API
211
+ - the OpenAPI document describing the API
214
212
  - the schemas that represent instances of the model, if any
215
213
 
216
214
  If the resource has HTTP operations associated with it (most, but not all resources will):
@@ -165,23 +165,62 @@ module Scorpio
165
165
  # instantiates a {Scorpio::Request} for this operation.
166
166
  # parameters are all passed to {Scorpio::Request#initialize}.
167
167
  # @return [Scorpio::Request]
168
- def build_request(**config, &b)
168
+ def build_request(configuration = {}, &b)
169
169
  @request_class ||= Scorpio::Request.request_class_by_operation(self)
170
- @request_class.new(**config, &b)
170
+ @request_class.new(configuration, &b)
171
171
  end
172
172
 
173
173
  # runs a {Scorpio::Request} for this operation, returning a {Scorpio::Ur}.
174
174
  # parameters are all passed to {Scorpio::Request#initialize}.
175
175
  # @return [Scorpio::Ur] response ur
176
- def run_ur(**config, &b)
177
- build_request(**config, &b).run_ur
176
+ def run_ur(configuration = {}, &b)
177
+ build_request(configuration, &b).run_ur
178
178
  end
179
179
 
180
180
  # runs a {Scorpio::Request} for this operation - see {Scorpio::Request#run}.
181
181
  # parameters are all passed to {Scorpio::Request#initialize}.
182
182
  # @return response body object
183
- def run(**config, &b)
184
- build_request(**config, &b).run
183
+ def run(configuration = {}, &b)
184
+ build_request(configuration, &b).run
185
+ end
186
+
187
+ # Runs this operation with the given request config, and yields the resulting {Scorpio::Ur}.
188
+ # If the response contains a `Link` header with a `next` link (and that link's URL
189
+ # corresponds to this operation), this operation is run again to that link's URL, that
190
+ # request's Ur yielded, and a `next` link in that response is followed.
191
+ # This repeats until a response does not contain a `Link` header with a `next` link.
192
+ #
193
+ # @param configuration (see Scorpio::Request#initialize)
194
+ # @yield [Scorpio::Ur]
195
+ # @return [Enumerator, nil]
196
+ def each_link_page(configuration = {}, &block)
197
+ init_request = build_request(configuration)
198
+ next_page = proc do |last_page_ur|
199
+ nextlinks = last_page_ur.response.links.select { |link| link.rel?('next') }
200
+ if nextlinks.size == 0
201
+ # no next link; we are at the end
202
+ nil
203
+ elsif nextlinks.size == 1
204
+ nextlink = nextlinks.first
205
+ # we do not use Addressable::URI#join as the paths should just be concatenated, not resolved.
206
+ # we use File.join just to deal with consecutive slashes.
207
+ template = Addressable::Template.new(File.join(init_request.base_url, path_template_str))
208
+ target_uri = nextlink.absolute_target_uri
209
+ path_params = template.extract(target_uri.merge(query: nil))
210
+ unless path_params
211
+ raise("the URI of the link to the next page did not match the URI of this operation")
212
+ end
213
+ query_params = target_uri.query_values
214
+ run_ur(
215
+ path_params: path_params,
216
+ query_params: query_params,
217
+ )
218
+ else
219
+ # TODO better error class / context / message
220
+ raise("response included multiple links with rel=next")
221
+ end
222
+ end
223
+ init_request.each_page_ur(next_page: next_page, &block)
185
224
  end
186
225
 
187
226
  private
@@ -21,7 +21,7 @@ module Scorpio
21
21
  autoload :OperationsScope, 'scorpio/openapi/operations_scope'
22
22
 
23
23
  module V3
24
- openapi_document_schema = JSI::JSONSchemaOrgDraft04.new_schema(::YAML.load_file(Scorpio.root.join(
24
+ openapi_document_schema = JSI::JSONSchemaDraft04.new_schema(::YAML.load_file(Scorpio.root.join(
25
25
  'documents/github.com/OAI/OpenAPI-Specification/blob/oas3-schema/schemas/v3.0/schema.yaml'
26
26
  )))
27
27
 
@@ -149,7 +149,7 @@ module Scorpio
149
149
  # do the Configurables first
150
150
  configuration.each do |name, value|
151
151
  if Configurables.public_method_defined?("#{name}=")
152
- Configurables.instance_method("#{name}=").bind_call(self, value)
152
+ Configurables.instance_method("#{name}=").bind(self).call(value)
153
153
  params_set << name
154
154
  end
155
155
  end
@@ -390,12 +390,17 @@ module Scorpio
390
390
  ur.response.body_object
391
391
  end
392
392
 
393
- # todo make a proper iterator interface
393
+ # Runs this request, passing the resulting Ur to the given block.
394
+ # The `next_page` callable is then called with that Ur and results in the next page's Ur, or nil.
395
+ # This repeats until the `next_page` call results in nil.
396
+ #
397
+ # See {OpenAPI::Operation#each_link_page} for integration with an OpenAPI Operation.
398
+ #
394
399
  # @param next_page [#call] a callable which will take a parameter `page_ur`, which is a {Scorpio::Ur},
395
400
  # and must result in an Ur representing the next page, which will be yielded to the block.
396
401
  # @yield [Scorpio::Ur] yields the first page, and each subsequent result of calls to `next_page` until
397
402
  # that results in nil
398
- # @return [void]
403
+ # @return [Enumerator, nil]
399
404
  def each_page_ur(next_page: , raise_on_http_error: true)
400
405
  return to_enum(__method__, next_page: next_page, raise_on_http_error: raise_on_http_error) unless block_given?
401
406
  page_ur = run_ur
@@ -211,7 +211,7 @@ module Scorpio
211
211
  end
212
212
 
213
213
  # @private
214
- # @param name [Scorpio::OpenAPI::Operation]
214
+ # @param operation [Scorpio::OpenAPI::Operation]
215
215
  # @return [String, nil]
216
216
  def api_method_name_by_operation(operation)
217
217
  raise(ArgumentError, operation.pretty_inspect) unless operation.is_a?(Scorpio::OpenAPI::Operation)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Scorpio
4
- VERSION = "0.6.3".freeze
4
+ VERSION = "0.6.4".freeze
5
5
  end
data/scorpio.gemspec CHANGED
@@ -23,8 +23,8 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.require_paths = ["lib"]
25
25
 
26
- spec.add_dependency "jsi", "= 0.8.0"
27
- spec.add_dependency "ur", "~> 0.2.4"
26
+ spec.add_dependency "jsi", "~> 0.8.1"
27
+ spec.add_dependency "ur", "~> 0.2.5"
28
28
  spec.add_dependency "faraday", "< 3.0"
29
29
  spec.add_dependency "addressable", '~> 2.3'
30
30
  end
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scorpio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.3
4
+ version: 0.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-25 00:00:00.000000000 Z
11
+ date: 2024-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsi
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '='
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.8.0
19
+ version: 0.8.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '='
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.8.0
26
+ version: 0.8.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ur
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.2.4
33
+ version: 0.2.5
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.2.4
40
+ version: 0.2.5
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: faraday
43
43
  requirement: !ruby/object:Gem::Requirement