class MistralClient::Client
Constants
- DEFAULT_HTTP_OPTIONS
Public Class Methods
new(base, options = {})
click to toggle source
# 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
resources()
click to toggle source
# File lib/mistral_client/client.rb, line 30 def self.resources { action_execution: MistralClient::ActionExecution, environment: MistralClient::Environment, execution: MistralClient::Execution, health: MistralClient::Health, task: MistralClient::Task, workflow: MistralClient::Workflow } end
Public Instance Methods
delete(path)
click to toggle source
# File lib/mistral_client/client.rb, line 12 def delete(path) HTTParty.delete("#{@base}/#{path}", @http_options) end
get(path)
click to toggle source
# 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
method_missing(name, *args, **kwargs, &block)
click to toggle source
Calls superclass method
# 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
post(path, body, json: false)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
Calls superclass method
# File lib/mistral_client/client.rb, line 53 def respond_to_missing?(name, include_private = false) self.class.resources.keys.include?(name) || super end
Private Instance Methods
check_for_error(resp)
click to toggle source
# File lib/mistral_client/client.rb, line 73 def check_for_error(resp) return if resp.code >= 200 && resp.code < 300 raise MissingObjectError, JSON.parse(resp.body)['faultstring'] if resp.code == 404 raise MistralResponseError.new(resp), "Could not perform the requested operation:\n#{resp.body}" end
post_or_put(verb, path, body, json)
click to toggle source
# File lib/mistral_client/client.rb, line 59 def post_or_put(verb, path, body, json) raise ArgumentError unless %i[post put].include?(verb) headers = if json { 'Content-Type' => 'application/json' } else { 'Content-Type' => 'text/plain' } end options = @http_options.merge(headers: headers, body: body) resp = HTTParty.send(verb, "#{@base}/#{path}", options) check_for_error(resp) JSON.parse(resp.body) end