async-rest 0.12.4 → 0.13.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: 80f375a2c5a177aac91923e259723dc2b57e7bed48cf815b71aec18f2d1ec98d
4
- data.tar.gz: 4f239b9d3677a86f68ed346440af2d138472dc17638c629d09d0b504a71d7b93
3
+ metadata.gz: 6a36f4148f0e9f165370b96bd494036289b5b1d669a4218c5823ffc3e7d90dfb
4
+ data.tar.gz: 93a3b829c129a26172d612f7e0f5c606132d9bd1cdc864e809eb09ce81f2c170
5
5
  SHA512:
6
- metadata.gz: fd3a56af4984229b5785512e20ab5dde647e741c31cfcec6151ad167e8962cbbb37a3e862f7404aaf80529b519edb001c2ef881e67b40fdcc85a75f12f747829
7
- data.tar.gz: b49d18472bcfa685c4140db4e440b0afd8af5f2e0ade4f4347a2e455e27bd29f0db65eab6ad0b431376fec89d0fbe6cedd9003b8da73a25a15f386dbef247a4e
6
+ metadata.gz: be6940b7aa4f462a888d1c2c4171f1c0d9501033d3a7aea7cdf7dfb79b4b2b14232badbc8f66ca73dd7432de710b1e5ab06f805284e204d612e71e4489cb8eba
7
+ data.tar.gz: d964f6876354324a8e8200ee4c9ea2320a6aa6254cbfba996e872a5f4e259e3eaa6ab657459b51058defcf01227eb3ad456ddd1c053eddea84b9e56ee280e1ac
checksums.yaml.gz.sig ADDED
Binary file
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2019-2023, by Samuel Williams.
22
5
 
23
6
  module Async
24
7
  module REST
@@ -1,24 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2018-2023, by Samuel Williams.
5
+ # Copyright, 2021, by Terry Kerr.
22
6
 
23
7
  require_relative 'error'
24
8
  require_relative 'resource'
@@ -26,51 +10,59 @@ require_relative 'wrapper/json'
26
10
 
27
11
  module Async
28
12
  module REST
13
+ # A representation of a resource has a value at the time the representation was created or fetched. It is usually generated by performing an HTTP request.
14
+ #
29
15
  # REST components perform actions on a resource by using a representation to capture the current or intended state of that resource and transferring that representation between components. A representation is a sequence of bytes, plus representation metadata to describe those bytes. Other commonly used but less precise names for a representation include: document, file, and HTTP message entity, instance, or variant.
30
16
  #
31
17
  # A representation consists of data, metadata describing the data, and, on occasion, metadata to describe the metadata (usually for the purpose of verifying message integrity). Metadata is in the form of name-value pairs, where the name corresponds to a standard that defines the value's structure and semantics. Response messages may include both representation metadata and resource metadata: information about the resource that is not specific to the supplied representation.
32
18
  class Representation
19
+ WRAPPER = Wrapper::JSON.new
20
+
33
21
  def self.[] wrapper
34
22
  klass = Class.new(self)
35
23
 
24
+ if wrapper.is_a?(Class)
25
+ wrapper = wrapper.new
26
+ end
27
+
36
28
  klass.const_set(:WRAPPER, wrapper)
37
29
 
38
30
  return klass
39
31
  end
40
32
 
41
- def self.for(*arguments, **options)
42
- representation = self.new(Resource.for(*arguments), **options)
43
-
44
- return representation unless block_given?
45
-
46
- Async do
47
- begin
48
- yield representation
49
- ensure
50
- representation.close
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|
37
+ return self.for(resource, response, &block)
38
+ end
51
39
  end
52
40
  end
53
41
  end
54
42
 
55
- WRAPPER = Wrapper::JSON
43
+ def self.for(resource, response, &block)
44
+ if block_given?
45
+ block.call(response)
46
+ end
47
+
48
+ return self.new(resource, value: response.read, metadata: response.headers)
49
+ end
56
50
 
57
51
  # @param resource [Resource] the RESTful resource that this representation is of.
58
- # @param metadata [Hash | HTTP::Headers] the metadata associated wtih teh representation.
52
+ # @param metadata [Hash | HTTP::Headers] the metadata associated with the representation.
59
53
  # @param value [Object] the value of the representation.
