Class: Libnotify::API

Inherits:
Object
  • Object
show all
Includes:
FFI
Defined in:
lib/libnotify/api.rb

Overview

API for Libnotify

See Also:

Class Attribute Summary (collapse)

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from FFI

attach_functions!, included, load_libs, #method_missing

Constructor Details

- (API) initialize(options = {}, &block)

Creates a notification object.

See Also:



27
28
29
30
# File 'lib/libnotify/api.rb', line 27

def initialize(options={}, &block)
  set_defaults
  apply_options(options, &block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Libnotify::FFI

Class Attribute Details

+ (Object) icon_dirs

List of globs to icons



16
17
18
# File 'lib/libnotify/api.rb', line 16

def icon_dirs
  @icon_dirs
end

Instance Attribute Details

- (Object) append

Returns the value of attribute append



12
13
14
# File 'lib/libnotify/api.rb', line 12

def append
  @append
end

- (Object) body

Returns the value of attribute body



12
13
14
# File 'lib/libnotify/api.rb', line 12

def body
  @body
end

- (Object) icon_path

Returns the value of attribute icon_path



11
12
13
# File 'lib/libnotify/api.rb', line 11

def icon_path
  @icon_path
end

- (Object) summary

Returns the value of attribute summary



12
13
14
# File 'lib/libnotify/api.rb', line 12

def summary
  @summary
end

- (Object) timeout

Returns the value of attribute timeout



11
12
13
# File 'lib/libnotify/api.rb', line 11

def timeout
  @timeout
end

- (Object) transient

Returns the value of attribute transient



12
13
14
# File 'lib/libnotify/api.rb', line 12

def transient
  @transient
end

- (Object) urgency

Returns the value of attribute urgency



12
13
14
# File 'lib/libnotify/api.rb', line 12

def urgency
  @urgency
end

Class Method Details

+ (Object) show(options = {}, &block)

Creates and shows a notification. It's a shortcut for Libnotify.new(options).show!.



122
123
124
# File 'lib/libnotify/api.rb', line 122

def self.show(options={}, &block)
  new(options, &block).show!
end

Instance Method Details

- (Object) close

Close a previously shown notification.



78
79
80
# File 'lib/libnotify/api.rb', line 78

def close
  notify_notification_close(@notification, nil) if @notification
end

- (Object) show

Shows an existing notification.



57
58
59
60
61
62
63
64
# File 'lib/libnotify/api.rb', line 57

def show
  notify_notification_set_urgency(@notification, urgency)
  notify_notification_set_timeout(@notification, timeout || -1)
  set_hints
  notify_notification_show(@notification, nil)
ensure
  clear_hints
end

- (Object) show!

Shows a new notification.

See Also:



50
51
52
53
54
# File 'lib/libnotify/api.rb', line 50

def show!
  notify_init(self.class.to_s) or raise "notify_init failed"
  @notification = notify_notification_new(summary, body, icon_path, nil)
  show
end

- (Object) update(options = {}, &block)

Updates a previously shown notification or creates a new one.



67
68
69
70
71
72
73
74
75
# File 'lib/libnotify/api.rb', line 67

def update(options={}, &block)
  apply_options(options, &block)
  if @notification
    notify_notification_update(@notification, summary, body, icon_path, nil)
    show
  else
    show!
  end
end