web_function 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/web_function/client.rb +14 -3
- data/lib/web_function/endpoint.rb +13 -1
- data/lib/web_function/pipeline.rb +25 -0
- data/lib/web_function/promise.rb +45 -0
- data/lib/web_function/version.rb +1 -1
- data/lib/web_function.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c7620ed2512ab7259a75a030dde6b4fdf41d781f09657027097a0d5dc7edfaf5
|
|
4
|
+
data.tar.gz: c99d5308bb8acd767bde97edbf18715bb836a147702d65f3608ca978978a9eb8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4b73307d8eabd0db7734aa42af1c83e12d71519dc21f2ab66df71e80330db92bf1bcbbeb8d9bf823431c00a7de8f7fcb86001161605656d1dccae596161ca5df
|
|
7
|
+
data.tar.gz: 0b0ca68068da0c6257b0a4e4894c3a6349e881c3778530c2dcd6e9439ea0a651a6a7b1ea83423eef415bbe37426c59dd2f9aa9fdf7a97117fb09e84c096bc814
|
data/lib/web_function/client.rb
CHANGED
|
@@ -2,19 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
module WebFunction
|
|
4
4
|
class Client
|
|
5
|
-
def initialize(package, bearer_auth: nil)
|
|
5
|
+
def initialize(package, bearer_auth: nil, pipeline: nil)
|
|
6
6
|
@package = package
|
|
7
7
|
@endpoints = package.endpoints.to_h { |e| [e.name.gsub("-", "_").to_sym, e] }
|
|
8
8
|
@bearer_auth = bearer_auth
|
|
9
|
+
@pipeline = pipeline
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
attr_reader :package
|
|
12
13
|
|
|
13
|
-
def self.from_package_endpoint(url, bearer_auth: nil)
|
|
14
|
+
def self.from_package_endpoint(url, bearer_auth: nil, pipeline_url: nil, pipeline: nil)
|
|
14
15
|
response = Endpoint.invoke(url, bearer_auth: bearer_auth)
|
|
15
16
|
package = Package.new(response)
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
if pipeline.is_a?(String)
|
|
19
|
+
pipeline = WebFunction::Pipeline.new(pipeline)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
new(package, bearer_auth: bearer_auth, pipeline: pipeline)
|
|
18
23
|
end
|
|
19
24
|
|
|
20
25
|
def methods
|
|
@@ -35,6 +40,12 @@ module WebFunction
|
|
|
35
40
|
url = URI.join(@package.base_url, endpoint.name).to_s
|
|
36
41
|
args = args.first
|
|
37
42
|
|
|
43
|
+
if @pipeline
|
|
44
|
+
step = Endpoint.invoke(url, bearer_auth: @bearer_auth, args: args, as_step: true)
|
|
45
|
+
promise = @pipeline.add_step(step)
|
|
46
|
+
return promise
|
|
47
|
+
end
|
|
48
|
+
|
|
38
49
|
Endpoint.invoke(url, bearer_auth: @bearer_auth, args: args)
|
|
39
50
|
end
|
|
40
51
|
end
|
|
@@ -6,17 +6,29 @@ module WebFunction
|
|
|
6
6
|
@endpoint = endpoint
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
def self.invoke(url, bearer_auth: nil, args: {})
|
|
9
|
+
def self.invoke(url, bearer_auth: nil, args: {}, as_step: false)
|
|
10
10
|
headers = {
|
|
11
11
|
"Content-Type": "application/json",
|
|
12
12
|
"Accept": "application/json",
|
|
13
13
|
"User-Agent": "webfunction/#{WebFunction::VERSION}",
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
if args.nil?
|
|
17
|
+
args = {}
|
|
18
|
+
end
|
|
19
|
+
|
|
16
20
|
if bearer_auth
|
|
17
21
|
headers["Authorization"] = "Bearer #{bearer_auth}"
|
|
18
22
|
end
|
|
19
23
|
|
|
24
|
+
if as_step
|
|
25
|
+
return {
|
|
26
|
+
url: url,
|
|
27
|
+
headers: headers,
|
|
28
|
+
body: args,
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
|
|
20
32
|
response = Excon.post(url,
|
|
21
33
|
headers: headers,
|
|
22
34
|
body: JSON.generate(args),
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module WebFunction
|
|
2
|
+
class Pipeline
|
|
3
|
+
def initialize(url)
|
|
4
|
+
@url = url
|
|
5
|
+
@steps = []
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def add_step(step)
|
|
9
|
+
n = @steps.count
|
|
10
|
+
@steps << step
|
|
11
|
+
Promise.new(self, "$[#{n}]")
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def execute(returns: "$")
|
|
15
|
+
if returns.to_sym == :last
|
|
16
|
+
returns = "$[-1:]"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
Endpoint.invoke(@url, args: {
|
|
20
|
+
steps: @steps,
|
|
21
|
+
returns: returns,
|
|
22
|
+
})
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module WebFunction
|
|
2
|
+
class Promise
|
|
3
|
+
def initialize(pipeline, path)
|
|
4
|
+
@pipeline = pipeline
|
|
5
|
+
@path = path
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def to_s
|
|
9
|
+
@path
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def to_json(*args)
|
|
13
|
+
@path.to_json(*args)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def resolve
|
|
17
|
+
@pipeline.execute(returns: :last)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def [](key)
|
|
21
|
+
case key
|
|
22
|
+
when String
|
|
23
|
+
mutate("#{@path}[\"#{key}\"]")
|
|
24
|
+
when Integer
|
|
25
|
+
mutate("#{@path}[#{key}]")
|
|
26
|
+
else
|
|
27
|
+
raise ArgumentError
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def method_missing(name, *args)
|
|
32
|
+
if block_given? || args.any?
|
|
33
|
+
super
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
mutate("#{@path}.#{name}")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def mutate(path)
|
|
42
|
+
Promise.new(@pipeline, path)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
data/lib/web_function/version.rb
CHANGED
data/lib/web_function.rb
CHANGED
|
@@ -11,6 +11,8 @@ require_relative "web_function/endpoint"
|
|
|
11
11
|
require_relative "web_function/argument"
|
|
12
12
|
require_relative "web_function/attribute"
|
|
13
13
|
require_relative "web_function/documented_error"
|
|
14
|
+
require_relative "web_function/pipeline"
|
|
15
|
+
require_relative "web_function/promise"
|
|
14
16
|
|
|
15
17
|
module WebFunction
|
|
16
18
|
class Error < StandardError
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: web_function
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Robin Clart
|
|
@@ -61,6 +61,8 @@ files:
|
|
|
61
61
|
- lib/web_function/documented_error.rb
|
|
62
62
|
- lib/web_function/endpoint.rb
|
|
63
63
|
- lib/web_function/package.rb
|
|
64
|
+
- lib/web_function/pipeline.rb
|
|
65
|
+
- lib/web_function/promise.rb
|
|
64
66
|
- lib/web_function/version.rb
|
|
65
67
|
- sig/web_function.rbs
|
|
66
68
|
homepage: https://github.com/robinclart/web_function
|
|
@@ -86,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
86
88
|
- !ruby/object:Gem::Version
|
|
87
89
|
version: '0'
|
|
88
90
|
requirements: []
|
|
89
|
-
rubygems_version:
|
|
91
|
+
rubygems_version: 4.0.5
|
|
90
92
|
specification_version: 4
|
|
91
93
|
summary: A Web Function Client for Ruby
|
|
92
94
|
test_files: []
|