Class: WebFunction::Client
- Inherits:
-
Object
- Object
- WebFunction::Client
show all
- Defined in:
- lib/web_function/client.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(package, bearer_auth: nil, pipeline: nil) ⇒ Client
Returns a new instance of Client.
5
6
7
8
9
10
|
# File 'lib/web_function/client.rb', line 5
def initialize(package, bearer_auth: nil, pipeline: nil)
@package = package
@endpoints = package.endpoints.to_h { |e| [e.name.gsub("-", "_").to_sym, e] }
@bearer_auth = bearer_auth
@pipeline = pipeline
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/web_function/client.rb', line 33
def method_missing(method_name, *args)
endpoint = @endpoints[method_name]
unless endpoint
super
end
url = URI.join(@package.base_url, endpoint.name).to_s
args = args.first
if @pipeline
step = Endpoint.invoke(url, bearer_auth: @bearer_auth, args: args, as_step: true)
promise = @pipeline.add_step(step)
return promise
end
Endpoint.invoke(url, bearer_auth: @bearer_auth, args: args)
end
|
Instance Attribute Details
#package ⇒ Object
Returns the value of attribute package.
12
13
14
|
# File 'lib/web_function/client.rb', line 12
def package
@package
end
|
Class Method Details
.from_package_endpoint(url, bearer_auth: nil, pipeline_url: nil, pipeline: nil) ⇒ Object
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/web_function/client.rb', line 14
def self.from_package_endpoint(url, bearer_auth: nil, pipeline_url: nil, pipeline: nil)
response = Endpoint.invoke(url, bearer_auth: bearer_auth)
package = Package.new(response)
if pipeline.is_a?(String)
pipeline = WebFunction::Pipeline.new(pipeline)
end
new(package, bearer_auth: bearer_auth, pipeline: pipeline)
end
|
Instance Method Details
#methods ⇒ Object
25
26
27
|
# File 'lib/web_function/client.rb', line 25
def methods
super + @endpoints.keys
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
29
30
31
|
# File 'lib/web_function/client.rb', line 29
def respond_to_missing?(method_name, include_private = false)
@endpoints[method_name] || super
end
|