async-rest 0.19.1 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae3aeb21790cedb9bbbe38afbf40b3d5990b28cb1a6eaf076495fab5a25a77e1
4
- data.tar.gz: 4c8fd49d8c4be1fe367f62fe50231f527ad9fb440a8533d40e34e4bd15fe5c60
3
+ metadata.gz: cea32789d5d2ec88da49bb30446fa3296485091225741be2491d30455008888f
4
+ data.tar.gz: 89e35b8658d1dd55ffeb3f47cb2479bb49315108c142eec0c62ec29e70767984
5
5
  SHA512:
6
- metadata.gz: cf1569c2fb59d7e216d3e677504e2b846cd3d47bf3411d55c5027c8cfb26334d3946996bb2e2c9e0180b2b040d543a6fa806a4af6e7952888387cce2f80b1dc2
7
- data.tar.gz: 1fe580a38cc6a60d43943eb64ff28efddf32e3399b43c371fafeb7e6f6d39263bf66c45c2148742eaf628bfa5a6f123933859b2052f87b23c4e2e3b259a32737
6
+ metadata.gz: d8f2e5496baaf8aef8f021543bd0539d4b0c2f42b3d0043475e9320cd0fc6482ad4fc00cda51be13a4cda69324985268474fd9bcc538bf4048ec7a12631648a1
7
+ data.tar.gz: 8fae801bb41b7e40e96583bceb43d724fdb26d6de0091b4e9cef121e7c7fa4aa8cfc6081d38ac4d3c42683001f788c887af3868a206997dff4b078c5c67321b6
checksums.yaml.gz.sig CHANGED
@@ -1 +1,5 @@
1
- 4`��ٍt��z�pged�Y�k\�K$bXr�������v0���V��Mb�B�jV˄l*[ǐ�o�=WI�TZY����P�=.���7�����E���`�M��odc��բ7)i�� ^��y����i��`�ħF۔©�*\�&C^'9�WP骽�뺌� �]5���DZe�)�CI��)�i�����_���ٳ��#��B�\[AV�:�(�LJ�l��e*�V�:�/��%V?�O4fj����p�� ���k�JZ���'`��k2�,�<!��I�׋�yH������*{Y�]Z��A�<7 �~��kf��(��}�����Ѕ�Ȭ�=��+����OW�h��s�h�#_�i���щ�F�؍^����<
1
+ {i�(ΗD]y-�N&s�����+��<�ωw�0�>����A�jq�v—��������䔏�s�`5����K
2
+ �Hm�gC|�4F�-w'�~�ߺO�Sy�ƕ�%B��� |l���h�
3
+ ,E�"�\���Cŋ�^
4
+ ݙ.��I"�0���fZ�^�t����w���]ղ���덥����=‰z a�� �uH(��wy�e�p���/`������u���?��Ĭ?�A4�~n���+�㐠'�P-��ET�'�p�;� z']�@�c֋�GH
5
+ ��;O*Y'�� ��4�)��
@@ -0,0 +1,61 @@
1
+ # Getting Started
2
+
3
+ This guide explains the design of the `async-rest` gem and how to use it to access RESTful APIs.
4
+
5
+ ## Installation
6
+
7
+ Add the gem to your project:
8
+
9
+ ``` shell
10
+ $ bundle add async-rest
11
+ ```
12
+
13
+ ## Core Concepts
14
+
15
+ The `async-rest` gem has two core concepts:
16
+
17
+ - A {ruby Async::REST::Resource} instance represents a specific resource and a delegate (HTTP connection) for accessing that resource.
18
+ - A {ruby Async::REST::Representation} instance represents a specific representation of a resource - usually a specific request to a URL that returns a response with a given content type.
19
+
20
+ Just as a webpage has hyperlinks, forms and buttons for connecting information and performing actions, a representation may also carry associated links to actions that can be performed on a resource. However, many services define a fixed set of actions that can be performed on a given resource using a schema. As such, the `async-rest` gem does not have a standard mechanism for discovering actions on a resource at runtime (or follow a design that requires this).
21
+
22
+ ## Usage
23
+
24
+ Generally speaking, you should model your interface around representations. Each representation should be a subclass of {ruby Async::REST::Representation} and define methods that represent the actions that can be performed on that resource.
25
+
26
+ ```ruby
27
+ require "async/rest"
28
+
29
+ module DNS
30
+ class Query < Async::REST::Representation[Async::REST::Wrapper::JSON]
31
+ def question
32
+ value[:Question]
33
+ end
34
+
35
+ def answer
36
+ value[:Answer]
37
+ end
38
+ end
39
+
40
+ class Client < Async::REST::Resource
41
+ # This is the default endpoint to use unless otherwise specified:
42
+ ENDPOINT = Async::HTTP::Endpoint.parse("https://dns.google/resolve")
43
+
44
+ # Resolve a DNS query.
45
+ def resolve(name, type)
46
+ Query.get(self.with(parameters: { name: name, type: type }))
47
+ end
48
+ end
49
+ end
50
+
51
+ DNS::Client.open do |client|
52
+ query = client.resolve("example.com", "AAAA")
53
+
54
+ puts query.question
55
+ # {:name=>"example.com.", :type=>28}
56
+ puts query.answer
57
+ # {:name=>"example.com.", :type=>28, :TTL=>13108, :data=>"2606:2800:220:1:248:1893:25c8:1946"}
58
+ end
59
+ ```
60
+
61
+ It should be noted that the above client is not a representation, but a resource. That is because `https://dns.google.com/resolve` is a fixed endpoint that does not have a schema for discovering actions at runtime. The `resolve` method is a convenience method that creates a new representation and performs a GET request to the endpoint.
@@ -0,0 +1,12 @@
1
+ # Automatically generated context index for Utopia::Project guides.
2
+ # Do not edit then files in this directory directly, instead edit the guides and then run `bake utopia:project:agent:context:update`.
3
+ ---
4
+ description: A library for RESTful clients (and hopefully servers).
5
+ metadata:
6
+ documentation_uri: https://socketry.github.io/async-rest/
7
+ source_code_uri: https://github.com/socketry/async-rest.git
8
+ files:
9
+ - path: getting-started.md
10
+ title: Getting Started
11
+ description: This guide explains the design of the `async-rest` gem and how to use
12
+ it to access RESTful APIs.
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2018-2024, by Samuel Williams.
4
+ # Copyright, 2018-2025, by Samuel Williams.
5
5
 
6
6
  require "async"
7
7
  require "async/http/client"
8
8
  require "async/http/endpoint"
9
9
 
10
10
  require "protocol/http/accept_encoding"
11
- require "protocol/http/reference"
11
+ require "protocol/url/reference"
12
12
 
13
13
  module Async
14
14
  module REST
@@ -20,9 +20,9 @@ module Async
20
20
 
21
21
  # Connect to the given endpoint, returning the HTTP client and reference.
22
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.
23
+ # @returns [Tuple(Async::HTTP::Client, ::Protocol::URL::Reference)] the client and reference.
24
24
  def self.connect(endpoint)
25
- reference = ::Protocol::HTTP::Reference.parse(endpoint.path)
25
+ reference = ::Protocol::URL::Reference.parse(endpoint.path)
26
26
 
27
27
  return ::Protocol::HTTP::AcceptEncoding.new(HTTP::Client.new(endpoint)), reference
28
28
  end
@@ -54,9 +54,9 @@ module Async
54
54
  end
55
55
 
56
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).
57
+ # @parameter reference [::Protocol::URL::Reference] the resource identifier (base request path/parameters).
58
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)
59
+ def initialize(delegate, reference = ::Protocol::URL::Reference.parse, headers = ::Protocol::HTTP::Headers.new)
60
60
  super(delegate)
