Class: Groem::App
Constant Summary
collapse
- DEFAULT_HOST =
'localhost'
- DEFAULT_PORT =
23053
- DEFAULT_ENV =
{'protocol' => 'GNTP', 'version' => '1.0',
'request_method' => 'REGISTER', 'encryption_id' => 'NONE'
}
Constants included
from Constants
Constants::ENVIRONMENT_KEY, Constants::GNTP_APPLICATION_ICON_KEY, Constants::GNTP_APPLICATION_NAME_KEY, Constants::GNTP_CALLBACK_RESPONSE, Constants::GNTP_CLICK_CALLBACK_RESULT, Constants::GNTP_CLOSE_CALLBACK_RESULT, Constants::GNTP_DEFAULT_ENVIRONMENT, Constants::GNTP_ENCRYPTION_ID_KEY, Constants::GNTP_ERROR_CODE_KEY, Constants::GNTP_ERROR_CODE_OK, Constants::GNTP_ERROR_RESPONSE, Constants::GNTP_NOTIFICATION_CALLBACK_CONTEXT_KEY, Constants::GNTP_NOTIFICATION_CALLBACK_CONTEXT_TYPE_KEY, Constants::GNTP_NOTIFICATION_CALLBACK_RESULT_KEY, Constants::GNTP_NOTIFICATION_CALLBACK_TARGET_KEY, Constants::GNTP_NOTIFICATION_CALLBACK_TIMESTAMP_KEY, Constants::GNTP_NOTIFICATION_COUNT_KEY, Constants::GNTP_NOTIFICATION_ICON_KEY, Constants::GNTP_NOTIFICATION_ID_KEY, Constants::GNTP_NOTIFICATION_NAME_KEY, Constants::GNTP_NOTIFY_METHOD, Constants::GNTP_OK_RESPONSE, Constants::GNTP_PROTOCOL_KEY, Constants::GNTP_REGISTER_METHOD, Constants::GNTP_REQUEST_METHOD_KEY, Constants::GNTP_RESPONSE_ACTION_KEY, Constants::GNTP_RESPONSE_METHOD_KEY, Constants::GNTP_SUBSCRIBE_METHOD, Constants::GNTP_TIMEDOUT_CALLBACK_RESULT, Constants::GNTP_VERSION_KEY, Constants::HEADERS_KEY, Constants::NOTIFICATIONS_KEY
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#[](key) ⇒ Object
used by Marshal::Request#dump.
-
#binary(key, value_or_io) ⇒ Object
-
#callbacks(&blk) ⇒ Object
-
#header(key, value) ⇒ Object
-
#icon(uri_or_file) ⇒ Object
-
#initialize(name, opts = {}) ⇒ App
constructor
-
#name ⇒ Object
-
#notification(name, *args) {|n| ... } ⇒ Object
-
#notify(name, *args, &blk) ⇒ Object
-
#register(&blk) ⇒ Object
-
#to_request ⇒ Object
-
#when_callback(action, path = nil, &blk) ⇒ Object
-
#when_click(path = nil, &blk) ⇒ Object
-
#when_close(path = nil, &blk) ⇒ Object
-
#when_register(&blk) ⇒ Object
—- callback definition methods.
-
#when_register_failed(&blk) ⇒ Object
-
#when_timedout(path = nil, &blk) ⇒ Object
#dump, included
Methods included from Constants
#growlify_action, #growlify_key, included
Constructor Details
#initialize(name, opts = {}) ⇒ App
Returns a new instance of App.
15
16
17
18
19
20
21
22
|
# File 'lib/groem/app.rb', line 15
def initialize(name, opts = {})
self.environment, self., self.notifications = {}, {}, {}
self.environment = DEFAULT_ENV.merge(opts.delete(:environment) || {})
self.host = opts.delete(:host) || DEFAULT_HOST
self.port = opts.delete(:port) || DEFAULT_PORT
self.[GNTP_APPLICATION_NAME_KEY] = name
opts.each_pair {|opt, val| self.[growlify_key(opt)] = val }
end
|
Instance Attribute Details
#environment ⇒ Object
Returns the value of attribute environment
5
6
7
|
# File 'lib/groem/app.rb', line 5
def environment
@environment
end
|
Returns the value of attribute headers
5
6
7
|
# File 'lib/groem/app.rb', line 5
def
@headers
end
|
#host ⇒ Object
Returns the value of attribute host
5
6
7
|
# File 'lib/groem/app.rb', line 5
def host
@host
end
|
#notifications ⇒ Object
Returns the value of attribute notifications
5
6
7
|
# File 'lib/groem/app.rb', line 5
def notifications
@notifications
end
|
#port ⇒ Object
Returns the value of attribute port
5
6
7
|
# File 'lib/groem/app.rb', line 5
def port
@port
end
|
Instance Method Details
#[](key) ⇒ Object
used by Marshal::Request#dump
25
26
27
|
# File 'lib/groem/app.rb', line 25
def [](key)
to_request[key]
end
|
#binary(key, value_or_io) ⇒ Object
77
78
79
|
# File 'lib/groem/app.rb', line 77
def binary(key, value_or_io)
end
|
#callbacks(&blk) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/groem/app.rb', line 60
def callbacks &blk
if blk.arity == 1
blk.call(self)
else
instance_eval(&blk)
end
end
|
68
69
70
|
# File 'lib/groem/app.rb', line 68
def (key, value)
self.[growlify_key(key)] = value
end
|
#icon(uri_or_file) ⇒ Object
#notification(name, *args) {|n| ... } ⇒ Object
53
54
55
56
57
58
|
# File 'lib/groem/app.rb', line 53
def notification(name, *args)
n = Groem::Notification.new(name, *args)
yield(n) if block_given?
n.application_name = self.name
self.notifications[name] = n
end
|
#notify(name, *args, &blk) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/groem/app.rb', line 40
def notify(name, *args, &blk)
return unless n = self.notifications[name]
opts = ((Hash === args.last) ? args.pop : {})
title = args.shift
n = n.dup n.title = title ? title : self.name
if cb = opts.delete(:callback)
n.callback(cb)
end
opts.each_pair {|k, v| n.__send__ :"#{k}=", v}
send_notify(n, &blk)
end
|
#register(&blk) ⇒ Object
31
32
33
34
35
36
37
38
|
# File 'lib/groem/app.rb', line 31
def register(&blk)
if blk.arity == 1
blk.call(self)
else
instance_eval(&blk)
end
send_register
end
|
#to_request ⇒ Object
117
118
119
120
121
122
|
# File 'lib/groem/app.rb', line 117
def to_request
{'environment' => self.environment,
'headers' => self.,
'notifications' => notifications_to_register
}
end
|
#when_callback(action, path = nil, &blk) ⇒ Object
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/groem/app.rb', line 103
def when_callback action, path=nil, &blk
action = growlify_action(action)
path = \
case path
when String
[path, nil]
when Hash
[path[:context], path[:type]]
end
notify_callbacks[Groem::Route.new(action, path)] = blk
end
|
#when_click(path = nil, &blk) ⇒ Object
91
92
93
|
# File 'lib/groem/app.rb', line 91
def when_click path=nil, &blk
when_callback GNTP_CLICK_CALLBACK_RESULT, path, &blk
end
|
#when_close(path = nil, &blk) ⇒ Object
95
96
97
|
# File 'lib/groem/app.rb', line 95
def when_close path=nil, &blk
when_callback GNTP_CLOSE_CALLBACK_RESULT, path, &blk
end
|
#when_register(&blk) ⇒ Object
—- callback definition methods
83
84
85
|
# File 'lib/groem/app.rb', line 83
def when_register &blk
@register_callback = blk
end
|
#when_register_failed(&blk) ⇒ Object
87
88
89
|
# File 'lib/groem/app.rb', line 87
def when_register_failed &blk
@register_errback = blk
end
|
#when_timedout(path = nil, &blk) ⇒ Object