Class: Logplex::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/logplex/namespace.rb,
lib/logplex/client/cli.rb,
lib/logplex/client/version.rb,
lib/logplex/client.rb

Overview

Public: a logplex client.

This class allows you to access logplex as a client; reading and writing logs, creating channels, tokens, etc.

For logplex’s HTTP API, see logplex.herokuapp.com

Examples

client = Logplex::Client.new("https://user:[email protected]/")
channel = client.create_channel("my-example-channel")
TODO(sissel): Complete this example.

Defined Under Namespace

Modules: Backends Classes: CLI

Constant Summary collapse

VERSION =

The version of this library.

"0.1.8"

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ Client

Public: Initialize a client pointing at a given url.

url - a url (including user+pass) to your logplex service

Examples

Logplex::Client.new("https://user:[email protected]/")


27
28
29
30
# File 'lib/logplex/client.rb', line 27

def initialize(url)
  @url = url
  @backend = Logplex::Client::Backends::HTTP.new(@url)
end

Instance Method Details

#channel(channel_id) ⇒ Object

Public: Get a Logplex::Channel instance with a given id.

If you have already created a channel, this is how you access it later.

channel_id - the channel id (number)

Returns a Logplex::Channel Raises TODO(sissel): ??? if the channel is not found



59
60
61
62
63
64
65
66
# File 'lib/logplex/client.rb', line 59

def channel(channel_id)
  # This will throw an exception if it doesn't exist.
  result = @backend.get_channel(channel_id)
  chan = Logplex::Channel.new(@url, channel_id)
  # Hack for now to push the result of get_channel into the Channel.
  chan.instance_eval { @info = result } 
  return chan
end

#create_channel(name) ⇒ Object

Public: Create a channel.

Note: the ‘name’ of the channel lives in a global namespace. Choose wisely. Note: You must save the channel id if you wish to use the channel later.

name - the string name to give to the channel being created.

Examples

client.create_channel("my-example-channel")

Returns a Logplex::Channel Raises TODO(sissel): Raises what?



45
46
47
48
49
# File 'lib/logplex/client.rb', line 45

def create_channel(name)
  # TODO(sissel): Call the API
  result = @backend.create_channel(name)
  return Logplex::Channel.new(@url, result[:channel_id])
end

#session(session_id) ⇒ Object

Public: Get a Session instance with a given id.

If you have already created a session, this is how you access it later.

session_id - the session id (number)

Returns a Session Raises TODO(sissel): ??? if the session is not found

Raises:

  • (NotImplemented)


76
77
78
# File 'lib/logplex/client.rb', line 76

def session(session_id)
  raise NotImplemented
end