61
61
 
62
62
  @reference = reference
@@ -5,6 +5,6 @@
5
5
 
6
6
  module Async
7
7
  module REST
8
- VERSION = "0.19.1"
8
+ VERSION = "0.20.0"
9
9
  end
10
10
  end
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2024, by Samuel Williams.
4
+ # Copyright, 2019-2025, by Samuel Williams.
5
+ # Copyright, 2025, by Ayush Newatia.
5
6
 
6
7
  require_relative "json"
7
8
  require_relative "url_encoded"
@@ -28,16 +29,15 @@ module Async
28
29
  request.headers["content-type"] = URLEncoded::APPLICATION_FORM_URLENCODED
29
30
 
30
31
  request.body = ::Protocol::HTTP::Body::Buffered.new([
31
- ::Protocol::HTTP::URL.encode(payload)
32
+ ::Protocol::URL::Encoding.encode(payload)
32
33
  ])
33
34
  end
34
35
  end
35
36
 
36
37
  def parser_for(response)
37
- if content_type = response.headers["content-type"]
38
- if parser = @content_types[content_type]
39
- return parser
40
- end
38
+ media_type, _ = response.headers["content-type"].split(";")
39
+ if media_type && parser = @content_types[media_type]
40
+ return parser
41
41
  end
42
42
 
