proc 0.7.0 → 0.8.0
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 +25 -5
- data/lib/proc/composition.rb +2 -2
- data/lib/proc/enumerator.rb +19 -0
- data/lib/proc/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ece2d4c0f8e4e0aa122ca1df9e751d061afaa802dc056e5dd2c0ba7b272ff3e8
|
4
|
+
data.tar.gz: 4f9ce5d28d966c23097dd3445d5ea5fc37fe9d0ecea1c5b13771b9633ac28d0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c084f766e97cced8633a74379d700d06efa54bc6f0eb81cf6351af9e2528aea465ebff4dc4d3dd3631c20016ce70a1a36c2245607fe14f85aaa29d115d3ac9a5
|
7
|
+
data.tar.gz: 62303f9d27683c07bc0ff8f5df8c8697a669fa8df7ac496929457e3e572384ded1c779580ddf09082d830b8658c6c1be07eadb3478255de9b013e318a51b2755
|
data/lib/proc/callable.rb
CHANGED
@@ -16,7 +16,7 @@ class Proc
|
|
16
16
|
@arguments = arguments.dup
|
17
17
|
end
|
18
18
|
|
19
|
-
def call(input = input_omitted = true, **arguments)
|
19
|
+
def call(input = input_omitted = true, **arguments, &block)
|
20
20
|
callable = self.class.new(
|
21
21
|
@proc,
|
22
22
|
client: @client,
|
@@ -24,7 +24,7 @@ class Proc
|
|
24
24
|
arguments: @arguments.merge(arguments)
|
25
25
|
)
|
26
26
|
|
27
|
-
@client.call(@proc, callable.input, **callable.arguments)
|
27
|
+
@client.call(@proc, callable.input, **callable.arguments, &block)
|
28
28
|
end
|
29
29
|
|
30
30
|
def with(input = input_omitted = true, **arguments)
|
data/lib/proc/client.rb
CHANGED
@@ -6,6 +6,7 @@ require "oj"
|
|
6
6
|
require_relative "argument"
|
7
7
|
require_relative "callable"
|
8
8
|
require_relative "composition"
|
9
|
+
require_relative "enumerator"
|
9
10
|
|
10
11
|
require_relative "http/client"
|
11
12
|
|
@@ -13,7 +14,9 @@ Console.logger.off!
|
|
13
14
|
|
14
15
|
Oj.default_options = {
|
15
16
|
mode: :custom,
|
16
|
-
bigdecimal_load: :auto
|
17
|
+
bigdecimal_load: :auto,
|
18
|
+
float_precision: 0,
|
19
|
+
second_precision: 6
|
17
20
|
}.freeze
|
18
21
|
|
19
22
|
class Proc
|
@@ -42,6 +45,8 @@ class Proc
|
|
42
45
|
end
|
43
46
|
|
44
47
|
class Client
|
48
|
+
attr_reader :authorization, :scheme, :host
|
49
|
+
|
45
50
|
def initialize(authorization, scheme: "https", host: "proc.dev")
|
46
51
|
@authorization = authorization
|
47
52
|
@scheme = scheme
|
@@ -74,7 +79,7 @@ class Proc
|
|
74
79
|
"content-type" => "application/vnd.proc+json"
|
75
80
|
}.freeze
|
76
81
|
|
77
|
-
def call(proc = nil, input = Proc.undefined, **arguments)
|
82
|
+
def call(proc = nil, input = Proc.undefined, **arguments, &block)
|
78
83
|
body = []
|
79
84
|
|
80
85
|
unless Proc.undefined?(input)
|
@@ -89,11 +94,26 @@ class Proc
|
|
89
94
|
"authorization" => "bearer #{@authorization}"
|
90
95
|
}.merge(DEFAULT_HEADERS)
|
91
96
|
|
92
|
-
status, payload = get_payload(proc: proc, headers: headers, body: body)
|
97
|
+
status, headers, payload = get_payload(proc: proc, headers: headers, body: body)
|
93
98
|
|
94
99
|
case status
|
95
100
|
when 200
|
96
|
-
extract_output(payload)
|
101
|
+
result = extract_output(payload)
|
102
|
+
|
103
|
+
if (cursor = headers["x-cursor"])
|
104
|
+
enumerator = Enumerator.new(result) {
|
105
|
+
arguments[:cursor] = cursor.to_s
|
106
|
+
call(proc, input, **arguments)
|
107
|
+
}
|
108
|
+
|
109
|
+
if block
|
110
|
+
enumerator.each(&block)
|
111
|
+
else
|
112
|
+
enumerator
|
113
|
+
end
|
114
|
+
else
|
115
|
+
result
|
116
|
+
end
|
97
117
|
when 400
|
98
118
|
raise Proc::Invalid, extract_error_message(payload)
|
99
119
|
when 401
|
@@ -156,7 +176,7 @@ class Proc
|
|
156
176
|
@internal.call(:post, build_uri(proc), headers: headers, body: Oj.dump(body)) do |response|
|
157
177
|
@remaining = response.headers["x-rate-limit-remaining"].to_s.to_i
|
158
178
|
@resets_at = Time.at(response.headers["x-rate-limit-reset"].to_s.to_i)
|
159
|
-
[response.status, Oj.load(response.read)]
|
179
|
+
[response.status, response.headers, Oj.load(response.read)]
|
160
180
|
end
|
161
181
|
rescue
|
162
182
|
raise Proc::Unavailable
|
data/lib/proc/composition.rb
CHANGED
@@ -15,7 +15,7 @@ class Proc
|
|
15
15
|
@callables = @callables.dup
|
16
16
|
end
|
17
17
|
|
18
|
-
def call(input = input_omitted = true, **arguments)
|
18
|
+
def call(input = input_omitted = true, **arguments, &block)
|
19
19
|
callable = self.class.new(
|
20
20
|
client: @client,
|
21
21
|
input: input_omitted ? @input : input,
|
@@ -23,7 +23,7 @@ class Proc
|
|
23
23
|
arguments: @arguments.merge(arguments)
|
24
24
|
)
|
25
25
|
|
26
|
-
@client.call("exec", Proc.undefined, proc: callable)
|
26
|
+
@client.call("exec", Proc.undefined, proc: callable, &block)
|
27
27
|
end
|
28
28
|
|
29
29
|
def with(input = input_omitted = true, **arguments)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Proc
|
4
|
+
class Enumerator
|
5
|
+
include Enumerable
|
6
|
+
|
7
|
+
def initialize(values, &next_block)
|
8
|
+
@values = values
|
9
|
+
@next_block = next_block
|
10
|
+
end
|
11
|
+
|
12
|
+
def each(&block)
|
13
|
+
return to_enum(:each) unless block
|
14
|
+
|
15
|
+
@values.each(&block)
|
16
|
+
@next_block.call.each(&block)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/proc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.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-02
|
11
|
+
date: 2021-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: async-http
|
@@ -65,6 +65,7 @@ files:
|
|
65
65
|
- lib/proc/callable.rb
|
66
66
|
- lib/proc/client.rb
|
67
67
|
- lib/proc/composition.rb
|
68
|
+
- lib/proc/enumerator.rb
|
68
69
|
- lib/proc/http/client.rb
|
69
70
|
- lib/proc/http/request.rb
|
70
71
|
- lib/proc/http/response.rb
|