Class: Alchemrest::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/alchemrest/client.rb,
lib/alchemrest/client/configuration.rb,
lib/alchemrest/client/configuration/connection.rb

Defined Under Namespace

Classes: Configuration

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configurationObject



17
18
19
20
21
# File 'lib/alchemrest/client.rb', line 17

def self.configuration
  raise InvalidConfigurationError, "Call `configure` in your client class to setup connection details" unless @configuration

  @configuration
end

.configure(&configuration_block) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/alchemrest/client.rb', line 23

def self.configure(&configuration_block)
  @configuration = begin
    config = Alchemrest::Client::Configuration.new
    class_exec(config, &configuration_block)
    config.freeze
    config
  end
end

.inherited(subclass) ⇒ Object

rubocop:disable Lint/MissingSuper



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/alchemrest/client.rb', line 5

def self.inherited(subclass) # rubocop:disable Lint/MissingSuper
  subclass.class_eval do
    def connection
      self.class.connection
    end

    def self.connection
      @connection ||= configuration.connection.create_new_connection
    end
  end
end

.kill_switchObject



32
33
34
# File 'lib/alchemrest/client.rb', line 32

def self.kill_switch
  KillSwitch.new(service_name: configuration.service_name)
end

Instance Method Details

#build_http_request(request) ⇒ Object



40
41
42
# File 'lib/alchemrest/client.rb', line 40

def build_http_request(request)
  HttpRequest.new(request, self)
end

#build_response(raw_response) ⇒ Object



44
45
46
# File 'lib/alchemrest/client.rb', line 44

def build_response(raw_response)
  Response.new(raw_response)
end

#configurationObject



36
37
38
# File 'lib/alchemrest/client.rb', line 36

def configuration
  self.class.configuration
end