Class: Minds::Client

Inherits:
Object
  • Object
show all
Includes:
RestClient
Defined in:
lib/minds/client.rb

Constant Summary collapse

SENSITIVE_ATTRIBUTES =
%i[@base_url @api_key].freeze
CONFIG_KEYS =
%i[base_url api_key log_errors api_version].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RestClient

#delete, #get, #patch, #post, #put

Constructor Details

#initialize(options = {}, &faraday_middleware) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
# File 'lib/minds/client.rb', line 11

def initialize(options = {}, &faraday_middleware)
  # if key not present. Fall back to global config
  CONFIG_KEYS.each do |key|
    instance_variable_set "@#{key}", options[key] || Client.config.send(key)
  end

  @faraday_middleware = faraday_middleware
end

Class Method Details

.configObject



21
22
23
# File 'lib/minds/client.rb', line 21

def config
  @config ||= Config::Base.new
end

.configure {|config| ... } ⇒ Object

Yields:



25
26
27
# File 'lib/minds/client.rb', line 25

def configure
  yield(config) if block_given?
end

Instance Method Details

#datasourcesObject



30
31
32
# File 'lib/minds/client.rb', line 30

def datasources
  @datasources ||= Datasources.new(client: self)
end

#inspectObject



38
39
40
41
42
43
44
45
46
# File 'lib/minds/client.rb', line 38

def inspect
  vars = instance_variables.map do |var|
    value = instance_variable_get(var)

    SENSITIVE_ATTRIBUTES.include?(var) ? "#{var}=[FILTERED]" : "#{var}=#{value.inspect}"
  end

  "#<#{self.class}:0x#{object_id.to_s(16)} #{vars.join(', ')}>"
end

#mindsObject



34
35
36
# File 'lib/minds/client.rb', line 34

def minds
  @minds ||= Minds.new(client: self)
end