async-rest 0.13.0 → 0.15.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: 6a36f4148f0e9f165370b96bd494036289b5b1d669a4218c5823ffc3e7d90dfb
4
- data.tar.gz: 93a3b829c129a26172d612f7e0f5c606132d9bd1cdc864e809eb09ce81f2c170
3
+ metadata.gz: 2a25bf93c109edc39f017bd8897b6f40cd588f9d09cd49ab0c121019a1aeb581
4
+ data.tar.gz: 29ada9fd6af46ba978cf89a24b7741ce94bcb779c0f1beaf87c174b33a98cd63
5
5
  SHA512:
6
- metadata.gz: be6940b7aa4f462a888d1c2c4171f1c0d9501033d3a7aea7cdf7dfb79b4b2b14232badbc8f66ca73dd7432de710b1e5ab06f805284e204d612e71e4489cb8eba
7
- data.tar.gz: d964f6876354324a8e8200ee4c9ea2320a6aa6254cbfba996e872a5f4e259e3eaa6ab657459b51058defcf01227eb3ad456ddd1c053eddea84b9e56ee280e1ac
6
+ metadata.gz: d9667632e07ff0d8a72c26eb1cdf68f9f765b390cddbf604402b67f79e70cb493860d172dd25eab00dd3c2934f5f69ddfbdb6fe14e5585845420bff0cd84bf02
7
+ data.tar.gz: 01c2a95426350e1b53dbc477176f9c6e75f0d244974c8308c6244678524cf5f3a67f797f2acf3ab3b835806caeeea9f9b1c0026e2996e551df773990b7aa072e
checksums.yaml.gz.sig CHANGED
Binary file
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2018-2023, by Samuel Williams.
4
+ # Copyright, 2018-2024, by Samuel Williams.
5
5
  # Copyright, 2021, by Terry Kerr.
6
6
 
7
- require_relative 'error'
8
- require_relative 'resource'
9
- require_relative 'wrapper/json'
7
+ require_relative "error"
8
+ require_relative "resource"
9
+ require_relative "wrapper/json"
10
10
 
11
11
  module Async
12
12
  module REST
@@ -31,21 +31,32 @@ module Async
31
31
  end
32
32
 
33
33
  class << self
34
- ::Protocol::HTTP::Methods.each do |name, verb|
35
- define_method(verb.downcase) do |resource, payload = nil, &block|
36
- self::WRAPPER.call(resource, verb, payload) do |response|
34
+ ::Protocol::HTTP::Methods.each do |name, method|
35
+ define_method(method.downcase) do |resource, payload = nil, &block|
36
+ self::WRAPPER.call(resource, method, payload) do |response|
37
37
  return self.for(resource, response, &block)
38
38
  end
39
39
  end
40
40
  end
41
41
  end
42
42
 
43
+ # Instantiate a new representation from a resource and response.
44
+ #
45
+ # If a block is given, it is called with the resource and response, and the return value is used as the representation.
46
+ #
47
+ # @returns [Representation] the representation of the resource.
43
48
  def self.for(resource, response, &block)
44
49
  if block_given?
45
- block.call(response)
50
+ if block.arity == 1
51
+ # Original behaviour:
52
+ yield(response)
53
+ else
54
+ # New behaviour:
55
+ return yield(resource, response)
56
+ end
57
+ else
58
+ return self.new(resource, value: response.read, metadata: response.headers)
46
59
  end
47
-
48
- return self.new(resource, value: response.read, metadata: response.headers)
49
60
  end
50
61
 
51
62
  # @param resource [Resource] the RESTful resource that this representation is of.
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2018-2023, by Samuel Williams.
4
+ # Copyright, 2018-2024, by Samuel Williams.
5
5
 
6
- require 'async'
7
- require 'async/http/client'
8
- require 'async/http/endpoint'
6
+ require "async"
7
+ require "async/http/client"
8
+ require "async/http/endpoint"
9
9
 
10
- require 'protocol/http/accept_encoding'
11
- require 'protocol/http/reference'
10
+ require "protocol/http/accept_encoding"
11
+ require "protocol/http/reference"
12
12
 
13
13
  module Async
14
14
  module REST
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2018-2023, by Samuel Williams.
4
+ # Copyright, 2018-2024, by Samuel Williams.
5
5
 
6
6
  module Async
7
7
  module REST
8
- VERSION = "0.13.0"
8
+ VERSION = "0.15.0"
9
9
  end
10
10
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2023, by Samuel Williams.
4
+ # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
- require_relative 'json'
7
- require_relative 'url_encoded'
6
+ require_relative "json"
7
+ require_relative "url_encoded"
8
8
 
9
9
  module Async
10
10
  module REST
@@ -21,11 +21,11 @@ module Async
21
21
 
22
22
  def prepare_request(request, payload)
23
23
  @content_types.each_key do |key|
24
- request.headers.add('accept', key)
24
+ request.headers.add("accept", key)
25
25
  end
26
26
 
27
27
  if payload
28
- request.headers['content-type'] = URLEncoded::APPLICATION_FORM_URLENCODED
28
+ request.headers["content-type"] = URLEncoded::APPLICATION_FORM_URLENCODED
29
29
 
