Class: EveryLog::Client

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/everylog_ruby_client.rb

Constant Summary collapse

SETUP_DEFAULTS =
{
  api_key: nil,
  projectId: nil,
  everylog_url: "https://api.everylog.io/api/v1/log-entries"
}.freeze
NOTIFY_DEFAULTS =
{
  title: "Empty notification",
  summary: "Empty summary",
  body: "Empty body",
  tags: [],
  link: "",
  push: false
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



26
27
28
# File 'lib/everylog_ruby_client.rb', line 26

def options
  @options
end

Instance Method Details

#notify(notify_options = {}) ⇒ Object

Parameters:

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

Options Hash (notify_options):

  • :projectId (String, options[:projectId])

    name of the project

  • :title (String)

    to display in the application and if enabled in the notification

  • :summary (String)

    is a not so long text to display on the application and if enabled in the notification

  • :body (String)

    it can contain a long text simple formatted, no html to display in the application

  • :tags (Array)

    it can be used to categorize the notification, must be strings

  • :link (String)

    it can be used to display on the application and if enabled in the notification

  • :push (Boolean)

    if True, a push notification is sent to application



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/everylog_ruby_client.rb', line 46

def notify(notify_options = {})
  @notify_options = _parse_options(notify_options, NOTIFY_DEFAULTS)
  merged_options  = { projectId: options[:projectId] }.merge(@notify_options)
  uri             = URI(options[:everylog_url])
  http            = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl    = true
  req             = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json', "Authorization": "Bearer #{options[:api_key]}")
  req.body        = merged_options.to_json
  res             = http.request(req)
  res.body
end

#setup(options = {}) ⇒ Object

Parameters:

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

Options Hash (options):

  • :api_key (String)

    for authenticate against Everylog server

  • :projectId (String)

    name of the project

  • :everylog_url (String) — default: https://api.everylog.io/api/v1/log-entries

    to reach Everlog server



32
33
34
35
# File 'lib/everylog_ruby_client.rb', line 32

def setup(options = {})
  @options = _parse_options(options, SETUP_DEFAULTS)
  self
end