async-rest 0.14.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: e7750b0f06535c7c980e2774a768b5c2b2617959964965adeb3dfbcced0e76f0
4
- data.tar.gz: ff05ab03fe24812120d5c3d1a50e0a029c641c7338c6ad413fa5cd8be0fe8b6d
3
+ metadata.gz: 2a25bf93c109edc39f017bd8897b6f40cd588f9d09cd49ab0c121019a1aeb581
4
+ data.tar.gz: 29ada9fd6af46ba978cf89a24b7741ce94bcb779c0f1beaf87c174b33a98cd63
5
5
  SHA512:
6
- metadata.gz: 2416bb4bebe3af462c90b42f94d4a3a20e73f3d3faac9ef2c8b69ff40175aa16601fb84f2807d76d48ecfa068d1538a35f2deeac0de8cc7691012390c7273f52
7
- data.tar.gz: 22c58ca1c2e508f6199ab41fc7e8c6072267b7aef1f644f94545769e0fc1fe90541f95e95d1e3cd165a50e34309b0c09920779f996a8625007d25d59150e04b3
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.14.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
@@ -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,10 +28,10 @@ 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
36
  request.body = ::Protocol::HTTP::Body::Buffered.new([
37
37
  ::JSON.dump(payload)
@@ -46,7 +46,7 @@ module Async
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.14.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-09-10 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
metadata.gz.sig CHANGED
Binary file