30
30
  request.body = ::Protocol::HTTP::Body::Buffered.new([
31
31
  ::Protocol::HTTP::URL.encode(payload)
@@ -34,7 +34,7 @@ module Async
34
34
  end
35
35
 
36
36
  def parser_for(response)
37
- if content_type = response.headers['content-type']
37
+ if content_type = response.headers["content-type"]
38
38
  if parser = @content_types[content_type]
39
39
  return parser
40
40
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2023, by Samuel Williams.
4
+ # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
6
  module Async
7
7
  module REST
@@ -53,7 +53,7 @@ module Async
53
53
  return response
54
54
  end
55
55
 
56
- class Unsupported < HTTP::Body::Wrapper
56
+ class Unsupported < ::Protocol::HTTP::Body::Wrapper
57
57
  def join
58
58
  raise UnsupportedError, super
59
59
  end
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2018-2023, by Samuel Williams.
4
+ # Copyright, 2018-2024, by Samuel Williams.
5
5
 
6
- require 'json'
6
+ require "json"
7
7
 
8
- require 'protocol/http/body/wrapper'
9
- require 'protocol/http/body/buffered'
8
+ require "protocol/http/body/wrapper"
9
+ require "protocol/http/body/buffered"
10
10
 
11
- require_relative 'generic'
11
+ require_relative "generic"
12
12
 
13
13
  module Async
14
14
  module REST
@@ -28,25 +28,25 @@ module Async
28
28
  end
29
29
 
30
30
  def prepare_request(request, payload)
31
- request.headers['accept'] ||= @content_type
31
+ request.headers["accept"] ||= @content_type
32
32
 
33
33
  if payload
34
- request.headers['content-type'] = @content_type
34
+ request.headers["content-type"] = @content_type
35
35
 
36
- request.body = HTTP::Body::Buffered.new([
36
+ request.body = ::Protocol::HTTP::Body::Buffered.new([
37
37
  ::JSON.dump(payload)
38
38
  ])
39
39
  end
40
40
  end
41
41
 
42
- class Parser < HTTP::Body::Wrapper
42
+ class Parser < ::Protocol::HTTP::Body::Wrapper
43
43
  def join
44
44
  ::JSON.parse(super, symbolize_names: true)
45
45
  end
46
46
  end
47
47
 
48
48
  def parser_for(response)
49
- if content_type = response.headers['content-type']
49
+ if content_type = response.headers["content-type"]
50
50
  if content_type.start_with? @content_type
51
51
  return Parser
52
52
  end
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2023, by Samuel Williams.
4
+ # Copyright, 2019-2024, by Samuel Williams.
5
5
 
6
- require 'json'
6
+ require "json"
7
7
 
8
- require 'protocol/http/body/wrapper'
9
- require 'protocol/http/body/buffered'
8
+ require "protocol/http/body/wrapper"
9
+ require "protocol/http/body/buffered"
10
10
 
11
- require_relative 'generic'
11
+ require_relative "generic"
12
12
 
13
13
  module Async
14
14
  module REST
@@ -27,10 +27,10 @@ module Async
27
27
  end
28
28
 
29
29
  def prepare_request(request, payload)
30
- request.headers['accept'] ||= @content_type
30
+ request.headers["accept"] ||= @content_type
31
31
 
32
32
  if payload
33
- request.headers['content-type'] = @content_type
33
+ request.headers["content-type"] = @content_type
34
34
 
35
35
  request.body = ::Protocol::HTTP::Body::Buffered.new([
36
36
  ::Protocol::HTTP::URL.encode(payload)
@@ -45,7 +45,7 @@ module Async
45
45
  end
46
46
 
47
47
  def parser_for(response)
48
- if content_type = response.headers['content-type']
48
+ if content_type = response.headers["content-type"]
49
49
  if content_type.start_with? @content_type
50
50
  return Parser
51
51
  end
data/lib/async/rest.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2018-2023, by Samuel Williams.
4
+ # Copyright, 2018-2024, by Samuel Williams.
5
5
 
6
- require_relative 'rest/version'
7
- require_relative 'rest/representation'
6
+ require_relative "rest/version"
7
+ require_relative "rest/representation"
data/readme.md CHANGED
@@ -27,8 +27,8 @@ We welcome contributions to this project.
27
27
 
28
28
  ### Developer Certificate of Origin
29
29
 
30
- This project uses the [Developer Certificate of Origin](https://developercertificate.org/). All contributors to this project must agree to this document to have their contributions accepted.
30
+ In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
31
31
 
32
- ### Contributor Covenant
32
+ ### Community Guidelines
33
33
 
34
- This project is governed by the [Contributor Covenant](https://www.contributor-covenant.org/). All contributors and participants agree to abide by its terms.
34
+ This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -40,7 +40,7 @@ cert_chain:
40
40
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
41
41
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
42
42
  -----END CERTIFICATE-----
43
- date: 2024-04-09 00:00:00.000000000 Z
43
+ date: 2024-09-12 00:00:00.000000000 Z
44
44
  dependencies:
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: async-http
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubygems_version: 3.5.3
111
+ rubygems_version: 3.5.11
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: A library for RESTful clients (and hopefully servers).
metadata.gz.sig CHANGED
Binary file