proc 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/proc/callable.rb +2 -2
- data/lib/proc/client.rb +24 -0
- data/lib/proc/composition.rb +2 -2
- data/lib/proc/composition/evaluator.rb +4 -4
- data/lib/proc/http/request.rb +1 -1
- data/lib/proc/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ec097a6117d6d476f35dbd2368b5e70e74b42ef134bf2df9a6f21f81f16a1a9
|
4
|
+
data.tar.gz: 5930aff0b125dc144bca46a6505b68dc049b0be416726b9f4af8fcafaa5b0a04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05d23e88b3c71c8fe7e06d450da67bd95054d2eecd5b25c35a5e92c2f0e0892739f5fb7d7a6c7343ef6081529ff5d1fb46f7e0f9368fc421c03187c6e16f3842
|
7
|
+
data.tar.gz: b50b6af0c4cc0a383aaa6043d2e9c99689951b87934bb5746fd59084c504d597555d61619e3cade3ed2d1be51d9d064536a0e1e50d4bcb499816db4e4e072d69
|
data/lib/proc/callable.rb
CHANGED
data/lib/proc/client.rb
CHANGED
@@ -25,6 +25,9 @@ class Proc
|
|
25
25
|
class Unavailable < Error
|
26
26
|
end
|
27
27
|
|
28
|
+
class RateLimited < Error
|
29
|
+
end
|
30
|
+
|
28
31
|
class Client < Http::Client
|
29
32
|
def initialize(authorization, scheme: "https", host: "proc.dev")
|
30
33
|
@authorization = authorization
|
@@ -38,6 +41,22 @@ class Proc
|
|
38
41
|
Callable.new(proc, client: self)
|
39
42
|
end
|
40
43
|
|
44
|
+
def remaining
|
45
|
+
unless defined?(@remaining)
|
46
|
+
self["ping"].call
|
47
|
+
end
|
48
|
+
|
49
|
+
@remaining
|
50
|
+
end
|
51
|
+
|
52
|
+
def resets_at
|
53
|
+
unless defined?(@resets_at)
|
54
|
+
self["ping"].call
|
55
|
+
end
|
56
|
+
|
57
|
+
@resets_at
|
58
|
+
end
|
59
|
+
|
41
60
|
def compose(&block)
|
42
61
|
Composition.new(client: self, &block)
|
43
62
|
end
|
@@ -59,6 +78,9 @@ class Proc
|
|
59
78
|
begin
|
60
79
|
response = call(:post, build_uri(proc), headers: headers, body: Oj.dump(body, mode: :json), task: task)
|
61
80
|
|
81
|
+
@remaining = response.headers["x-rate-limit-remaining"].to_s.to_i
|
82
|
+
@resets_at = Time.at(response.headers["x-rate-limit-reset"].to_s.to_i)
|
83
|
+
|
62
84
|
payload = Oj.load(response.read, mode: :strict)
|
63
85
|
rescue => error
|
64
86
|
raise Proc::Unavailable, error.message
|
@@ -75,6 +97,8 @@ class Proc
|
|
75
97
|
raise Proc::Unauthorized, payload.dig("error", "message")
|
76
98
|
when 404
|
77
99
|
raise Proc::Undefined, payload.dig("error", "message")
|
100
|
+
when 429
|
101
|
+
raise Proc::RateLimited, payload.dig("error", "message")
|
78
102
|
when 500
|
79
103
|
raise Proc::Error, payload.dig("error", "message")
|
80
104
|
end
|
data/lib/proc/composition.rb
CHANGED
@@ -23,16 +23,16 @@ class Proc
|
|
23
23
|
@callables << proc
|
24
24
|
end
|
25
25
|
|
26
|
-
def >>(
|
26
|
+
def >>(other)
|
27
27
|
evaluator = dup
|
28
28
|
|
29
|
-
case
|
29
|
+
case other
|
30
30
|
when Evaluator
|
31
|
-
|
31
|
+
other.callables.each do |each_callable|
|
32
32
|
evaluator << each_callable
|
33
33
|
end
|
34
34
|
when Callable
|
35
|
-
evaluator << Deferable.new(
|
35
|
+
evaluator << Deferable.new(other.proc)
|
36
36
|
end
|
37
37
|
|
38
38
|
evaluator
|
data/lib/proc/http/request.rb
CHANGED
data/lib/proc/version.rb
CHANGED