43
43
  return super
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2019-2024, by Samuel Williams.
4
+ # Copyright, 2019-2025, by Samuel Williams.
5
5
 
6
6
  require "json"
7
7
 
@@ -33,14 +33,14 @@ module Async
33
33
  request.headers["content-type"] = @content_type
34
34
 
35
35
  request.body = ::Protocol::HTTP::Body::Buffered.new([
36
- ::Protocol::HTTP::URL.encode(payload)
36
+ ::Protocol::URL::Encoding.encode(payload)
37
37
  ])
38
38
  end
39
39
  end
40
40
 
41
41
  class Parser < ::Protocol::HTTP::Body::Wrapper
42
42
  def join
43
- ::Protocol::HTTP::URL.decode(super, symbolize_keys: true)
43
+ ::Protocol::URL::Encoding.decode(super, symbolize_keys: true)
44
44
  end
45
45
  end
46
46
 
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2025, by Samuel Williams.
5
+
6
+ require_relative "wrapper/form"
7
+ require_relative "wrapper/json"
8
+ require_relative "wrapper/url_encoded"
data/lib/async/rest.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2018-2024, by Samuel Williams.
4
+ # Copyright, 2018-2025, by Samuel Williams.
5
5
 
6
6
  require_relative "rest/version"
7
7
  require_relative "rest/representation"
8
+ require_relative "rest/wrapper"
data/license.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # MIT License
2
2
 
3
- Copyright, 2018-2024, by Samuel Williams.
3
+ Copyright, 2018-2025, by Samuel Williams.
4
4
  Copyright, 2019, by Cyril Roelandt.
5
5
  Copyright, 2020-2021, by Olle Jonsson.
6
6
  Copyright, 2021, by Terry Kerr.
7
+ Copyright, 2025, by Ayush Newatia.
7
8
 
8
9
  Permission is hereby granted, free of charge, to any person obtaining a copy
9
10
  of this software and associated documentation files (the "Software"), to deal
