Class: Influxdb::Api::Client

Inherits:
Object
  • Object
show all
Includes:
Namespaces
Defined in:
lib/influxdb/api/client.rb,
lib/influxdb/api/client/errors.rb,
lib/influxdb/api/client/response.rb,
lib/influxdb/api/client/selector.rb,
lib/influxdb/api/client/connection.rb,
lib/influxdb/api/client/connection_pool.rb

Defined Under Namespace

Modules: Errors, Selector Classes: Connection, ConnectionPool, Error, Response, ServerError

Constant Summary collapse

HTTP_STATUSES =
{
  300 => 'MultipleChoices',
  301 => 'MovedPermanently',
  302 => 'Found',
  303 => 'SeeOther',
  304 => 'NotModified',
  305 => 'UseProxy',
  307 => 'TemporaryRedirect',
  308 => 'PermanentRedirect',

  400 => 'BadRequest',
  401 => 'Unauthorized',
  402 => 'PaymentRequired',
  403 => 'Forbidden',
  404 => 'NotFound',
  405 => 'MethodNotAllowed',
  406 => 'NotAcceptable',
  407 => 'ProxyAuthenticationRequired',
  408 => 'RequestTimeout',
  409 => 'Conflict',
  410 => 'Gone',
  411 => 'LengthRequired',
  412 => 'PreconditionFailed',
  413 => 'RequestEntityTooLarge',
  414 => 'RequestURITooLong',
  415 => 'UnsupportedMediaType',
  416 => 'RequestedRangeNotSatisfiable',
  417 => 'ExpectationFailed',
  418 => 'ImATeapot',
  421 => 'TooManyConnectionsFromThisIP',
  426 => 'UpgradeRequired',
  450 => 'BlockedByWindowsParentalControls',
  494 => 'RequestHeaderTooLarge',
  497 => 'HTTPToHTTPS',
  499 => 'ClientClosedRequest',

  500 => 'InternalServerError',
  501 => 'NotImplemented',
  502 => 'BadGateway',
  503 => 'ServiceUnavailable',
  504 => 'GatewayTimeout',
  505 => 'HTTPVersionNotSupported',
  506 => 'VariantAlsoNegotiates',
  510 => 'NotExtended'
}
ERRORS =
HTTP_STATUSES.inject({}) do |sum, error|
  status, name = error
  sum[status] = Errors.const_set(name, Class.new(ServerError))
  sum
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Namespaces

#cluster_admins, #databases, #interfaces, #servers, #shards, #sync?, #version

Constructor Details

#initialize(config = Influxdb::Api.config) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
# File 'lib/influxdb/api/client.rb', line 8

def initialize(config = Influxdb::Api.config)
  @config = config
  @connection_pool = ConnectionPool.new(config)
  @last_request_at = Time.now
  @resurrect_after = 60
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/influxdb/api/client.rb', line 6

def config
  @config
end

Instance Method Details

#perform_request(method, path, params = {}, body = nil, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/influxdb/api/client.rb', line 15

def perform_request(method, path, params = {}, body = nil, &block)
  method = method.downcase.to_sym unless method.is_a?(Symbol)

  response = with_retry(path, params) do |connection, url|
    connection.basic_auth(config.user, config.password)
    headers = { 'Content-Type' => 'application/json' }

    connection.run_request(method, url, (body ? convert_to_json(body) : nil), headers, &block)
  end

  raise_transport_error(response) if response.status.to_i >= 300

  json = config.serializer.load(response.body) if response.headers && response.headers["content-type"] =~ /json/

  Response.new(response.status, json || response.body, response.headers)
ensure
  @last_request_at = Time.now
end