60
- # @param wrapper [#prepare_request, #process_response] the wrapper for encoding/decoding the request/response body.
61
- def initialize(resource, metadata: {}, value: nil, wrapper: self.class::WRAPPER.new)
54
+ def initialize(resource, value: nil, metadata: {})
62
55
  @resource = resource
63
- @wrapper = wrapper
64
56
 
65
- @metadata = metadata
66
57
  @value = value
58
+ @metadata = metadata
67
59
  end
68
60
 
69
61
  def with(klass = nil, **options)
70
62
  if klass
71
- klass.new(@resource.with(**options), wrapper: klass::WRAPPER.new)
63
+ klass.new(@resource.with(**options))
72
64
  else
73
- self.class.new(@resource.with(**options), wrapper: @wrapper)
65
+ self.class.new(@resource.with(**options))
74
66
  end
75
67
  end
76
68
 
@@ -83,46 +75,16 @@ module Async
83
75
  end
84
76
 
85
77
  attr :resource
86
- attr :wrapper
87
-
88
- def prepare_request(verb, payload)
89
- @resource.prepare_request(verb, payload, &@wrapper.method(:prepare_request))
90
- end
91
-
92
- # If an exception propagates out of this method, the response will be closed.
93
- def process_response(request, response)
94
- @wrapper.process_response(request, response)
95
- end
96
-
97
- ::Protocol::HTTP::Methods.each do |name, verb|
98
- # TODO when Ruby 3.0 lands, convert this to |payload = nil, **parameters|
99
- # Blocked by https://bugs.ruby-lang.org/issues/14183
100
- define_method(verb.downcase) do |payload = nil|
101
- request = prepare_request(verb, payload)
102
-
103
- response = @resource.call(request)
104
-
105
- # If we exit this block because of an exception, we close the response. This ensures we don't have any dangling connections.
106
- begin
107
- return process_response(request, response)
108
- rescue
109
- response.close
110
-
111
- raise
112
- end
113
- end
114
- end
115
-
116
78
  attr :metadata
117
79
 
118
- def value!
119
- response = self.get
120
-
121
- if response.success?
122
- @metadata = response.headers
123
- @value = response.read
124
- else
125
- raise ResponseError, response
80
+ private def get
81
+ self.class::WRAPPER.call(@resource) do |response|
82
+ if response.success?
83
+ @metadata = response.headers
84
+ @value = response.read
85
+ else
86
+ raise ResponseError, response
87
+ end
126
88
  end
127
89
  end
128
90
 
@@ -131,35 +93,38 @@ module Async
131
93
  end
132
94
 
133
95
  def value
134
- @value ||= value!
96
+ @value ||= self.get
135
97
  end
136
98
 
137
- def value= value
138
- @value = self.assign(value)
139
- end
140
-
141
- def call(value)
142
- if value
143
- self.post(value)
144
- else
145
- self.delete
99
+ # Provides a way to mutate the value of the representation.
100
+ module Mutable
101
+ def value= value
102
+ @value = self.assign(value)
146
103
  end
147
- end
148
-
149
- def assign(value)
150
- response = self.call(value)
151
104
 
152
- response.read
105
+ def call(value)
106
+ if value
107
+ self.post(value)
108
+ else
109
+ self.delete
110
+ end
111
+ end
153
112
 
154
- return @value
155
- end
156
-
157
- def update
158
- @value = assign(@value)
113
+ def assign(value)
114
+ response = self.call(value)
115
+
116
+ response.read
117
+
118
+ return @value
119
+ end
120
+
121
+ def update
122
+ @value = assign(@value)
123
+ end
159
124
  end
160
125
 
161
126
  def inspect
162
- "\#<#{self.class} #{@resource.inspect}: value=#{@value.inspect}>"
127
+ "\#<#{self.class} #{@resource.inspect} value=#{@value.inspect}>"
163
128
  end
164
129
  end
165
130
  end
@@ -1,22 +1,7 @@
1
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
2
- #
3
- # Permission is hereby granted, free of charge, to any person obtaining a copy
4
- # of this software and associated documentation files (the "Software"), to deal
5
- # in the Software without restriction, including without limitation the rights
6
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
- # copies of the Software, and to permit persons to whom the Software is
8
- # furnished to do so, subject to the following conditions:
9
- #
10
- # The above copyright notice and this permission notice shall be included in
11
- # all copies or substantial portions of the Software.
12
- #
13
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
- # THE SOFTWARE.
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2018-2023, by Samuel Williams.
20
5
 
