async-rest 0.17.0 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/async/rest/representation.rb +12 -16
- data/lib/async/rest/resource.rb +4 -0
- data/lib/async/rest/version.rb +1 -1
- data/lib/async/rest/wrapper/generic.rb +24 -4
- data/readme.md +7 -0
- data.tar.gz.sig +0 -0
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9feb22e0660bd79fdf80e6fc2146afa4b6c51f6ef9a08e912415c59d99677232
|
4
|
+
data.tar.gz: 4ed1027a6ff4cd8af484bbe7a237f3aef1933ef7e965551e0289ab672c8429e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c79a403bc85492375ec4cc0f3a396a3beb834f1cd6813a631b0e6eeca99a65e4d7aae2c575892513ac93d4d885dce621e35cf8590fdcb0788254a031fc59b6bb
|
7
|
+
data.tar.gz: 0c99e3832e8faf24bfec7778cc13879aa9f59b90f0fb9662ff585cdfa34d1227301baf44bc5f49be27c77064933abe6c1b5929b52eda78f06a3fee88b2378140
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -103,33 +103,29 @@ module Async
|
|
103
103
|
|
104
104
|
# Provides a way to mutate the value of the representation.
|
105
105
|
module Mutable
|
106
|
-
def value
|
107
|
-
|
106
|
+
def post(value)
|
107
|
+
self.class.post(@resource, value) do |resource, response|
|
108
|
+
@value = response.read
|
109
|
+
|
110
|
+
self
|
111
|
+
end
|
108
112
|
end
|
109
113
|
|
110
|
-
def
|
114
|
+
def delete
|
115
|
+
self.class.delete(@resource)
|
116
|
+
end
|
117
|
+
|
118
|
+
def assign(value)
|
111
119
|
if value
|
112
120
|
self.post(value)
|
113
121
|
else
|
114
122
|
self.delete
|
115
123
|
end
|
116
124
|
end
|
117
|
-
|
118
|
-
def assign(value)
|
119
|
-
response = self.call(value)
|
120
|
-
|
121
|
-
response.read
|
122
|
-
|
123
|
-
return @value
|
124
|
-
end
|
125
|
-
|
126
|
-
def update
|
127
|
-
@value = assign(@value)
|
128
|
-
end
|
129
125
|
end
|
130
126
|
|
131
127
|
def inspect
|
132
|
-
"\#<#{self.class} #{@resource.inspect} value=#{@value.inspect}>"
|
128
|
+
"\#<#{self.class} #{@resource.path.inspect} value=#{@value.inspect}>"
|
133
129
|
end
|
134
130
|
end
|
135
131
|
end
|
data/lib/async/rest/resource.rb
CHANGED
data/lib/async/rest/version.rb
CHANGED
@@ -7,11 +7,29 @@ module Async
|
|
7
7
|
module REST
|
8
8
|
module Wrapper
|
9
9
|
class Generic
|
10
|
-
def
|
11
|
-
|
10
|
+
protected def response_for(resource, request)
|
11
|
+
while true
|
12
|
+
response = resource.call(request)
|
13
|
+
|
14
|
+
if response.status == 429
|
15
|
+
if retry_after = response.headers["retry-after"]
|
16
|
+
sleep(retry_after.to_f)
|
17
|
+
else
|
18
|
+
# Without the `retry-after` header, we can't determine how long to wait, so we just return the response.
|
19
|
+
return response
|
20
|
+
end
|
21
|
+
else
|
22
|
+
return response
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def call(resource, method = "GET", payload = nil, &block)
|
28
|
+
request = ::Protocol::HTTP::Request[method, nil]
|
29
|
+
|
12
30
|
self.prepare_request(request, payload)
|
13
31
|
|
14
|
-
response =
|
32
|
+
response = self.response_for(resource, request)
|
15
33
|
|
16
34
|
# If we exit this block because of an exception, we close the response. This ensures we don't have any dangling connections.
|
17
35
|
begin
|
@@ -47,7 +65,9 @@ module Async
|
|
47
65
|
# Wrap the response body in the given klass.
|
48
66
|
def wrap_response(response)
|
49
67
|
if body = response.body
|
50
|
-
|
68
|
+
if parser = parser_for(response)
|
69
|
+
response.body = parser.new(body)
|
70
|
+
end
|
51
71
|
end
|
52
72
|
|
53
73
|
return response
|
data/readme.md
CHANGED
@@ -15,6 +15,13 @@ 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
|
+
## See Also
|
19
|
+
|
20
|
+
- [async-ollama](https://github.com/socketry/async-ollama) - A client for Ollama, a local large language model server.
|
21
|
+
- [async-discord](https://github.com/socketry/async-discord) - A client for Discord, a popular chat platform.
|
22
|
+
- [cloudflare](https://github.com/socketry/cloudflare) - A client for Cloudflare, a popular CDN and DDoS protection service.
|
23
|
+
- [async-slack](https://github.com/socketry/async-slack) - A client for Slack, a popular chat platform.
|
24
|
+
|
18
25
|
## Contributing
|
19
26
|
|
20
27
|
We welcome contributions to this project.
|
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.
|
4
|
+
version: 0.19.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-
|
43
|
+
date: 2024-11-26 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.
|
111
|
+
rubygems_version: 3.5.22
|
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
|