proc 0.8.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +353 -22
- data/README.md +26 -50
- data/lib/proc.rb +13 -8
- data/lib/proc/callable.rb +59 -3
- data/lib/proc/client.rb +129 -54
- data/lib/proc/composition.rb +40 -3
- data/lib/proc/enumerator.rb +9 -3
- data/lib/proc/msgpack/types/decimal.rb +36 -0
- data/lib/proc/version.rb +3 -1
- metadata +18 -20
- data/lib/proc/http/client.rb +0 -42
- data/lib/proc/http/request.rb +0 -37
- data/lib/proc/http/response.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 821daaa038073142fa515aae0833fe8e81f4926a28a4877e554524dc644adf18
|
4
|
+
data.tar.gz: ad184bc2e2b55dd5dde33a73e51d4b08c7ab1b26cbb0a627a93c767adb6ba6e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a1d0b04708f3858d59308723f7b4aea5e9a5d29501365354353a95846d2d47b539d54040f563c4deb2656a8e0d7b1d64093abdc6d0d4e3cfb3432c9f96c43ca
|
7
|
+
data.tar.gz: 9eead252e396cd7376ddf1b3b223c9cf9113ace60d92b3f96b65c3cfcb64797647c0b5328c9dee6706743246c6d01a0935ee162ce31c75c8ba76428cf2d7cbfd
|
data/LICENSE
CHANGED
@@ -1,22 +1,353 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
1
|
+
Mozilla Public License, version 2.0
|
2
|
+
|
3
|
+
1. Definitions
|
4
|
+
|
5
|
+
1.1. “Contributor”
|
6
|
+
|
7
|
+
means each individual or legal entity that creates, contributes to the
|
8
|
+
creation of, or owns Covered Software.
|
9
|
+
|
10
|
+
1.2. “Contributor Version”
|
11
|
+
|
12
|
+
means the combination of the Contributions of others (if any) used by a
|
13
|
+
Contributor and that particular Contributor’s Contribution.
|
14
|
+
|
15
|
+
1.3. “Contribution”
|
16
|
+
|
17
|
+
means Covered Software of a particular Contributor.
|
18
|
+
|
19
|
+
1.4. “Covered Software”
|
20
|
+
|
21
|
+
means Source Code Form to which the initial Contributor has attached the
|
22
|
+
notice in Exhibit A, the Executable Form of such Source Code Form, and
|
23
|
+
Modifications of such Source Code Form, in each case including portions
|
24
|
+
thereof.
|
25
|
+
|
26
|
+
1.5. “Incompatible With Secondary Licenses”
|
27
|
+
means
|
28
|
+
|
29
|
+
a. that the initial Contributor has attached the notice described in
|
30
|
+
Exhibit B to the Covered Software; or
|
31
|
+
|
32
|
+
b. that the Covered Software was made available under the terms of version
|
33
|
+
1.1 or earlier of the License, but not also under the terms of a
|
34
|
+
Secondary License.
|
35
|
+
|
36
|
+
1.6. “Executable Form”
|
37
|
+
|
38
|
+
means any form of the work other than Source Code Form.
|
39
|
+
|
40
|
+
1.7. “Larger Work”
|
41
|
+
|
42
|
+
means a work that combines Covered Software with other material, in a separate
|
43
|
+
file or files, that is not Covered Software.
|
44
|
+
|
45
|
+
1.8. “License”
|
46
|
+
|
47
|
+
means this document.
|
48
|
+
|
49
|
+
1.9. “Licensable”
|
50
|
+
|
51
|
+
means having the right to grant, to the maximum extent possible, whether at the
|
52
|
+
time of the initial grant or subsequently, any and all of the rights conveyed by
|
53
|
+
this License.
|
54
|
+
|
55
|
+
1.10. “Modifications”
|
56
|
+
|
57
|
+
means any of the following:
|
58
|
+
|
59
|
+
a. any file in Source Code Form that results from an addition to, deletion
|
60
|
+
from, or modification of the contents of Covered Software; or
|
61
|
+
|
62
|
+
b. any new file in Source Code Form that contains any Covered Software.
|
63
|
+
|
64
|
+
1.11. “Patent Claims” of a Contributor
|
65
|
+
|
66
|
+
means any patent claim(s), including without limitation, method, process,
|
67
|
+
and apparatus claims, in any patent Licensable by such Contributor that
|
68
|
+
would be infringed, but for the grant of the License, by the making,
|
69
|
+
using, selling, offering for sale, having made, import, or transfer of
|
70
|
+
either its Contributions or its Contributor Version.
|
71
|
+
|
72
|
+
1.12. “Secondary License”
|
73
|
+
|
74
|
+
means either the GNU General Public License, Version 2.0, the GNU Lesser
|
75
|
+
General Public License, Version 2.1, the GNU Affero General Public
|
76
|
+
License, Version 3.0, or any later versions of those licenses.
|
77
|
+
|
78
|
+
1.13. “Source Code Form”
|
79
|
+
|
80
|
+
means the form of the work preferred for making modifications.
|
81
|
+
|
82
|
+
1.14. “You” (or “Your”)
|
83
|
+
|
84
|
+
means an individual or a legal entity exercising rights under this
|
85
|
+
License. For legal entities, “You” includes any entity that controls, is
|
86
|
+
controlled by, or is under common control with You. For purposes of this
|
87
|
+
definition, “control” means (a) the power, direct or indirect, to cause
|
88
|
+
the direction or management of such entity, whether by contract or
|
89
|
+
otherwise, or (b) ownership of more than fifty percent (50%) of the
|
90
|
+
outstanding shares or beneficial ownership of such entity.
|
91
|
+
|
92
|
+
|
93
|
+
2. License Grants and Conditions
|
94
|
+
|
95
|
+
2.1. Grants
|
96
|
+
|
97
|
+
Each Contributor hereby grants You a world-wide, royalty-free,
|
98
|
+
non-exclusive license:
|
99
|
+
|
100
|
+
a. under intellectual property rights (other than patent or trademark)
|
101
|
+
Licensable by such Contributor to use, reproduce, make available,
|
102
|
+
modify, display, perform, distribute, and otherwise exploit its
|
103
|
+
Contributions, either on an unmodified basis, with Modifications, or as
|
104
|
+
part of a Larger Work; and
|
105
|
+
|
106
|
+
b. under Patent Claims of such Contributor to make, use, sell, offer for
|
107
|
+
sale, have made, import, and otherwise transfer either its Contributions
|
108
|
+
or its Contributor Version.
|
109
|
+
|
110
|
+
2.2. Effective Date
|
111
|
+
|
112
|
+
The licenses granted in Section 2.1 with respect to any Contribution become
|
113
|
+
effective for each Contribution on the date the Contributor first distributes
|
114
|
+
such Contribution.
|
115
|
+
|
116
|
+
2.3. Limitations on Grant Scope
|
117
|
+
|
118
|
+
The licenses granted in this Section 2 are the only rights granted under this
|
119
|
+
License. No additional rights or licenses will be implied from the distribution
|
120
|
+
or licensing of Covered Software under this License. Notwithstanding Section
|
121
|
+
2.1(b) above, no patent license is granted by a Contributor:
|
122
|
+
|
123
|
+
a. for any code that a Contributor has removed from Covered Software; or
|
124
|
+
|
125
|
+
b. for infringements caused by: (i) Your and any other third party’s
|
126
|
+
modifications of Covered Software, or (ii) the combination of its
|
127
|
+
Contributions with other software (except as part of its Contributor
|
128
|
+
Version); or
|
129
|
+
|
130
|
+
c. under Patent Claims infringed by Covered Software in the absence of its
|
131
|
+
Contributions.
|
132
|
+
|
133
|
+
This License does not grant any rights in the trademarks, service marks, or
|
134
|
+
logos of any Contributor (except as may be necessary to comply with the
|
135
|
+
notice requirements in Section 3.4).
|
136
|
+
|
137
|
+
2.4. Subsequent Licenses
|
138
|
+
|
139
|
+
No Contributor makes additional grants as a result of Your choice to
|
140
|
+
distribute the Covered Software under a subsequent version of this License
|
141
|
+
(see Section 10.2) or under the terms of a Secondary License (if permitted
|
142
|
+
under the terms of Section 3.3).
|
143
|
+
|
144
|
+
2.5. Representation
|
145
|
+
|
146
|
+
Each Contributor represents that the Contributor believes its Contributions
|
147
|
+
are its original creation(s) or it has sufficient rights to grant the
|
148
|
+
rights to its Contributions conveyed by this License.
|
149
|
+
|
150
|
+
2.6. Fair Use
|
151
|
+
|
152
|
+
This License is not intended to limit any rights You have under applicable
|
153
|
+
copyright doctrines of fair use, fair dealing, or other equivalents.
|
154
|
+
|
155
|
+
2.7. Conditions
|
156
|
+
|
157
|
+
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
|
158
|
+
Section 2.1.
|
159
|
+
|
160
|
+
|
161
|
+
3. Responsibilities
|
162
|
+
|
163
|
+
3.1. Distribution of Source Form
|
164
|
+
|
165
|
+
All distribution of Covered Software in Source Code Form, including any
|
166
|
+
Modifications that You create or to which You contribute, must be under the
|
167
|
+
terms of this License. You must inform recipients that the Source Code Form
|
168
|
+
of the Covered Software is governed by the terms of this License, and how
|
169
|
+
they can obtain a copy of this License. You may not attempt to alter or
|
170
|
+
restrict the recipients’ rights in the Source Code Form.
|
171
|
+
|
172
|
+
3.2. Distribution of Executable Form
|
173
|
+
|
174
|
+
If You distribute Covered Software in Executable Form then:
|
175
|
+
|
176
|
+
a. such Covered Software must also be made available in Source Code Form,
|
177
|
+
as described in Section 3.1, and You must inform recipients of the
|
178
|
+
Executable Form how they can obtain a copy of such Source Code Form by
|
179
|
+
reasonable means in a timely manner, at a charge no more than the cost
|
180
|
+
of distribution to the recipient; and
|
181
|
+
|
182
|
+
b. You may distribute such Executable Form under the terms of this License,
|
183
|
+
or sublicense it under different terms, provided that the license for
|
184
|
+
the Executable Form does not attempt to limit or alter the recipients’
|
185
|
+
rights in the Source Code Form under this License.
|
186
|
+
|
187
|
+
3.3. Distribution of a Larger Work
|
188
|
+
|
189
|
+
You may create and distribute a Larger Work under terms of Your choice,
|
190
|
+
provided that You also comply with the requirements of this License for the
|
191
|
+
Covered Software. If the Larger Work is a combination of Covered Software
|
192
|
+
with a work governed by one or more Secondary Licenses, and the Covered
|
193
|
+
Software is not Incompatible With Secondary Licenses, this License permits
|
194
|
+
You to additionally distribute such Covered Software under the terms of
|
195
|
+
such Secondary License(s), so that the recipient of the Larger Work may, at
|
196
|
+
their option, further distribute the Covered Software under the terms of
|
197
|
+
either this License or such Secondary License(s).
|
198
|
+
|
199
|
+
3.4. Notices
|
200
|
+
|
201
|
+
You may not remove or alter the substance of any license notices (including
|
202
|
+
copyright notices, patent notices, disclaimers of warranty, or limitations
|
203
|
+
of liability) contained within the Source Code Form of the Covered
|
204
|
+
Software, except that You may alter any license notices to the extent
|
205
|
+
required to remedy known factual inaccuracies.
|
206
|
+
|
207
|
+
3.5. Application of Additional Terms
|
208
|
+
|
209
|
+
You may choose to offer, and to charge a fee for, warranty, support,
|
210
|
+
indemnity or liability obligations to one or more recipients of Covered
|
211
|
+
Software. However, You may do so only on Your own behalf, and not on behalf
|
212
|
+
of any Contributor. You must make it absolutely clear that any such
|
213
|
+
warranty, support, indemnity, or liability obligation is offered by You
|
214
|
+
alone, and You hereby agree to indemnify every Contributor for any
|
215
|
+
liability incurred by such Contributor as a result of warranty, support,
|
216
|
+
indemnity or liability terms You offer. You may include additional
|
217
|
+
disclaimers of warranty and limitations of liability specific to any
|
218
|
+
jurisdiction.
|
219
|
+
|
220
|
+
4. Inability to Comply Due to Statute or Regulation
|
221
|
+
|
222
|
+
If it is impossible for You to comply with any of the terms of this License
|
223
|
+
with respect to some or all of the Covered Software due to statute, judicial
|
224
|
+
order, or regulation then You must: (a) comply with the terms of this License
|
225
|
+
to the maximum extent possible; and (b) describe the limitations and the code
|
226
|
+
they affect. Such description must be placed in a text file included with all
|
227
|
+
distributions of the Covered Software under this License. Except to the
|
228
|
+
extent prohibited by statute or regulation, such description must be
|
229
|
+
sufficiently detailed for a recipient of ordinary skill to be able to
|
230
|
+
understand it.
|
231
|
+
|
232
|
+
5. Termination
|
233
|
+
|
234
|
+
5.1. The rights granted under this License will terminate automatically if You
|
235
|
+
fail to comply with any of its terms. However, if You become compliant,
|
236
|
+
then the rights granted under this License from a particular Contributor
|
237
|
+
are reinstated (a) provisionally, unless and until such Contributor
|
238
|
+
explicitly and finally terminates Your grants, and (b) on an ongoing basis,
|
239
|
+
if such Contributor fails to notify You of the non-compliance by some
|
240
|
+
reasonable means prior to 60 days after You have come back into compliance.
|
241
|
+
Moreover, Your grants from a particular Contributor are reinstated on an
|
242
|
+
ongoing basis if such Contributor notifies You of the non-compliance by
|
243
|
+
some reasonable means, this is the first time You have received notice of
|
244
|
+
non-compliance with this License from such Contributor, and You become
|
245
|
+
compliant prior to 30 days after Your receipt of the notice.
|
246
|
+
|
247
|
+
5.2. If You initiate litigation against any entity by asserting a patent
|
248
|
+
infringement claim (excluding declaratory judgment actions, counter-claims,
|
249
|
+
and cross-claims) alleging that a Contributor Version directly or
|
250
|
+
indirectly infringes any patent, then the rights granted to You by any and
|
251
|
+
all Contributors for the Covered Software under Section 2.1 of this License
|
252
|
+
shall terminate.
|
253
|
+
|
254
|
+
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
|
255
|
+
license agreements (excluding distributors and resellers) which have been
|
256
|
+
validly granted by You or Your distributors under this License prior to
|
257
|
+
termination shall survive termination.
|
258
|
+
|
259
|
+
6. Disclaimer of Warranty
|
260
|
+
|
261
|
+
Covered Software is provided under this License on an “as is” basis, without
|
262
|
+
warranty of any kind, either expressed, implied, or statutory, including,
|
263
|
+
without limitation, warranties that the Covered Software is free of defects,
|
264
|
+
merchantable, fit for a particular purpose or non-infringing. The entire
|
265
|
+
risk as to the quality and performance of the Covered Software is with You.
|
266
|
+
Should any Covered Software prove defective in any respect, You (not any
|
267
|
+
Contributor) assume the cost of any necessary servicing, repair, or
|
268
|
+
correction. This disclaimer of warranty constitutes an essential part of this
|
269
|
+
License. No use of any Covered Software is authorized under this License
|
270
|
+
except under this disclaimer.
|
271
|
+
|
272
|
+
7. Limitation of Liability
|
273
|
+
|
274
|
+
Under no circumstances and under no legal theory, whether tort (including
|
275
|
+
negligence), contract, or otherwise, shall any Contributor, or anyone who
|
276
|
+
distributes Covered Software as permitted above, be liable to You for any
|
277
|
+
direct, indirect, special, incidental, or consequential damages of any
|
278
|
+
character including, without limitation, damages for lost profits, loss of
|
279
|
+
goodwill, work stoppage, computer failure or malfunction, or any and all
|
280
|
+
other commercial damages or losses, even if such party shall have been
|
281
|
+
informed of the possibility of such damages. This limitation of liability
|
282
|
+
shall not apply to liability for death or personal injury resulting from such
|
283
|
+
party’s negligence to the extent applicable law prohibits such limitation.
|
284
|
+
Some jurisdictions do not allow the exclusion or limitation of incidental or
|
285
|
+
consequential damages, so this exclusion and limitation may not apply to You.
|
286
|
+
|
287
|
+
8. Litigation
|
288
|
+
|
289
|
+
Any litigation relating to this License may be brought only in the courts of
|
290
|
+
a jurisdiction where the defendant maintains its principal place of business
|
291
|
+
and such litigation shall be governed by laws of that jurisdiction, without
|
292
|
+
reference to its conflict-of-law provisions. Nothing in this Section shall
|
293
|
+
prevent a party’s ability to bring cross-claims or counter-claims.
|
294
|
+
|
295
|
+
9. Miscellaneous
|
296
|
+
|
297
|
+
This License represents the complete agreement concerning the subject matter
|
298
|
+
hereof. If any provision of this License is held to be unenforceable, such
|
299
|
+
provision shall be reformed only to the extent necessary to make it
|
300
|
+
enforceable. Any law or regulation which provides that the language of a
|
301
|
+
contract shall be construed against the drafter shall not be used to construe
|
302
|
+
this License against a Contributor.
|
303
|
+
|
304
|
+
|
305
|
+
10. Versions of the License
|
306
|
+
|
307
|
+
10.1. New Versions
|
308
|
+
|
309
|
+
Mozilla Foundation is the license steward. Except as provided in Section
|
310
|
+
10.3, no one other than the license steward has the right to modify or
|
311
|
+
publish new versions of this License. Each version will be given a
|
312
|
+
distinguishing version number.
|
313
|
+
|
314
|
+
10.2. Effect of New Versions
|
315
|
+
|
316
|
+
You may distribute the Covered Software under the terms of the version of
|
317
|
+
the License under which You originally received the Covered Software, or
|
318
|
+
under the terms of any subsequent version published by the license
|
319
|
+
steward.
|
320
|
+
|
321
|
+
10.3. Modified Versions
|
322
|
+
|
323
|
+
If you create software not governed by this License, and you want to
|
324
|
+
create a new license for such software, you may create and use a modified
|
325
|
+
version of this License if you rename the license and remove any
|
326
|
+
references to the name of the license steward (except to note that such
|
327
|
+
modified license differs from this License).
|
328
|
+
|
329
|
+
10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses
|
330
|
+
If You choose to distribute Source Code Form that is Incompatible With
|
331
|
+
Secondary Licenses under the terms of this version of the License, the
|
332
|
+
notice described in Exhibit B of this License must be attached.
|
333
|
+
|
334
|
+
Exhibit A - Source Code Form License Notice
|
335
|
+
|
336
|
+
This Source Code Form is subject to the
|
337
|
+
terms of the Mozilla Public License, v.
|
338
|
+
2.0. If a copy of the MPL was not
|
339
|
+
distributed with this file, You can
|
340
|
+
obtain one at
|
341
|
+
http://mozilla.org/MPL/2.0/.
|
342
|
+
|
343
|
+
If it is not possible or desirable to put the notice in a particular file, then
|
344
|
+
You may include the notice in a location (such as a LICENSE file in a relevant
|
345
|
+
directory) where a recipient would be likely to look for such a notice.
|
346
|
+
|
347
|
+
You may add additional accurate notices of copyright ownership.
|
348
|
+
|
349
|
+
Exhibit B - “Incompatible With Secondary Licenses” Notice
|
350
|
+
|
351
|
+
This Source Code Form is “Incompatible
|
352
|
+
With Secondary Licenses”, as defined by
|
353
|
+
the Mozilla Public License, v. 2.0.
|
data/README.md
CHANGED
@@ -1,80 +1,56 @@
|
|
1
|
-
|
1
|
+
**This is the official Ruby client for Proc: Serverless web functions with superpowers.**
|
2
2
|
|
3
|
-
|
3
|
+
* [Learn more about Proc](https://proc.dev)
|
4
|
+
* [Browse available packages](https://proc.dev/packages)
|
5
|
+
* [Read the docs](https://proc.dev/docs)
|
6
|
+
* [Join chat](https://discord.gg/aRu8qvkCmy)
|
4
7
|
|
5
|
-
Install
|
8
|
+
## Install
|
9
|
+
|
10
|
+
Install with `gem install proc`:
|
6
11
|
|
7
12
|
```
|
8
13
|
gem install proc
|
9
14
|
```
|
10
15
|
|
11
|
-
|
12
|
-
|
13
|
-
## Connecting
|
16
|
+
## Usage
|
14
17
|
|
15
|
-
|
18
|
+
Connect to proc using an account secret or limited api key:
|
16
19
|
|
17
20
|
```ruby
|
18
|
-
|
19
|
-
```
|
20
|
-
|
21
|
-
## Calling Procs
|
21
|
+
require "proc"
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
```ruby
|
26
|
-
client.core.string.reverse.call("hello")
|
27
|
-
=> "olleh"
|
23
|
+
client = Proc.connect("{your-proc-authorization}")
|
28
24
|
```
|
29
25
|
|
30
|
-
|
31
|
-
|
32
|
-
## Callable Contexts
|
33
|
-
|
34
|
-
Proc lookups create contexts that can be called later:
|
26
|
+
Now you can call procs just like local code:
|
35
27
|
|
36
28
|
```ruby
|
37
|
-
|
29
|
+
client.type.number.add.call(1, {value: 1});
|
38
30
|
|
39
|
-
|
40
|
-
=> "olleh"
|
41
|
-
|
42
|
-
string.truncate.call("hello", length: 3)
|
43
|
-
=> "hel"
|
31
|
+
=> 2
|
44
32
|
```
|
45
33
|
|
46
|
-
|
34
|
+
Build more complex behaviors by composing procs together:
|
47
35
|
|
48
36
|
```ruby
|
49
|
-
|
37
|
+
time = client.time
|
50
38
|
|
51
|
-
|
52
|
-
=> "d"
|
53
|
-
```
|
39
|
+
composition = time.now >> time.format(string: "%A")
|
54
40
|
|
55
|
-
|
41
|
+
composition.call
|
56
42
|
|
57
|
-
|
58
|
-
|
59
|
-
=> "def"
|
60
|
-
```
|
43
|
+
=> "Tuesday"
|
44
|
+
````
|
61
45
|
|
62
|
-
|
46
|
+
Deploy custom endpoints instantly and call them from anywhere:
|
63
47
|
|
64
48
|
```ruby
|
65
|
-
client
|
66
|
-
=> "hel"
|
67
|
-
```
|
68
|
-
|
69
|
-
## Compositions
|
49
|
+
client.proc.create.call(name: "day_of_week", proc: composition)
|
70
50
|
|
71
|
-
|
72
|
-
|
73
|
-
```ruby
|
74
|
-
composition = client.core.string.reverse >> client.core.string.truncate(length: 3) >> client.core.string.capitalize
|
51
|
+
client.self.day_of_week.call
|
75
52
|
|
76
|
-
|
77
|
-
=> "Oll"
|
53
|
+
=> "Tuesday"
|
78
54
|
```
|
79
55
|
|
80
|
-
|
56
|
+
Learn more at [proc.dev](https://proc.dev). See you around!
|
data/lib/proc.rb
CHANGED
@@ -1,17 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "proc/client"
|
4
|
+
require_relative "proc/version"
|
4
5
|
|
5
6
|
class Proc
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
class << self
|
8
|
+
# [public] Connect a client with an authorization.
|
9
|
+
#
|
10
|
+
def connect(authorization, **options)
|
11
|
+
Client.new(authorization, **options)
|
12
|
+
end
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
14
|
+
def undefined
|
15
|
+
@_undefined ||= ::Object.new
|
16
|
+
end
|
13
17
|
|
14
|
-
|
15
|
-
|
18
|
+
def undefined?(value)
|
19
|
+
value == undefined
|
20
|
+
end
|
16
21
|
end
|
17
22
|
end
|
data/lib/proc/callable.rb
CHANGED
@@ -16,7 +16,28 @@ class Proc
|
|
16
16
|
@arguments = arguments.dup
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
# [public] Dispatches this callable context to proc using the client.
|
20
|
+
#
|
21
|
+
# If a block is passed, it will be called to prior to dispatch and its result passed as a nested context.
|
22
|
+
#
|
23
|
+
def call(input = input_omitted = true, **arguments)
|
24
|
+
if block_given?
|
25
|
+
arguments[:proc] = yield
|
26
|
+
end
|
27
|
+
|
28
|
+
callable = self.class.new(
|
29
|
+
@proc,
|
30
|
+
client: @client,
|
31
|
+
input: input_omitted ? @input : input,
|
32
|
+
arguments: @arguments.merge(arguments)
|
33
|
+
)
|
34
|
+
|
35
|
+
@client.call(@proc, callable.input, **callable.arguments)
|
36
|
+
end
|
37
|
+
|
38
|
+
# [public] Dispatches this callable context to proc using the client, calling the given block once for each value.
|
39
|
+
#
|
40
|
+
def each(input = input_omitted = true, **arguments, &block)
|
20
41
|
callable = self.class.new(
|
21
42
|
@proc,
|
22
43
|
client: @client,
|
@@ -27,7 +48,13 @@ class Proc
|
|
27
48
|
@client.call(@proc, callable.input, **callable.arguments, &block)
|
28
49
|
end
|
29
50
|
|
51
|
+
# [public] Creates a new callable context based on this one, with a new input and/or arguments.
|
52
|
+
#
|
30
53
|
def with(input = input_omitted = true, **arguments)
|
54
|
+
if block_given?
|
55
|
+
arguments[:proc] = yield
|
56
|
+
end
|
57
|
+
|
31
58
|
self.class.new(
|
32
59
|
@proc,
|
33
60
|
client: @client,
|
@@ -36,6 +63,17 @@ class Proc
|
|
36
63
|
)
|
37
64
|
end
|
38
65
|
|
66
|
+
# [public] Returns a composition built from this callable context and one or more other callables.
|
67
|
+
#
|
68
|
+
def compose(*others)
|
69
|
+
composed = Composition.new(client: @client, input: @input)
|
70
|
+
composed << self
|
71
|
+
others.each { |other| composed << other }
|
72
|
+
composed
|
73
|
+
end
|
74
|
+
|
75
|
+
# [public] Returns a composition built from this callable context and another callable.
|
76
|
+
#
|
39
77
|
def >>(other)
|
40
78
|
composed = Composition.new(client: @client, input: @input)
|
41
79
|
composed << self
|
@@ -69,21 +107,37 @@ class Proc
|
|
69
107
|
}
|
70
108
|
end
|
71
109
|
|
110
|
+
# [public] Returns a callable context for `proc`, nested within this callable context.
|
111
|
+
#
|
72
112
|
def [](proc)
|
113
|
+
arguments = if block_given?
|
114
|
+
duped = @arguments.dup
|
115
|
+
duped[:proc] = yield
|
116
|
+
duped
|
117
|
+
else
|
118
|
+
@arguments
|
119
|
+
end
|
120
|
+
|
73
121
|
Callable.new(
|
74
122
|
[@proc, proc].join("."),
|
75
123
|
client: @client,
|
76
124
|
input: @input,
|
77
|
-
arguments:
|
125
|
+
arguments: arguments
|
78
126
|
)
|
79
127
|
end
|
80
128
|
|
81
129
|
IGNORE_MISSING = %i[to_hash].freeze
|
82
130
|
|
131
|
+
# [public] Allows nested callable contexts to be built through method lookups.
|
132
|
+
#
|
83
133
|
def method_missing(name, input = input_omitted = true, **arguments)
|
84
134
|
if IGNORE_MISSING.include?(name)
|
85
135
|
super
|
86
136
|
else
|
137
|
+
if block_given?
|
138
|
+
arguments[:proc] = yield
|
139
|
+
end
|
140
|
+
|
87
141
|
Callable.new(
|
88
142
|
[@proc, name].join("."),
|
89
143
|
client: @client,
|
@@ -102,7 +156,9 @@ class Proc
|
|
102
156
|
end
|
103
157
|
|
104
158
|
private def serialize_value(value)
|
105
|
-
if value.
|
159
|
+
if value.is_a?(Symbol)
|
160
|
+
["@@", value.to_s, {}]
|
161
|
+
elsif value.respond_to?(:serialize)
|
106
162
|
value.serialize
|
107
163
|
else
|
108
164
|
["%%", value]
|
data/lib/proc/client.rb
CHANGED
@@ -1,84 +1,138 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "async"
|
4
|
-
require "
|
3
|
+
require "core/async"
|
4
|
+
require "http"
|
5
|
+
require "msgpack"
|
6
|
+
|
7
|
+
require_relative "msgpack/types/decimal"
|
8
|
+
MessagePack::DefaultFactory.register_type(0x00, Proc::Msgpack::Types::Decimal)
|
9
|
+
MessagePack::DefaultFactory.register_type(-1, Time, packer: MessagePack::Time::Packer, unpacker: MessagePack::Time::Unpacker)
|
5
10
|
|
6
11
|
require_relative "argument"
|
7
12
|
require_relative "callable"
|
8
13
|
require_relative "composition"
|
9
14
|
require_relative "enumerator"
|
10
15
|
|
11
|
-
require_relative "http/client"
|
12
|
-
|
13
|
-
Console.logger.off!
|
14
|
-
|
15
|
-
Oj.default_options = {
|
16
|
-
mode: :custom,
|
17
|
-
bigdecimal_load: :auto,
|
18
|
-
float_precision: 0,
|
19
|
-
second_precision: 6
|
20
|
-
}.freeze
|
21
|
-
|
22
16
|
class Proc
|
17
|
+
# [public]
|
18
|
+
#
|
23
19
|
class Error < StandardError
|
24
20
|
end
|
25
21
|
|
22
|
+
# [public] Raised when input or arguments are invalid.
|
23
|
+
#
|
26
24
|
class Invalid < ::ArgumentError
|
27
25
|
end
|
28
26
|
|
27
|
+
# [public] Raised when a proc endpoint does not exist.
|
28
|
+
#
|
29
29
|
class Undefined < ::NameError
|
30
30
|
end
|
31
31
|
|
32
|
+
# [public] Raised when the client is unauthorized.
|
33
|
+
#
|
32
34
|
class Unauthorized < Error
|
33
35
|
end
|
34
36
|
|
37
|
+
# [public] Raised when a call is authorized but is blocked.
|
38
|
+
#
|
35
39
|
class Forbidden < Error
|
36
40
|
end
|
37
41
|
|
42
|
+
# [public] Raised when proc is unavailable due to an unexpected error.
|
43
|
+
#
|
38
44
|
class Unavailable < Error
|
39
45
|
end
|
40
46
|
|
47
|
+
# [public] Raised when the client is being rate limited.
|
48
|
+
#
|
41
49
|
class Limited < Error
|
42
50
|
end
|
43
51
|
|
52
|
+
# [public] Raised when a proc call surpasses the defined limit.
|
53
|
+
#
|
44
54
|
class Timeout < Error
|
45
55
|
end
|
46
56
|
|
57
|
+
# [public] Connection to proc, configured with an authorization.
|
58
|
+
#
|
47
59
|
class Client
|
48
|
-
|
60
|
+
include Is::Async
|
61
|
+
|
62
|
+
# [public] The configured authorization.
|
63
|
+
#
|
64
|
+
attr_reader :authorization
|
65
|
+
|
66
|
+
# [public] The configured scheme.
|
67
|
+
#
|
68
|
+
attr_reader :scheme
|
69
|
+
|
70
|
+
# [public] The configured host.
|
71
|
+
#
|
72
|
+
attr_reader :host
|
73
|
+
|
74
|
+
# [public] The number of requests this client has performed.
|
75
|
+
#
|
76
|
+
attr_reader :request_count
|
77
|
+
|
78
|
+
DEFAULT_HEADERS = {
|
79
|
+
"accept" => "application/vnd.proc+msgpack",
|
80
|
+
"content-type" => "application/vnd.proc+msgpack"
|
81
|
+
}.freeze
|
49
82
|
|
50
83
|
def initialize(authorization, scheme: "https", host: "proc.dev")
|
51
84
|
@authorization = authorization
|
52
85
|
@scheme = scheme
|
53
86
|
@host = host
|
54
|
-
@
|
55
|
-
end
|
87
|
+
@request_count = 0
|
56
88
|
|
57
|
-
|
58
|
-
|
89
|
+
@__base_url = "#{@scheme}://#{host}"
|
90
|
+
@__headers = {
|
91
|
+
"authorization" => "bearer #{@authorization}"
|
92
|
+
}.merge(DEFAULT_HEADERS)
|
59
93
|
end
|
60
94
|
|
61
|
-
|
62
|
-
|
63
|
-
|
95
|
+
# [public] Returns a callable context for `proc`.
|
96
|
+
#
|
97
|
+
def [](proc)
|
98
|
+
if block_given?
|
99
|
+
Callable.new(proc, client: self, arguments: {proc: yield})
|
100
|
+
else
|
101
|
+
Callable.new(proc, client: self)
|
64
102
|
end
|
103
|
+
end
|
65
104
|
|
66
|
-
|
105
|
+
# [public] Returns the current rate limit.
|
106
|
+
#
|
107
|
+
def rate_limit
|
108
|
+
refresh_rate_limit
|
109
|
+
@rate_limit
|
67
110
|
end
|
68
111
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
112
|
+
# [public] Returns the current rate limit window.
|
113
|
+
#
|
114
|
+
def rate_limit_window
|
115
|
+
refresh_rate_limit
|
116
|
+
@rate_limit_window
|
117
|
+
end
|
73
118
|
|
74
|
-
|
119
|
+
# [public] Returns the time at which the current rate limit will reset.
|
120
|
+
#
|
121
|
+
def rate_limit_reset
|
122
|
+
refresh_rate_limit
|
123
|
+
@rate_limit_reset
|
75
124
|
end
|
76
125
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
126
|
+
private def refresh_rate_limit
|
127
|
+
unless defined?(@rate_limit)
|
128
|
+
self["core.ping"].call
|
129
|
+
end
|
130
|
+
end
|
81
131
|
|
132
|
+
# [public] Calls a proc with the given input and arguments.
|
133
|
+
#
|
134
|
+
# If a block is passed and the proc returns an enumerable, the block will be called with each value.
|
135
|
+
#
|
82
136
|
def call(proc = nil, input = Proc.undefined, **arguments, &block)
|
83
137
|
body = []
|
84
138
|
|
@@ -90,21 +144,21 @@ class Proc
|
|
90
144
|
body << ["$$", key.to_s, serialize_value(value)]
|
91
145
|
end
|
92
146
|
|
93
|
-
headers =
|
94
|
-
"authorization" => "bearer #{@authorization}"
|
95
|
-
}.merge(DEFAULT_HEADERS)
|
96
|
-
|
97
|
-
status, headers, payload = get_payload(proc: proc, headers: headers, body: body)
|
147
|
+
status, headers, payload = get_payload(proc: proc, body: body)
|
98
148
|
|
99
149
|
case status
|
100
150
|
when 200
|
101
151
|
result = extract_output(payload)
|
102
152
|
|
103
153
|
if (cursor = headers["x-cursor"])
|
104
|
-
enumerator =
|
105
|
-
|
106
|
-
|
107
|
-
|
154
|
+
enumerator = if cursor.empty?
|
155
|
+
Enumerator.new(result)
|
156
|
+
else
|
157
|
+
Enumerator.new(result) {
|
158
|
+
arguments[:cursor] = cursor.to_s
|
159
|
+
call(proc, input, **arguments)
|
160
|
+
}
|
161
|
+
end
|
108
162
|
|
109
163
|
if block
|
110
164
|
enumerator.each(&block)
|
@@ -137,6 +191,8 @@ class Proc
|
|
137
191
|
end
|
138
192
|
end
|
139
193
|
|
194
|
+
# [public] Allows callable contexts to be built through method lookups.
|
195
|
+
#
|
140
196
|
def method_missing(name, input = input_omitted = true, *, **arguments)
|
141
197
|
if input_omitted
|
142
198
|
Callable.new(name, client: self, arguments: arguments)
|
@@ -149,39 +205,58 @@ class Proc
|
|
149
205
|
true
|
150
206
|
end
|
151
207
|
|
208
|
+
# [public] Builds a named argument with options.
|
209
|
+
#
|
152
210
|
def argument(name, **options)
|
153
211
|
Argument.new(name, **options)
|
154
212
|
end
|
155
213
|
alias_method :arg, :argument
|
156
214
|
|
157
|
-
def close
|
158
|
-
@internal.close
|
159
|
-
end
|
160
|
-
|
161
215
|
private def build_uri(proc)
|
162
|
-
|
163
|
-
|
164
|
-
"#{@scheme}://#{host_and_path}"
|
216
|
+
File.join(@__base_url, proc.to_s.split(".").join("/"))
|
165
217
|
end
|
166
218
|
|
167
219
|
private def serialize_value(value)
|
168
|
-
if value.
|
220
|
+
if value.is_a?(Symbol)
|
221
|
+
["@@", value.to_s, {}]
|
222
|
+
elsif value.respond_to?(:serialize)
|
169
223
|
value.serialize
|
170
224
|
else
|
171
225
|
["%%", value]
|
172
226
|
end
|
173
227
|
end
|
174
228
|
|
175
|
-
private def get_payload(proc:,
|
176
|
-
|
177
|
-
@
|
178
|
-
|
179
|
-
|
180
|
-
|
229
|
+
private def get_payload(proc:, body:)
|
230
|
+
await {
|
231
|
+
@request_count += 1
|
232
|
+
|
233
|
+
response = HTTP.headers(@__headers).post(build_uri(proc), body: MessagePack.pack(body))
|
234
|
+
|
235
|
+
update_rate_limit(response)
|
236
|
+
|
237
|
+
[response.status, response.headers, MessagePack.unpack(response.to_s)]
|
238
|
+
}
|
181
239
|
rescue
|
182
240
|
raise Proc::Unavailable
|
183
241
|
end
|
184
242
|
|
243
|
+
private def update_rate_limit(response)
|
244
|
+
split_limit = response.headers["x-rate-limit"].to_s.split(";window=")
|
245
|
+
|
246
|
+
@rate_limit = split_limit[0].to_i
|
247
|
+
|
248
|
+
@rate_limit_window = case split_limit[1]
|
249
|
+
when "60"
|
250
|
+
:minute
|
251
|
+
when "1"
|
252
|
+
:second
|
253
|
+
end
|
254
|
+
|
255
|
+
@rate_limit_reset = if (reset = response.headers["x-rate-limit-reset"])
|
256
|
+
Time.at(reset.to_s.to_i)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
185
260
|
private def extract_output(payload)
|
186
261
|
payload.each do |tuple|
|
187
262
|
case tuple[0]
|
data/lib/proc/composition.rb
CHANGED
@@ -15,7 +15,13 @@ class Proc
|
|
15
15
|
@callables = @callables.dup
|
16
16
|
end
|
17
17
|
|
18
|
-
|
18
|
+
# [public] Dispatches this composition to proc using the client.
|
19
|
+
#
|
20
|
+
def call(input = input_omitted = true, **arguments)
|
21
|
+
if block_given?
|
22
|
+
arguments[:proc] = yield
|
23
|
+
end
|
24
|
+
|
19
25
|
callable = self.class.new(
|
20
26
|
client: @client,
|
21
27
|
input: input_omitted ? @input : input,
|
@@ -23,10 +29,29 @@ class Proc
|
|
23
29
|
arguments: @arguments.merge(arguments)
|
24
30
|
)
|
25
31
|
|
26
|
-
@client.call("exec", Proc.undefined, proc: callable
|
32
|
+
@client.call("core.exec", Proc.undefined, proc: callable)
|
27
33
|
end
|
28
34
|
|
35
|
+
# [public] Dispatches this composition to proc using the client, calling the given block once for each value.
|
36
|
+
#
|
37
|
+
def each(input = input_omitted = true, **arguments, &block)
|
38
|
+
callable = self.class.new(
|
39
|
+
client: @client,
|
40
|
+
input: input_omitted ? @input : input,
|
41
|
+
callables: @callables.dup,
|
42
|
+
arguments: @arguments.merge(arguments)
|
43
|
+
)
|
44
|
+
|
45
|
+
@client.call("core.exec", Proc.undefined, proc: callable, &block)
|
46
|
+
end
|
47
|
+
|
48
|
+
# [public] Creates a new composition based on this one, with a new input and/or arguments.
|
49
|
+
#
|
29
50
|
def with(input = input_omitted = true, **arguments)
|
51
|
+
if block_given?
|
52
|
+
arguments[:proc] = yield
|
53
|
+
end
|
54
|
+
|
30
55
|
self.class.new(
|
31
56
|
client: @client,
|
32
57
|
input: input_omitted ? @input : input,
|
@@ -35,6 +60,16 @@ class Proc
|
|
35
60
|
)
|
36
61
|
end
|
37
62
|
|
63
|
+
# [public] Returns a composition from this composition and one or more other callables.
|
64
|
+
#
|
65
|
+
def compose(*others)
|
66
|
+
composed = dup
|
67
|
+
others.each { |other| composed << other }
|
68
|
+
composed
|
69
|
+
end
|
70
|
+
|
71
|
+
# [public] Returns a composition built from this composition and another callable.
|
72
|
+
#
|
38
73
|
def >>(other)
|
39
74
|
composed = dup
|
40
75
|
composed << other
|
@@ -78,7 +113,9 @@ class Proc
|
|
78
113
|
end
|
79
114
|
|
80
115
|
private def serialize_value(value)
|
81
|
-
if value.
|
116
|
+
if value.is_a?(Symbol)
|
117
|
+
["@@", value.to_s, {}]
|
118
|
+
elsif value.respond_to?(:serialize)
|
82
119
|
value.serialize
|
83
120
|
else
|
84
121
|
["%%", value]
|
data/lib/proc/enumerator.rb
CHANGED
@@ -4,16 +4,22 @@ class Proc
|
|
4
4
|
class Enumerator
|
5
5
|
include Enumerable
|
6
6
|
|
7
|
+
attr_reader :values, :next_block
|
8
|
+
|
7
9
|
def initialize(values, &next_block)
|
8
10
|
@values = values
|
9
11
|
@next_block = next_block
|
10
12
|
end
|
11
13
|
|
12
|
-
|
14
|
+
# [public] Calls the given block once for each value.
|
15
|
+
#
|
16
|
+
def each(enumerable = self, &block)
|
13
17
|
return to_enum(:each) unless block
|
14
18
|
|
15
|
-
|
16
|
-
|
19
|
+
while enumerable
|
20
|
+
enumerable.values.each(&block)
|
21
|
+
enumerable = enumerable.next_block&.call
|
22
|
+
end
|
17
23
|
end
|
18
24
|
end
|
19
25
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bigdecimal"
|
4
|
+
|
5
|
+
class BigDecimal
|
6
|
+
def to_msgpack(packer)
|
7
|
+
if precision > 16
|
8
|
+
packer.write(Proc::Msgpack::Types::Decimal.new(self))
|
9
|
+
packer
|
10
|
+
else
|
11
|
+
to_f.to_msgpack(packer)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Proc
|
17
|
+
module Msgpack
|
18
|
+
module Types
|
19
|
+
class Decimal
|
20
|
+
class << self
|
21
|
+
def from_msgpack_ext(data)
|
22
|
+
BigDecimal(data)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize(value)
|
27
|
+
@value = value
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_msgpack_ext
|
31
|
+
@value.to_s
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/proc/version.rb
CHANGED
metadata
CHANGED
@@ -1,58 +1,58 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Powell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: async
|
14
|
+
name: core-async
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.5.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.5.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: http
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '4.4'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '4.4'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: msgpack
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '1.4'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
-
description: Proc client
|
54
|
+
version: '1.4'
|
55
|
+
description: Proc Ruby client.
|
56
56
|
email: bryan@metabahn.com
|
57
57
|
executables: []
|
58
58
|
extensions: []
|
@@ -66,13 +66,11 @@ files:
|
|
66
66
|
- lib/proc/client.rb
|
67
67
|
- lib/proc/composition.rb
|
68
68
|
- lib/proc/enumerator.rb
|
69
|
-
- lib/proc/
|
70
|
-
- lib/proc/http/request.rb
|
71
|
-
- lib/proc/http/response.rb
|
69
|
+
- lib/proc/msgpack/types/decimal.rb
|
72
70
|
- lib/proc/version.rb
|
73
|
-
homepage: https://
|
71
|
+
homepage: https://github.com/metabahn/proc-rb/
|
74
72
|
licenses:
|
75
|
-
-
|
73
|
+
- MPL-2.0
|
76
74
|
metadata: {}
|
77
75
|
post_install_message:
|
78
76
|
rdoc_options: []
|
@@ -82,15 +80,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
82
80
|
requirements:
|
83
81
|
- - ">="
|
84
82
|
- !ruby/object:Gem::Version
|
85
|
-
version:
|
83
|
+
version: 3.0.0
|
86
84
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
85
|
requirements:
|
88
86
|
- - ">="
|
89
87
|
- !ruby/object:Gem::Version
|
90
88
|
version: '0'
|
91
89
|
requirements: []
|
92
|
-
rubygems_version: 3.2.
|
90
|
+
rubygems_version: 3.2.15
|
93
91
|
signing_key:
|
94
92
|
specification_version: 4
|
95
|
-
summary: Proc client
|
93
|
+
summary: Proc Ruby client.
|
96
94
|
test_files: []
|
data/lib/proc/http/client.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "async"
|
4
|
-
require "async/http/internet"
|
5
|
-
|
6
|
-
require "core/async"
|
7
|
-
|
8
|
-
require_relative "request"
|
9
|
-
require_relative "response"
|
10
|
-
|
11
|
-
class Proc
|
12
|
-
module Http
|
13
|
-
class Client
|
14
|
-
include Is::Async
|
15
|
-
|
16
|
-
def call(method, uri, params: {}, headers: {}, body: nil)
|
17
|
-
internet = Async::HTTP::Internet.new
|
18
|
-
request = Request.new(method: method, uri: uri, params: params, headers: headers, body: body)
|
19
|
-
|
20
|
-
await {
|
21
|
-
begin
|
22
|
-
response = make_request(internet, request)
|
23
|
-
|
24
|
-
yield response
|
25
|
-
ensure
|
26
|
-
response&.close
|
27
|
-
internet&.close
|
28
|
-
end
|
29
|
-
}
|
30
|
-
end
|
31
|
-
|
32
|
-
private def make_request(internet, request)
|
33
|
-
async_response = internet.call(*request.callable)
|
34
|
-
wrap_async_response_for_request(async_response, request)
|
35
|
-
end
|
36
|
-
|
37
|
-
private def wrap_async_response_for_request(async_response, request)
|
38
|
-
Response.new(request, async_response)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
data/lib/proc/http/request.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class Proc
|
4
|
-
module Http
|
5
|
-
class Request
|
6
|
-
attr_reader :method, :uri, :params, :headers, :body
|
7
|
-
|
8
|
-
def initialize(method:, uri:, params:, headers:, body:)
|
9
|
-
@method = method
|
10
|
-
@uri = uri
|
11
|
-
@params = params
|
12
|
-
@headers = headers
|
13
|
-
@body = body
|
14
|
-
end
|
15
|
-
|
16
|
-
def callable
|
17
|
-
[@method.to_s.upcase, finalize_uri(@uri, @params), @headers, @body]
|
18
|
-
end
|
19
|
-
|
20
|
-
private def finalize_uri(uri, params)
|
21
|
-
"#{uri}#{query_string(params)}"
|
22
|
-
end
|
23
|
-
|
24
|
-
private def query_string(params)
|
25
|
-
params = params.compact
|
26
|
-
|
27
|
-
if params.any?
|
28
|
-
"?" + params.compact.map { |key, value|
|
29
|
-
"#{key}=#{value}"
|
30
|
-
}.join("&")
|
31
|
-
else
|
32
|
-
""
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/lib/proc/http/response.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "forwardable"
|
4
|
-
|
5
|
-
class Proc
|
6
|
-
module Http
|
7
|
-
class Response
|
8
|
-
extend Forwardable
|
9
|
-
def_delegators :@response, :status, :version, :headers, :read, :close
|
10
|
-
|
11
|
-
attr_reader :request
|
12
|
-
|
13
|
-
def initialize(request, response)
|
14
|
-
@request = request
|
15
|
-
@response = response
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|