21
6
  require 'async'
22
7
  require 'async/http/client'
@@ -27,75 +12,62 @@ require 'protocol/http/reference'
27
12
 
28
13
  module Async
29
14
  module REST
15
+ # A resource is an abstract reference to some named entity, typically a URL with associated metatadata. Generally, your entry to any web service will be a resource, and that resource will create zero or more representations as you navigate through the service.
16
+ #
30
17
  # The key abstraction of information in REST is a resource. Any information that can be named can be a resource: a document or image, a temporal service (e.g. "today's weather in Los Angeles"), a collection of other resources, a non-virtual object (e.g. a person), and so on. In other words, any concept that might be the target of an author's hypertext reference must fit within the definition of a resource. A resource is a conceptual mapping to a set of entities, not the entity that corresponds to the mapping at any particular point in time.
31
18
  class Resource < ::Protocol::HTTP::Middleware
32
- # @param delegate [Async::HTTP::Middleware] the delegate that will handle requests.
33
- # @param reference [::Protocol::HTTP::Reference] the resource identifier (base request path/parameters).
34
- # @param headers [::Protocol::HTTP::Headers] the default headers that will be supplied with the request.
35
- def initialize(delegate, reference = ::Protocol::HTTP::Reference.parse, headers = ::Protocol::HTTP::Headers.new)
36
- super(delegate)
37
-
38
- @reference = reference
39
- @headers = headers
40
- end
19
+ ENDPOINT = nil
41
20
 
42
- # @param endpoint [Async::HTTP::Endpoint] used to connect to the remote system and specify the base path.
21
+ # Connect to the given endpoint, returning the HTTP client and reference.
22
+ # @parameter endpoint [Async::HTTP::Endpoint] used to connect to the remote system and specify the base path.
23
+ # @returns [Tuple(Async::HTTP::Client, ::Protocol::HTTP::Reference)] the client and reference.
43
24
  def self.connect(endpoint)
44
25
  reference = ::Protocol::HTTP::Reference.parse(endpoint.path)
45
26
 
46
27
  return ::Protocol::HTTP::AcceptEncoding.new(HTTP::Client.new(endpoint)), reference
47
28
  end
48
29
 
49
- def self.for(endpoint, *arguments)
50
- # TODO This behaviour is deprecated and will probably be removed.
51
- if endpoint.is_a? String
52
- endpoint = HTTP::Endpoint.parse(endpoint)
30
+ # Create a new resource for the given endpoint.
31
+ def self.open(endpoint = self::ENDPOINT, **options)
32
+ if endpoint.is_a?(String)
33
+ endpoint = Async::HTTP::Endpoint.parse(endpoint)
53
34
  end
54
35
 
55
36
  client, reference = connect(endpoint)
56
37
 
57
- resource = self.new(client, reference, *arguments)
38
+ resource = self.new(client, reference, **options)
58
39
 
59
40
  return resource unless block_given?
60
41
 
61
- Async do
62
- begin
63
- yield resource
64
- ensure
65
- resource.close
66
- end
42
+ Sync do
43
+ yield resource
44
+ ensure
45
+ resource.close
67
46
  end
68
47
  end
69
48
 
70
- attr :reference
71
- attr :headers
72
-
73
- def self.with(parent, *arguments, headers: {}, **options)
49
+ def self.with(parent, headers: {}, **options)
74
50
  reference = parent.reference.with(**options)
51
+ headers = parent.headers.merge(headers)
75
52
 
76
- self.new(*arguments, parent.delegate, reference, parent.headers.merge(headers))
53
+ self.new(parent.delegate, reference, headers)
77
54
  end
78
55
 
79
- def with(*arguments, **options)
80
- self.class.with(self, *arguments, **options)
56
+ # @parameter delegate [Async::HTTP::Middleware] the delegate that will handle requests.
57
+ # @parameter reference [::Protocol::HTTP::Reference] the resource identifier (base request path/parameters).
58
+ # @parameter headers [::Protocol::HTTP::Headers] the default headers that will be supplied with the request.
59
+ def initialize(delegate, reference = ::Protocol::HTTP::Reference.parse, headers = ::Protocol::HTTP::Headers.new)
60
+ super(delegate)
61
+
62
+ @reference = reference
63
+ @headers = headers
81
64
  end
