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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 59becc885513c542ccee8100b436c2854d5c42939b72424a691a281741861728
4
- data.tar.gz: 82cfac2a503a9e934efeae9b41d037b6dd72d1e78e493a6ec921d04a39fec97e
3
+ metadata.gz: 7ec097a6117d6d476f35dbd2368b5e70e74b42ef134bf2df9a6f21f81f16a1a9
4
+ data.tar.gz: 5930aff0b125dc144bca46a6505b68dc049b0be416726b9f4af8fcafaa5b0a04
5
5
  SHA512:
6
- metadata.gz: 71cbb386c7e906584a706538f3cccba04a7090496486b80160b2856b2d4dbe480d35b02f83814643fb208173518053f283b9d4e2c365f8164781e569b23f98ea
7
- data.tar.gz: '095adc172bb26b52871a0fb9d8265fb782cab0ae43981c03f1bedfe47200cdf1551e78cf1564e29ade46a535f0c717350e306513583b4ced7e09eac815a10c73'
6
+ metadata.gz: 05d23e88b3c71c8fe7e06d450da67bd95054d2eecd5b25c35a5e92c2f0e0892739f5fb7d7a6c7343ef6081529ff5d1fb46f7e0f9368fc421c03187c6e16f3842
7
+ data.tar.gz: b50b6af0c4cc0a383aaa6043d2e9c99689951b87934bb5746fd59084c504d597555d61619e3cade3ed2d1be51d9d064536a0e1e50d4bcb499816db4e4e072d69
@@ -13,10 +13,10 @@ class Proc
13
13
  @client.perform(@proc, input, **arguments)
14
14
  end
15
15
 
16
- def >>(callable)
16
+ def >>(other)
17
17
  composed = Composition.new(client: @client)
18
18
  composed << self
19
- composed << callable
19
+ composed << other
20
20
  composed
21
21
  end
22
22
  end
@@ -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
@@ -24,9 +24,9 @@ class Proc
24
24
  end
25
25
  end
26
26
 
27
- def >>(callable)
27
+ def >>(other)
28
28
  composed = dup
29
- composed << callable
29
+ composed << other
30
30
  composed
31
31
  end
32
32
 
@@ -23,16 +23,16 @@ class Proc
23
23
  @callables << proc
24
24
  end
25
25
 
26
- def >>(callable)
26
+ def >>(other)
27
27
  evaluator = dup
28
28
 
29
- case callable
29
+ case other
30
30
  when Evaluator
31
- callable.callables.each do |each_callable|
31
+ other.callables.each do |each_callable|
32
32
  evaluator << each_callable
33
33
  end
34
34
  when Callable
35
- evaluator << Deferable.new(callable.proc)
35
+ evaluator << Deferable.new(other.proc)
36
36
  end
37
37
 
38
38
  evaluator
@@ -14,7 +14,7 @@ class Proc
14
14
  end
15
15
 
16
16
  def callable
17
- return @method.to_s.upcase, finalize_uri(@uri, @params), @headers, @body
17
+ [@method.to_s.upcase, finalize_uri(@uri, @params), @headers, @body]
18
18
  end
19
19
 
20
20
  private def finalize_uri(uri, params)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Proc
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.3"
5
5
 
6
6
  def self.version
7
7
  VERSION
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bryan Powell