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:

  • (defaults to: {})


22
23
24
25
26
# File 'lib/graylogapi/client.rb', line 22

def initialize(options = {})
  @options = options
  uri = URI.parse(options[:base_url])
  @http = Net::HTTP.new(uri.host, uri.port)
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

#json_request(method, path, params = {}) ⇒ Object

Make request to the API

Parameters:

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

  • url

  • (defaults to: {})

    request params

Returns:

  • Struct



34
35
36
37
38
39
40
41
42
43
# File 'lib/graylogapi/client.rb', line 34

def json_request(method, path, params = {})
  request = request(method, path, params)
  request.basic_auth(options[:user], options[:pass])
  request.add_field('Content-Type', 'application/json')
  response = @http.request(request)

  Response.new(response)
rescue
  response
end