gnome-campfire-notifications 0.1.0
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/lib/gnome-campfire-notifications.rb +82 -0
- metadata +62 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
require "twitter/json_stream"
|
|
2
|
+
require "json"
|
|
3
|
+
require "yaml"
|
|
4
|
+
require "net/http"
|
|
5
|
+
|
|
6
|
+
class GnomeCampfireNotifications
|
|
7
|
+
HOST = 'streaming.campfirenow.com'
|
|
8
|
+
|
|
9
|
+
def self.start
|
|
10
|
+
room_name = ENV['GNOME_CAMPFIRE_NOTIFICATIONS_ROOM_NAME']
|
|
11
|
+
room_id = ENV['GNOME_CAMPFIRE_NOTIFICATIONS_ROOM_ID']
|
|
12
|
+
token = ENV['GNOME_CAMPFIRE_NOTIFICATIONS_TOKEN']
|
|
13
|
+
|
|
14
|
+
unless room_name && room_id && token
|
|
15
|
+
raise "please set GNOME_CAMPFIRE_NOTIFICATIONS_ROOM_ID and GNOME_CAMPFIRE_NOTIFICATIONS_TOKEN"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
new(
|
|
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
|
|
29
|
+
@username_cache = []
|
|
30
|
+
listen
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def listen
|
|
36
|
+
on_message do |item|
|
|
37
|
+
username = get_username(item["user_id"].to_i)
|
|
38
|
+
message = "#{item["body"].to_s.gsub(/'/, "\'")}"
|
|
39
|
+
|
|
40
|
+
system("notify-send --hint=int:transient:1 -u low '#{username}' '#{message}'")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def on_message
|
|
45
|
+
EventMachine::run do
|
|
46
|
+
stream = Twitter::JSONStream.connect(@options)
|
|
47
|
+
|
|
48
|
+
stream.each_item do |item|
|
|
49
|
+
json = JSON::parse(item)
|
|
50
|
+
if json["type"] == "TextMessage"
|
|
51
|
+
yield(json)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
stream.on_error { |m| puts "ERROR: #{m.inspect}" }
|
|
56
|
+
stream.on_max_reconnects { |timeout, retries| puts "Tried #{retries} times to connect." }
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def get_username(id)
|
|
61
|
+
return "Unknown" if id.nil?
|
|
62
|
+
|
|
63
|
+
unless @username_cache[id]
|
|
64
|
+
req = Net::HTTP::Get.new("https://#{room_url}/users/#{id}.json")
|
|
65
|
+
req.basic_auth(@options[:token], "x")
|
|
66
|
+
http = Net::HTTP.new(room_url, 443)
|
|
67
|
+
http.use_ssl = true
|
|
68
|
+
resp = http.start { |h| h.request(req) }
|
|
69
|
+
|
|
70
|
+
json = JSON.parse(resp.body)
|
|
71
|
+
|
|
72
|
+
# Get username
|
|
73
|
+
@username_cache[id] = json["user"]["name"]
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
@username_cache[id]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def room_url
|
|
80
|
+
"#{@options[:room_name]}.campfirenow.com"
|
|
81
|
+
end
|
|
82
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: gnome-campfire-notifications
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- mcnelson
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-11-07 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: twitter-stream
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
description: A Ruby script that spawns GNOME desktop notifications when something
|
|
31
|
+
is said in your Campfire chatroom.
|
|
32
|
+
email: michael@nelsonware.com
|
|
33
|
+
executables: []
|
|
34
|
+
extensions: []
|
|
35
|
+
extra_rdoc_files: []
|
|
36
|
+
files:
|
|
37
|
+
- lib/gnome-campfire-notifications.rb
|
|
38
|
+
homepage: https://rubygems.org/gems/example
|
|
39
|
+
licenses: []
|
|
40
|
+
post_install_message:
|
|
41
|
+
rdoc_options: []
|
|
42
|
+
require_paths:
|
|
43
|
+
- lib
|
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
45
|
+
none: false
|
|
46
|
+
requirements:
|
|
47
|
+
- - ! '>='
|
|
48
|
+
- !ruby/object:Gem::Version
|
|
49
|
+
version: '0'
|
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
|
+
none: false
|
|
52
|
+
requirements:
|
|
53
|
+
- - ! '>='
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: '0'
|
|
56
|
+
requirements: []
|
|
57
|
+
rubyforge_project:
|
|
58
|
+
rubygems_version: 1.8.25
|
|
59
|
+
signing_key:
|
|
60
|
+
specification_version: 3
|
|
61
|
+
summary: GNOME desktop notifications for Campfire.
|
|
62
|
+
test_files: []
|