Module: Vayacondios::Client::Connection

Included in:
HttpAdmin, HttpRead, HttpWrite
Defined in:
lib/vayacondios/client/connection.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.base_uri(options) ⇒ Object



4
5
6
7
8
# File 'lib/vayacondios/client/connection.rb', line 4

def self.base_uri options
  host = options[:host] || ConnectionOpts[:host]
  port = options[:port] || ConnectionOpts[:port]
  "http://#{host}:#{port}/#{Vayacondios::API_VERSION}"
end

.factory(options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/vayacondios/client/connection.rb', line 10

def self.factory(options = {})
  Faraday.new(base_uri options) do |setup|
    setup.request  :json
    setup.adapter  options[:adapter] || ConnectionOpts[:adapter]
    setup.response :json, content_type: /\bjson$/
    if logger = options[:log] || ConnectionOpts[:log]
      setup.response :logger, logger
    end
  end
end

Instance Method Details

#configure_connection(options) ⇒ Object



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

def configure_connection options
  @connection = Connection.factory(options)
end

#http_connectionObject



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

def http_connection
  @connection ||= Connection.factory
end

#organizationObject



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

def organization
  'vcd'
end

#url(handler, topic = nil, id = nil) ⇒ Object



25
26
27
28
# File 'lib/vayacondios/client/connection.rb', line 25

def url(handler, topic = nil, id = nil)
  segments = [organization, handler, topic, id].compact.map(&:to_s)
  File.join(*segments)
end