gnome-campfire-notifications 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/assets/campfire.png +0 -0
- data/bin/gnome-campfire-notifications +1 -1
- data/lib/gnome-campfire-notifications.rb +51 -27
- metadata +6 -6
data/assets/campfire.png
ADDED
|
Binary file
|
|
@@ -1,49 +1,46 @@
|
|
|
1
1
|
require "twitter/json_stream"
|
|
2
|
-
require "json"
|
|
3
|
-
require "yaml"
|
|
4
2
|
require "net/http"
|
|
3
|
+
require "json"
|
|
5
4
|
|
|
6
5
|
class GnomeCampfireNotifications
|
|
7
6
|
HOST = 'streaming.campfirenow.com'
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
7
|
+
NOTIFICATION_GFX_FILENAME = 'campfire.png'
|
|
8
|
+
NOTIFICATION_GFX_SYSPATH = "/usr/share/icons/gnome/32x32/apps"
|
|
9
|
+
|
|
10
|
+
ATTR_MAP = {
|
|
11
|
+
room_name: 'GNOME_CAMPFIRE_NOTIFICATIONS_ROOM_NAME',
|
|
12
|
+
room_id: 'GNOME_CAMPFIRE_NOTIFICATIONS_ROOM_ID',
|
|
13
|
+
token: 'GNOME_CAMPFIRE_NOTIFICATIONS_TOKEN'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
def initialize
|
|
17
|
+
if (missing = ATTR_MAP.values.select { |env| ENV[env].empty? }).any?
|
|
18
|
+
raise "please set environment variable(s) #{missing.join(', ')}"
|
|
16
19
|
end
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
path: "/room/#{room_id}/live.json",
|
|
20
|
-
host: HOST,
|
|
21
|
-
auth: "#{token}:x",
|
|
22
|
-
token: token,
|
|
23
|
-
room_name: room_name
|
|
24
|
-
)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
def initialize(options)
|
|
28
|
-
@options = options
|
|
21
|
+
@options = ATTR_MAP.map.with_object({}) { |(key, env), opts| opts[key] = ENV[env] }
|
|
29
22
|
@username_cache = []
|
|
30
|
-
|
|
23
|
+
try_icon
|
|
31
24
|
end
|
|
32
25
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def listen
|
|
26
|
+
def start
|
|
36
27
|
on_message do |item|
|
|
37
28
|
username = get_username(item["user_id"].to_i)
|
|
38
29
|
message = "#{item["body"].to_s.gsub(/'/, "\'")}"
|
|
39
30
|
|
|
40
|
-
system("notify-send --hint=int:transient:1 -u low '#{username}' '#{message}'")
|
|
31
|
+
system("notify-send --hint=int:transient:1 -u low#{icon} '#{username}' '#{message}'")
|
|
41
32
|
end
|
|
42
33
|
end
|
|
43
34
|
|
|
35
|
+
private
|
|
36
|
+
|
|
44
37
|
def on_message
|
|
45
38
|
EventMachine::run do
|
|
46
|
-
stream = Twitter::JSONStream.connect(
|
|
39
|
+
stream = Twitter::JSONStream.connect(
|
|
40
|
+
host: HOST,
|
|
41
|
+
path: "/room/#{room_id}/live.json",
|
|
42
|
+
auth: "#{token}:x",
|
|
43
|
+
)
|
|
47
44
|
|
|
48
45
|
stream.each_item do |item|
|
|
49
46
|
json = JSON::parse(item)
|
|
@@ -76,7 +73,34 @@ class GnomeCampfireNotifications
|
|
|
76
73
|
@username_cache[id]
|
|
77
74
|
end
|
|
78
75
|
|
|
76
|
+
def icon
|
|
77
|
+
" -i #{@options[:icon_path]}"
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def try_icon
|
|
81
|
+
if path = notification_gfx_paths.detect { |p| File.exists?(p) }
|
|
82
|
+
@options[:icon_path] = path
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def notification_gfx_paths
|
|
87
|
+
[[NOTIFICATION_GFX_SYSPATH, NOTIFICATION_GFX_FILENAME],
|
|
88
|
+
[gem_dir, "assets", NOTIFICATION_GFX_FILENAME]].join('/')
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def gem_dir
|
|
92
|
+
Gem::Specification.find_by_name("gnome-campfire-notifications").gem_dir
|
|
93
|
+
end
|
|
94
|
+
|
|
79
95
|
def room_url
|
|
80
96
|
"#{@options[:room_name]}.campfirenow.com"
|
|
81
97
|
end
|
|
98
|
+
|
|
99
|
+
def room_id
|
|
100
|
+
@options[:room_id]
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def token
|
|
104
|
+
@options[:token]
|
|
105
|
+
end
|
|
82
106
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: gnome-campfire-notifications
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2013-11-
|
|
12
|
+
date: 2013-11-10 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: twitter-stream
|
|
@@ -36,9 +36,9 @@ extensions: []
|
|
|
36
36
|
extra_rdoc_files: []
|
|
37
37
|
files:
|
|
38
38
|
- lib/gnome-campfire-notifications.rb
|
|
39
|
-
-
|
|
40
|
-
|
|
41
|
-
homepage: https://
|
|
39
|
+
- assets/campfire.png
|
|
40
|
+
- bin/gnome-campfire-notifications
|
|
41
|
+
homepage: https://github.com/mcnelson/gnome-campfire-notifications
|
|
42
42
|
licenses: []
|
|
43
43
|
post_install_message:
|
|
44
44
|
rdoc_options: []
|
|
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
58
58
|
version: '0'
|
|
59
59
|
requirements: []
|
|
60
60
|
rubyforge_project:
|
|
61
|
-
rubygems_version: 1.8.
|
|
61
|
+
rubygems_version: 1.8.24
|
|
62
62
|
signing_key:
|
|
63
63
|
specification_version: 3
|
|
64
64
|
summary: GNOME desktop notifications for Campfire.
|