data/readme.md CHANGED
@@ -15,6 +15,57 @@ Please see the [project documentation](https://socketry.github.io/async-rest/) f
15
15
 
16
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
17
 
18
+ ## Releases
19
+
20
+ Please see the [project releases](https://socketry.github.io/async-rest/releases/index) for all releases.
21
+
22
+ ### v0.20.0
23
+
24
+ - Migrated to `protocol-url` gem for URL handling.
25
+ - Ensured instances are properly closed after use to prevent resource leaks.
26
+ - All wrappers are now required by default from main `async/rest.rb` entry point.
27
+ - Fixed logic to correctly parse JSON responses in `Form` wrapper.
28
+
29
+ ### v0.19.1
30
+
31
+ - Fixed `retry-after` header handling to treat it as a single value header.
32
+
33
+ ### v0.19.0
34
+
35
+ - Added support for standard `retry-after` rate limiting.
36
+ - Improved response body handling to only replace the body if a parser is found.
37
+
38
+ ### v0.18.0
39
+
40
+ - Minor improvements and fixes to `Mutable`.
41
+
42
+ ### v0.17.0
43
+
44
+ - Bug fixes and minor improvements.
45
+
46
+ ### v0.16.0
47
+
48
+ - Removed legacy behaviour for cleaner implementation.
49
+
50
+ ### v0.15.0
51
+
52
+ - `Representation.for` can now take a block and return a custom representation.
53
+ - Renamed methods to prefer `method` rather than `verb` for HTTP operations.
54
+
55
+ ### v0.14.0
56
+
57
+ - Fixed constant names.
58
+ - Removed unused and legacy requires.
59
+
60
+ ### v0.13.0
61
+
62
+ - Better support for streaming responses.
63
+ - Simplified interface for resources and representations.
64
+
65
+ ### v0.12.4
66
+
67
+ - Fixed `self.new` to use `self.class.new` for proper subclass instantiation.
68
+
18
69
  ## See Also
19
70
 
20
71
  - [async-ollama](https://github.com/socketry/async-ollama) - A client for Ollama, a local large language model server.
data/releases.md ADDED
@@ -0,0 +1,146 @@
1
+ # Releases
2
+
3
+ ## v0.20.0
4
+
5
+ - Migrated to `protocol-url` gem for URL handling.
6
+ - Ensured instances are properly closed after use to prevent resource leaks.
7
+ - All wrappers are now required by default from main `async/rest.rb` entry point.
8
+ - Fixed logic to correctly parse JSON responses in `Form` wrapper.
9
+
10
+ ## v0.19.1
11
+
12
+ - Fixed `retry-after` header handling to treat it as a single value header.
13
+
14
+ ## v0.19.0
15
+
16
+ - Added support for standard `retry-after` rate limiting.
17
+ - Improved response body handling to only replace the body if a parser is found.
18
+
19
+ ## v0.18.0
20
+
21
+ - Minor improvements and fixes to `Mutable`.
22
+
23
+ ## v0.17.0
24
+
25
+ - Bug fixes and minor improvements.
26
+
27
+ ## v0.16.0
28
+
29
+ - Removed legacy behaviour for cleaner implementation.
30
+
31
+ ## v0.15.0
32
+
33
+ - `Representation.for` can now take a block and return a custom representation.
34
+ - Renamed methods to prefer `method` rather than `verb` for HTTP operations.
35
+
36
+ ## v0.14.0
37
+
38
+ - Fixed constant names.
39
+ - Removed unused and legacy requires.
40
+
41
+ ## v0.13.0
42
+
43
+ - Better support for streaming responses.
44
+ - Simplified interface for resources and representations.
45
+
46
+ ## v0.12.4
47
+
48
+ - Fixed `self.new` to use `self.class.new` for proper subclass instantiation.
49
+
50
+ ## v0.12.3
51
+
52
+ - Ensured correct wrapper class is used when making derived representations.
53
+ - Improved argument handling with `*arguments` syntax.
54
+
55
+ ## v0.12.2
56
+
57
+ - Fixed adding composite headers.
58
+
59
+ ## v0.12.1
60
+
61
+ - Improved error handling to raise a response error if the response was non-200 status.
62
+ - Better overall error handling throughout the library.
63
+
64
+ ## v0.12.0
65
+
66
+ - Added `Form` wrapper which behaves like a standard HTML form.
67
+ - Improved error handling.
68
+ - Added GitHub feed example.
69
+ - Added example showing multiple simultaneous requests.
70
+ - Added example for scraping HTML programmatically.
71
+
72
+ ## v0.10.1
73
+
74
+ - Ensured response is closed if it causes an exception.
75
+
76
+ ## v0.10.0
77
+
78
+ - Renamed `url` parameter to `endpoint` for clarity (with backwards compatibility).
79
+
80
+ ## v0.9.0
81
+
82
+ - Simplified handling of wrapped responses.
83
+ - Improved consistency and flexibility of `Representation`.
84
+ - Added path computation checks.
85
+
86
+ ## v0.8.2
87
+
88
+ - Added base `Error` class.
89
+ - Better handling of resource references.
90
+
91
+ ## v0.8.1
92
+
93
+ - Updated dependencies.
94
+
95
+ ## v0.8.0
96
+
97
+ - Fixed URL usage throughout the library.
98
+ - Updated dependencies.
99
+
100
+ ## v0.7.3
101
+
102
+ - Fixed circular loading issue.
103
+ - Increased rate limiting delay.
104
+
105
+ ## v0.7.2
106
+
107
+ - Fixed missing `require` for `representation`.
108
+
109
+ ## v0.7.1
110
+
111
+ - Relaxed gem dependencies.
112
+
113
+ ## v0.7.0
114
+
115
+ - Added support for URL encoded payloads.
116
+
117
+ ## v0.6.0
118
+
119
+ - **Breaking**: RESTful design based on Fielding's thesis.
120
+
121
+ ## v0.5.2
122
+
123
+ - Fixed bad require statement.
124
+
125
+ ## v0.5.1
126
+
127
+ - Simplified sub-resources implementation.
128
+
129
+ ## v0.4.0
130
+
131
+ - Updated dependencies.
132
+
133
+ ## v0.3.0
134
+
135
+ - Added `@wrapper` instance to handle request and response encoding/decoding logic.
136
+ - Implemented middleware-style JSON serialization/deserialization.
137
+ - Moved compression functionality into `Async::HTTP::Compressor`.
138
+
139
+ ## v0.2.0
140
+
141
+ - Added compression support.
142
+ - General code cleanup and improvements.
143
+
144
+ ## v0.1.0
145
+
146
+ - Initial release split from `async-http`.
data.tar.gz.sig CHANGED
@@ -1 +1,3 @@
1
- ~�7�t�O�<�����q3i��$m�M �����0i�ktL���б&�544��� ���E��S\����Vhbm����ڨ� =h1[�m���CžD��J4�5��c|07|�Њ��mJ\�.Ħ����Sܑ�����ə�s7o�2�v��6�˿�Y�Rz`��7��us�?�_^Z���k�����VG�����1~Wk���[W�@�<
1
+ B(z^�O��������� �͙*��L1%�K$�c��Pf\��;u[�@B�
2
+ �,h�o.@����j)$����W��$�$M^|�y��B[���&��m�q��m��y���G`
3
+ �X��sl+����p��K�G��T�N�>� w
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.1
4
+ version: 0.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
+ - Ayush Newatia
8
9
  - Olle Jonsson
9
10
  - Cyril Roelandt
10
11
  - Terry Kerr
11
- autorequire:
12
12
  bindir: bin
13
13
  cert_chain:
14
14
  - |
@@ -40,7 +40,7 @@ cert_chain:
40
40
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
41
41
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
42
42
  -----END CERTIFICATE-----
43
- date: 2024-11-26 00:00:00.000000000 Z
43
+ date: 1980-01-02 00:00:00.000000000 Z
44
44
  dependencies:
45
45
  - !ruby/object:Gem::Dependency
46
46
  name: async-http
@@ -57,43 +57,44 @@ dependencies:
57
57
  - !ruby/object:Gem::Version
58
58
  version: '0.42'
59
59
  - !ruby/object:Gem::Dependency
60
- name: protocol-http
60
+ name: protocol-url
61
61
  requirement: !ruby/object:Gem::Requirement
62
62
  requirements:
63
63
  - - "~>"
64
64
  - !ruby/object:Gem::Version
65
- version: '0.45'
65
+ version: '0.2'
66
66
  type: :runtime
67
67
  prerelease: false
68
68
  version_requirements: !ruby/object:Gem::Requirement
69
69
  requirements:
70
70
  - - "~>"
71
71
  - !ruby/object:Gem::Version
72
- version: '0.45'
73
- description:
74
- email:
72
+ version: '0.2'
75
73
  executables: []
76
74
  extensions: []
77
75
  extra_rdoc_files: []
78
76
  files:
77
+ - context/getting-started.md
78
+ - context/index.yaml
79
79
  - lib/async/rest.rb
80
80
  - lib/async/rest/error.rb
81
81
  - lib/async/rest/representation.rb
82
82
  - lib/async/rest/resource.rb
83
83
  - lib/async/rest/version.rb
84
+ - lib/async/rest/wrapper.rb
84
85
  - lib/async/rest/wrapper/form.rb
85
86
  - lib/async/rest/wrapper/generic.rb
86
87
  - lib/async/rest/wrapper/json.rb
87
88
  - lib/async/rest/wrapper/url_encoded.rb
88
89
  - license.md
89
90
  - readme.md
91
+ - releases.md
90
92
  homepage: https://github.com/socketry/async-rest
91
93
  licenses:
92
94
  - MIT
93
95
  metadata:
94
96
  documentation_uri: https://socketry.github.io/async-rest/
95
97
  source_code_uri: https://github.com/socketry/async-rest.git
96
- post_install_message:
97
98
  rdoc_options: []
98
99
  require_paths:
99
100
  - lib
@@ -101,15 +102,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
102
  requirements:
102
103
  - - ">="
103
104
  - !ruby/object:Gem::Version
104
- version: '3.1'
105
+ version: '3.2'
105
106
  required_rubygems_version: !ruby/object:Gem::Requirement
106
107
  requirements:
107
108
  - - ">="
108
109
  - !ruby/object:Gem::Version
109
110
  version: '0'
110
111
  requirements: []
111
- rubygems_version: 3.5.22
112
- signing_key:
112
+ rubygems_version: 3.7.2
113
113
  specification_version: 4
114
114
  summary: A library for RESTful clients (and hopefully servers).
115
115
  test_files: []
metadata.gz.sig CHANGED
Binary file