Class: GraylogAPI::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/graylogapi/client.rb,
lib/graylogapi/client/response.rb

Overview

The client is the entry point to the api

Defined Under Namespace

Classes: Response

Constant Summary collapse

METHODS =
{
  delete: Net::HTTP::Delete,
  get: Net::HTTP::Get,
  post: Net::HTTP::Post,
  put: Net::HTTP::Put
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ GraylogAPI::Client

Initializes a new Client object

Parameters:

  • options (Hash) (defaults to: {})
    • :base_url [String] Endpoint of graylog API

    • :user [String] Username

    • :pass [String] Password

    • :token [String] Token

    • :read_timeout [Integer] Read timeout of http request in seconds (60 default)

    • :open_timeout [Integer] Open timeout of http request in secods (60 default)



28
29
30
31
32
# File 'lib/graylogapi/client.rb', line 28

def initialize(options = {})
  @options = options
  @options[:base_url] = options[:base_url].chomp('/')
  @http = http_client(URI.parse(options[:base_url]), options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns options of object [Hash].

Returns:

  • options of object [Hash]



16
17
18
# File 'lib/graylogapi/client.rb', line 16

def options
  @options
end

Instance Method Details

#request(method, path, params = {}) ⇒ GraylogAPI::Client::Response

Make request to the API

Parameters:

  • method (Symbol)

    can be :get, :post, :delete, :put

  • path (String)

    url

  • params (Hash) (defaults to: {})

    request params

Returns:



40
41
42
43
44
45
46
47
# File 'lib/graylogapi/client.rb', line 40

def request(method, path, params = {})
  request = make_request(method, path, params)
  request.add_field('Content-Type', 'application/json')
  request.basic_auth(username, password)
  response = @http.request(request)

  Response.new(response)
end