82
65
 
83
- def get(klass = Representation, **parameters)
84
- klass.new(self.with(parameters: parameters)).tap(&:value)
85
- end
66
+ attr :reference
67
+ attr :headers
86
68
 
87
- # @param verb [String] the HTTP verb to use.
88
- # @param payload [Object] the object which will used to generate the body of the request.
89
- def prepare_request(verb, payload)
90
- if payload
91
- headers = @headers.dup
92
- body = yield payload, headers
93
- else
94
- headers = @headers
95
- body = nil
96
- end
97
-
98
- return ::Protocol::HTTP::Request[verb, @reference, headers, body]
69
+ def with(**options)
70
+ self.class.with(self, **options)
99
71
  end
100
72
 
101
73
  def inspect
@@ -105,6 +77,13 @@ module Async
105
77
  def to_s
106
78
  "\#<#{self.class} #{@reference.to_s}>"
107
79
  end
80
+
81
+ def call(request)
82
+ request.path = @reference.with(path: request.path).to_s
83
+ request.headers = @headers.merge(request.headers)
84
+
85
+ super
86
+ end
108
87
  end
109
88
  end
110
89
  end
@@ -1,27 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2018-2023, by Samuel Williams.
22
5
 
23
6
  module Async
24
7
  module REST
25
- VERSION = "0.12.4"
8
+ VERSION = "0.13.0"
26
9
  end
27
10
  end
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2019-2023, by Samuel Williams.
22
5
 
23
6
  require_relative 'json'
24
7
  require_relative 'url_encoded'
@@ -36,15 +19,15 @@ module Async
36
19
  @content_types = content_types
37
20
  end
38
21
 
39
- def prepare_request(payload, headers)
22
+ def prepare_request(request, payload)
40
23
  @content_types.each_key do |key|
41
- headers.add('accept', key)
24
+ request.headers.add('accept', key)
42
25
  end
43
26
 
44
27
  if payload
45
- headers['content-type'] = URLEncoded::APPLICATION_FORM_URLENCODED
28
+ request.headers['content-type'] = URLEncoded::APPLICATION_FORM_URLENCODED
46
29
 
