proc 0.4.0 → 0.5.0

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: 63d146f97fd1dc28e5ff40ae924ac80e5f34838da4a3bb626b51023c2e23efbc
4
- data.tar.gz: ebbab25f52bc3344c9fee6e10a00af6ed5022808d05f8516c41dc914987178d6
3
+ metadata.gz: a3b65698431242010b57cb9897c5ddf826cbd9c81dea9a3947505062e8060aeb
4
+ data.tar.gz: bf1d1caaa7fffda8b8eac8d65c50b29a4c95003d980b8c83962f65bed8e1749e
5
5
  SHA512:
6
- metadata.gz: 06f06ba059619e117f86021bfeda3b5520d6842664d5fb284c77e7920cae38b66d4e82874329243ee0e456216034a07111e04f8b49ffaf6828470eb8a0e7f2fc
7
- data.tar.gz: d6b1423b158de5320e963c48a988db2936c5c576eb3e02b2ec9d2d675ff54ca6c428e270baaf566935bf8df2fd18b9b59e67449c5ed661d5c57d7a4b75a8f41b
6
+ metadata.gz: ba18a8388e58dfe25119b412274b13eaf7cf684fc33e2ca186c8527c85a6f8973ecf01d39c9f56b861456646262b0a0fbaf9272feaec44ce178f328e1c6349ca
7
+ data.tar.gz: 77ecd00cf5f48da5e17e80da46b2f0145ec1c8ae87d710d0b423d3e1908f7fdbc13fe251b9efee67289b5f20e1711b81a2c186fc0a48a9042aaff02413a8cdc8
data/lib/proc/argument.rb CHANGED
@@ -8,7 +8,7 @@ class Proc
8
8
  end
9
9
 
10
10
  def serialize
11
- {"::" => {"name" => @name.to_s}.merge(serialized_options)}
11
+ ["@@", @name.to_s, serialized_options]
12
12
  end
13
13
 
14
14
  def serialized_options
@@ -21,7 +21,7 @@ class Proc
21
21
  if value.respond_to?(:serialize)
22
22
  value.serialize
23
23
  else
24
- value
24
+ ["%%", value]
25
25
  end
26
26
  end
27
27
  end
data/lib/proc/callable.rb CHANGED
@@ -24,7 +24,7 @@ class Proc
24
24
  arguments: @arguments.merge(arguments)
25
25
  )
26
26
 
27
- @client.call(@proc, callable.serialized_input, **callable.serialized_arguments)
27
+ @client.call(@proc, callable.input, **callable.arguments)
28
28
  end
29
29
 
30
30
  def with(input = input_omitted = true, **arguments)
@@ -44,13 +44,15 @@ class Proc
44
44
  end
45
45
 
46
46
  def serialize
47
- wrapped = {"[]" => [[@proc, serialized_arguments]]}
47
+ serialized = ["()", @proc]
48
48
 
49
49
  unless Proc.undefined?(@input)
50
- wrapped["<<"] = serialized_input
50
+ serialized << [">>", serialized_input]
51
51
  end
52
52
 
53
- {"{}" => wrapped}
53
+ serialized.concat(serialized_arguments)
54
+
55
+ ["{}", serialized]
54
56
  end
55
57
 
56
58
  def serialized_input
@@ -58,8 +60,8 @@ class Proc
58
60
  end
59
61
 
60
62
  def serialized_arguments
