Class: MistralClient::Client
- Inherits:
-
Object
- Object
- MistralClient::Client
show all
- Defined in:
- lib/mistral_client/client.rb
Constant Summary
collapse
- DEFAULT_HTTP_OPTIONS =
{ verify: true }.freeze
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(base, options = {}) ⇒ Client
Returns a new instance of Client.
5
6
7
8
9
10
|
# File 'lib/mistral_client/client.rb', line 5
def initialize(base, options = {})
raise ConfigurationError, 'base is required' if base.to_s.empty?
@base = base
@http_options = DEFAULT_HTTP_OPTIONS.merge(options)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **kwargs, &block) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/mistral_client/client.rb', line 41
def method_missing(name, *args, **kwargs, &block)
if self.class.resources.keys.include?(name)
if kwargs.nil? || kwargs.empty?
self.class.resources[name].new(self, *args)
else
self.class.resources[name].new(self, *args, **kwargs)
end
else
super
end
end
|
Instance Method Details
#delete(path) ⇒ Object
12
13
14
|
# File 'lib/mistral_client/client.rb', line 12
def delete(path)
HTTParty.delete("#{@base}/#{path}", @http_options)
end
|
#get(path) ⇒ Object
16
17
18
19
20
|
# File 'lib/mistral_client/client.rb', line 16
def get(path)
resp = HTTParty.get("#{@base}/#{path}", @http_options)
check_for_error(resp)
JSON.parse(resp.body)
end
|
#post(path, body, json: false) ⇒ Object
22
23
24
|
# File 'lib/mistral_client/client.rb', line 22
def post(path, body, json: false)
post_or_put(:post, path, body, json)
end
|
#put(path, body, json: false) ⇒ Object
26
27
28
|
# File 'lib/mistral_client/client.rb', line 26
def put(path, body, json: false)
post_or_put(:put, path, body, json)
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
53
54
55
|
# File 'lib/mistral_client/client.rb', line 53
def respond_to_missing?(name, include_private = false)
self.class.resources.keys.include?(name) || super
end
|