47
- ::Protocol::HTTP::Body::Buffered.new([
30
+ request.body = ::Protocol::HTTP::Body::Buffered.new([
48
31
  ::Protocol::HTTP::URL.encode(payload)
49
32
  ])
50
33
  end
@@ -1,33 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2019, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2019-2023, by Samuel Williams.
22
5
 
23
6
  module Async
24
7
  module REST
25
8
  module Wrapper
26
9
  class Generic
10
+ def call(resource, verb = "GET", payload = nil, &block)
11
+ request = ::Protocol::HTTP::Request[verb, nil]
12
+ self.prepare_request(request, payload)
13
+
14
+ response = resource.call(request)
15
+
16
+ # If we exit this block because of an exception, we close the response. This ensures we don't have any dangling connections.
17
+ begin
18
+ self.process_response(request, response)
19
+
20
+ yield response
21
+ rescue
22
+ response.close
23
+
24
+ raise
25
+ end
26
+ end
27
+
27
28
  # @param payload [Object] a request payload to send.
28
29
  # @param headers [Protocol::HTTP::Headers] the mutable HTTP headers for the request.
29
30
  # @return [Body | nil] an optional request body based on the given payload.
30
- def prepare_request(payload, headers)
31
+ def prepare_request(request, payload)
32
+ request.body = ::Protocol::HTTP::Body::Buffered.wrap(payload)
31
33
  end
32
34
 
33
35
  # @param request [Protocol::HTTP::Request] the request that was made.
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2018-2023, by Samuel Williams.
22
5
 
23
6
  require 'json'
24
7
 
@@ -44,13 +27,13 @@ module Async
44
27
  @content_type.split
45
28
  end
46
29
 
47
- def prepare_request(payload, headers)
48
- headers['accept'] ||= @content_type
30
+ def prepare_request(request, payload)
31
+ request.headers['accept'] ||= @content_type
49
32
 
50
33
  if payload
51
- headers['content-type'] = @content_type
34
+ request.headers['content-type'] = @content_type
52
35
 
53
- HTTP::Body::Buffered.new([
36
+ request.body = HTTP::Body::Buffered.new([
54
37
  ::JSON.dump(payload)
55
38
  ])
56
39
  end
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2019-2023, by Samuel Williams.
22
5
 
23
6
  require 'json'
24
7
 
@@ -43,13 +26,13 @@ module Async
43
26
  @content_type.split
44
27
  end
45
28
 
46
- def prepare_request(payload, headers)
47
- headers['accept'] ||= @content_type
29
+ def prepare_request(request, payload)
30
+ request.headers['accept'] ||= @content_type
48
31
 
49
32
  if payload
50
- headers['content-type'] = @content_type
33
+ request.headers['content-type'] = @content_type
51
34
 
52
- ::Protocol::HTTP::Body::Buffered.new([
35
+ request.body = ::Protocol::HTTP::Body::Buffered.new([
53
36
  ::Protocol::HTTP::URL.encode(payload)
54
37
  ])
55
38
  end
data/lib/async/rest.rb CHANGED
@@ -1,24 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Copyright, 2018, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # Released under the MIT License.
4
+ # Copyright, 2018-2023, by Samuel Williams.
22
5
 
23
6
  require_relative 'rest/version'
24
7
  require_relative 'rest/representation'
data/license.md ADDED
@@ -0,0 +1,24 @@
1
+ # MIT License
2
+
3
+ Copyright, 2018-2024, by Samuel Williams.
4
+ Copyright, 2019, by Cyril Roelandt.
5
+ Copyright, 2020-2021, by Olle Jonsson.
6
+ Copyright, 2021, by Terry Kerr.
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ of this software and associated documentation files (the "Software"), to deal
10
+ in the Software without restriction, including without limitation the rights
11
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ copies of the Software, and to permit persons to whom the Software is
13
+ furnished to do so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,34 @@
1
+ # Async::REST
2
+
3
+ Roy Thomas Fielding's thesis [Architectural Styles and the Design of Network-based Software Architectures](https://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm) describes [Representational State Transfer](https://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm) which comprises several core concepts:
4
+
5
+ - `Resource`: A conceptual mapping to one or more entities.
6
+ - `Representation`: An instance of a resource at a given point in time.
7
+
8
+ This gem models these abstractions as closely and practically as possible and serves as a basis for building asynchronous web clients.
9
+
10
+ [![Development Status](https://github.com/socketry/async-rest/workflows/Test/badge.svg)](https://github.com/socketry/async-rest/actions?workflow=Test)
11
+
12
+ ## Usage
13
+
14
+ Please see the [project documentation](https://socketry.github.io/async-rest/) for more details.
15
+
16
+ - [Getting Started](https://socketry.github.io/async-rest/guides/getting-started/index) - This guide explains the design of the `async-rest` gem and how to use it to access RESTful APIs.
17
+
18
+ ## Contributing
19
+
20
+ We welcome contributions to this project.
21
+
22
+ 1. Fork it.
23
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
24
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
25
+ 4. Push to the branch (`git push origin my-new-feature`).
26
+ 5. Create new Pull Request.
27
+
28
+ ### Developer Certificate of Origin
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.
31
+
32
+ ### Contributor Covenant
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.
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,14 +1,46 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.4
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
+ - Olle Jonsson
9
+ - Cyril Roelandt
10
+ - Terry Kerr
8
11
  autorequire:
9
12
  bindir: bin
10
- cert_chain: []
11
- date: 2021-06-14 00:00:00.000000000 Z
13
+ cert_chain:
14
+ - |
15
+ -----BEGIN CERTIFICATE-----
16
+ MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11
17
+ ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK
18
+ CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz
19
+ MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd
20
+ MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnNmZXIxEjAQBgoJkiaJk/IsZAEZFgJj
21
+ bzESMBAGCgmSJomT8ixkARkWAm56MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIB
22
+ igKCAYEAomvSopQXQ24+9DBB6I6jxRI2auu3VVb4nOjmmHq7XWM4u3HL+pni63X2
23
+ 9qZdoq9xt7H+RPbwL28LDpDNflYQXoOhoVhQ37Pjn9YDjl8/4/9xa9+NUpl9XDIW
24
+ sGkaOY0eqsQm1pEWkHJr3zn/fxoKPZPfaJOglovdxf7dgsHz67Xgd/ka+Wo1YqoE
25
+ e5AUKRwUuvaUaumAKgPH+4E4oiLXI4T1Ff5Q7xxv6yXvHuYtlMHhYfgNn8iiW8WN
26
+ XibYXPNP7NtieSQqwR/xM6IRSoyXKuS+ZNGDPUUGk8RoiV/xvVN4LrVm9upSc0ss
27
+ RZ6qwOQmXCo/lLcDUxJAgG95cPw//sI00tZan75VgsGzSWAOdjQpFM0l4dxvKwHn
28
+ tUeT3ZsAgt0JnGqNm2Bkz81kG4A2hSyFZTFA8vZGhp+hz+8Q573tAR89y9YJBdYM
29
+ zp0FM4zwMNEUwgfRzv1tEVVUEXmoFCyhzonUUw4nE4CFu/sE3ffhjKcXcY//qiSW
30
+ xm4erY3XAgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
31
+ BBYEFO9t7XWuFf2SKLmuijgqR4sGDlRsMC4GA1UdEQQnMCWBI3NhbXVlbC53aWxs
32
+ aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWBI3NhbXVlbC53aWxs
33
+ aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEBCwUAA4IBgQB5sxkE
34
+ cBsSYwK6fYpM+hA5B5yZY2+L0Z+27jF1pWGgbhPH8/FjjBLVn+VFok3CDpRqwXCl
35
+ xCO40JEkKdznNy2avOMra6PFiQyOE74kCtv7P+Fdc+FhgqI5lMon6tt9rNeXmnW/
36
+ c1NaMRdxy999hmRGzUSFjozcCwxpy/LwabxtdXwXgSay4mQ32EDjqR1TixS1+smp
37
+ 8C/NCWgpIfzpHGJsjvmH2wAfKtTTqB9CVKLCWEnCHyCaRVuKkrKjqhYCdmMBqCws
38
+ JkxfQWC+jBVeG9ZtPhQgZpfhvh+6hMhraUYRQ6XGyvBqEUe+yo6DKIT3MtGE2+CP
39
+ eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt
40
+ Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
41
+ voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
42
+ -----END CERTIFICATE-----
43
+ date: 2024-04-09 00:00:00.000000000 Z
12
44
  dependencies:
13
45
  - !ruby/object:Gem::Dependency
14
46
  name: async-http
@@ -38,76 +70,6 @@ dependencies:
38
70
  - - "~>"
39
71
  - !ruby/object:Gem::Version
40
72
  version: '0.7'
41
- - !ruby/object:Gem::Dependency
42
- name: async-rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '1.1'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '1.1'
55
- - !ruby/object:Gem::Dependency
56
- name: bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: covered
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: rake
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: rspec
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '3.6'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '3.6'
111
73
  description:
112
74
  email:
113
75
  executables: []
@@ -123,10 +85,14 @@ files:
123
85
  - lib/async/rest/wrapper/generic.rb
124
86
  - lib/async/rest/wrapper/json.rb
125
87
  - lib/async/rest/wrapper/url_encoded.rb
88
+ - license.md
89
+ - readme.md
126
90
  homepage: https://github.com/socketry/async-rest
127
91
  licenses:
128
92
  - MIT
129
- metadata: {}
93
+ metadata:
94
+ documentation_uri: https://socketry.github.io/async-rest/
95
+ source_code_uri: https://github.com/socketry/async-rest.git
130
96
  post_install_message:
131
97
  rdoc_options: []
132
98
  require_paths:
@@ -135,14 +101,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
101
  requirements:
136
102
  - - ">="
137
103
  - !ruby/object:Gem::Version
138
- version: '0'
104
+ version: '3.1'
139
105
  required_rubygems_version: !ruby/object:Gem::Requirement
140
106
  requirements:
141
107
  - - ">="
142
108
  - !ruby/object:Gem::Version
143
109
  version: '0'
144
110
  requirements: []
145
- rubygems_version: 3.1.6
111
+ rubygems_version: 3.5.3
146
112
  signing_key:
147
113
  specification_version: 4
148
114
  summary: A library for RESTful clients (and hopefully servers).
metadata.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ N�*&�������v\�2�)�iHD+�@o�h����CNN"��>��Y��}�uc0�h}�8�Gd�_H�P���Yg� d� \ԍ����ԡ�}�����P+}�c���w��镮�K�� |��w g9��tJ��|�d��?\g^,�E�휑&��*��x[�I�������%��3*(9�Y���v�c�X�:�X�D�"�v�:�G�
2
+