61
- @arguments.each_pair.each_with_object({}) { |(key, value), hash|
62
- hash[key.to_s] = serialize_value(value)
63
+ @arguments.map { |key, value|
64
+ ["$$", key.to_s, serialize_value(value)]
63
65
  }
64
66
  end
65
67
 
@@ -99,7 +101,7 @@ class Proc
99
101
  if value.respond_to?(:serialize)
100
102
  value.serialize
101
103
  else
102
- value
104
+ ["%%", value]
103
105
  end
104
106
  end
105
107
  end
data/lib/proc/client.rb CHANGED
@@ -65,46 +65,48 @@ class Proc
65
65
  end
66
66
 
67
67
  DEFAULT_HEADERS = {
68
- "accept" => "application/json",
69
- "content-type" => "application/json"
68
+ "accept" => "application/vnd.proc+json",
69
+ "content-type" => "application/vnd.proc+json"
70
70
  }.freeze
71
71
 
72
- def call(proc = nil, input = nil, **arguments)
73
- body = {"<>" => true}
72
+ def call(proc = nil, input = Proc.undefined, **arguments)
73
+ body = []
74
74
 
75
75
  unless Proc.undefined?(input)
76
- body["<<"] = serialize_value(input)
76
+ body << [">>", serialize_value(input)]
77
77
  end
78
78
 
79
79
  arguments.each_pair do |key, value|
80
- body[key.to_s] = serialize_value(value)
80
+ body << ["$$", key.to_s, serialize_value(value)]
81
81
  end
82
82
 
83
83
  headers = {
84
84
  "authorization" => "bearer #{@authorization}"
85
85
  }.merge(DEFAULT_HEADERS)
86
86
 
87
- payload = get_payload(proc: proc, headers: headers, body: body)
87
+ status, payload = get_payload(proc: proc, headers: headers, body: body)
88
88
 
89
- case payload["status"]
89
+ case status
90
90
  when 200
91
- payload[">>"]
91
+ extract_output(payload)
92
92
  when 400
93
- raise Proc::Invalid, payload.dig("error", "message")
93
+ raise Proc::Invalid, extract_error_message(payload)
94
94
  when 401
95
- raise Proc::Unauthorized, payload.dig("error", "message")
95
+ raise Proc::Unauthorized, extract_error_message(payload)
96
96
  when 403
97
- raise Proc::Forbidden, payload.dig("error", "message")
97
+ raise Proc::Forbidden, extract_error_message(payload)
98
98
  when 404
99
- raise Proc::Undefined, payload.dig("error", "message")
99
+ raise Proc::Undefined, extract_error_message(payload)
100
100
  when 408
101
- raise Proc::Timeout, payload.dig("error", "message")
101
+ raise Proc::Timeout, extract_error_message(payload)
102
+ when 413
103
+ raise Proc::Invalid, extract_error_message(payload)
102
104
  when 429
103
- raise Proc::Limited, payload.dig("error", "message")
105
+ raise Proc::Limited, extract_error_message(payload)
104
106
  when 500
105
- raise Proc::Error, payload.dig("error", "message")
107
+ raise Proc::Error, extract_error_message(payload)
106
108
  when 508
107
- raise Proc::Error, payload.dig("error", "message")
109
+ raise Proc::Error, extract_error_message(payload)
108
110
  else
109
111
  raise Proc::Error, "unhandled"
110
112
  end
@@ -141,21 +143,44 @@ class Proc
141
143
  if value.respond_to?(:serialize)
142
144
  value.serialize
143
145
  else
144
- value
146
+ ["%%", value]
145
147
  end
146
148
  end
147
149
 
148
150
  private def get_payload(proc:, headers:, body:)
149
- @internal.call(:post, build_uri(proc), headers: headers, body: Oj.dump(body, mode: :custom)) { |response|
151
+ @internal.call(:post, build_uri(proc), headers: headers, body: Oj.dump(body, mode: :custom)) do |response|
150
152
  @remaining = response.headers["x-rate-limit-remaining"].to_s.to_i
151
153
  @resets_at = Time.at(response.headers["x-rate-limit-reset"].to_s.to_i)
152
-
153
- payload = Oj.load(response.read, mode: :compat, compat_bigdecimal: true)
154
- payload["status"] = response.status
155
- payload
156
- }
154
+ [response.status, Oj.load(response.read, mode: :compat, compat_bigdecimal: true)]
155
+ end
157
156
  rescue
158
157
  raise Proc::Unavailable
159
158
  end
159
+
160
+ private def extract_output(payload)
161
+ payload.each do |tuple|
162
+ case tuple[0]
163
+ when "<<"
164
+ return tuple[1]
165
+ end
166
+ end
167
+
168
+ nil
169
+ end
170
+
171
+ private def extract_error(payload)
172
+ payload.each do |tuple|
173
+ case tuple[0]
174
+ when "!!"
175
+ return tuple[1]
176
+ end
177
+ end
178
+
179
+ nil
180
+ end
181
+
182
+ private def extract_error_message(payload)
183
+ extract_error(payload)&.dig("message")
184
+ end
160
185
  end
161
186
  end
@@ -23,7 +23,7 @@ class Proc
23
23
  arguments: @arguments.merge(arguments)
24
24
  )
25
25
 
26
- @client.call("proc.exec", nil, proc: callable.serialize)
26
+ @client.call("proc.exec", Proc.undefined, proc: callable)
27
27
  end
28
28
 
29
29
  def with(input = input_omitted = true, **arguments)
@@ -51,24 +51,32 @@ class Proc
51
51
  end
52
52
 
53
53
  def serialize
54
- wrapped = {"[]" => serialized_calls}
54
+ # wrapped = {"[]" => serialized_calls}
55
+
56
+ # unless Proc.undefined?(@input)
57
+ # wrapped["<<"] = serialized_input
58
+ # end
59
+
60
+ # {"{}" => wrapped.merge(serialized_arguments)}
61
+
62
+ serialized = ["{}"]
55
63
 
56
64
  unless Proc.undefined?(@input)
57
- wrapped["<<"] = serialized_input
65
+ serialized << [">>", serialized_input]
58
66
  end
59
67
 
60
- {"{}" => wrapped.merge(serialized_arguments)}
68
+ serialized + serialized_arguments + serialized_calls
61
69
  end
62
70
 
63
71
  def serialized_calls
64
72
  @callables.map { |callable|
65
- arguments = callable.serialized_arguments
73
+ serialized = ["()", callable.proc]
66
74
 
67
75
  unless Proc.undefined?(callable.input)
68
- arguments["<<"] = callable.serialized_input
76
+ serialized << [">>", callable.serialized_input]
69
77
  end
70
78
 
71
- [callable.proc, arguments]
79
+ serialized.concat(callable.serialized_arguments)
72
80
  }
73
81
  end
74
82
 
@@ -77,8 +85,8 @@ class Proc
77
85
  end
78
86
 
79
87
  def serialized_arguments
80
- @arguments.each_pair.each_with_object({}) { |(key, value), hash|
81
- hash[key.to_s] = serialize_value(value)
88
+ @arguments.map { |key, value|
89
+ ["$$", key.to_s, serialize_value(value)]
82
90
  }
83
91
  end
84
92
 
@@ -93,7 +101,7 @@ class Proc
93
101
  if value.respond_to?(:serialize)
94
102
  value.serialize
95
103
  else
96
- value
104
+ ["%%", value]
97
105
  end
98
106
  end
99
107
  end
data/lib/proc/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Proc
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
 
6
6
  def self.version
7
7
  VERSION
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.0
4
+ version: 0.5.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-01-20 00:00:00.000000000 Z
11
+ date: 2021-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-http