absentee_camper 0.0.6 → 0.0.7
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/absentee_camper.gemspec +1 -0
- data/lib/absentee_camper.rb +4 -0
- data/lib/absentee_camper/campfire/room.rb +8 -20
- data/lib/absentee_camper/email_notifier.rb +38 -0
- data/lib/absentee_camper/logger.rb +8 -0
- data/lib/absentee_camper/monitor.rb +12 -34
- data/lib/absentee_camper/notification_manager.rb +25 -0
- data/lib/absentee_camper/prowl_notifier.rb +20 -0
- data/lib/absentee_camper/version.rb +1 -1
- metadata +27 -12
data/absentee_camper.gemspec
CHANGED
data/lib/absentee_camper.rb
CHANGED
|
@@ -9,6 +9,10 @@ require 'settingslogic'
|
|
|
9
9
|
module AbsenteeCamper
|
|
10
10
|
autoload :Config, 'absentee_camper/config'
|
|
11
11
|
autoload :Monitor, 'absentee_camper/monitor'
|
|
12
|
+
autoload :NotificationManager, 'absentee_camper/notification_manager'
|
|
13
|
+
autoload :EmailNotifier, 'absentee_camper/email_notifier'
|
|
14
|
+
autoload :ProwlNotifier, 'absentee_camper/prowl_notifier'
|
|
15
|
+
autoload :Logger, 'absentee_camper/logger'
|
|
12
16
|
autoload :API, 'absentee_camper/campfire/api'
|
|
13
17
|
autoload :Room, 'absentee_camper/campfire/room'
|
|
14
18
|
|
|
@@ -7,20 +7,10 @@ module AbsenteeCamper
|
|
|
7
7
|
@room_id = room_id
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def leave
|
|
15
|
-
post 'leave'
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def lock
|
|
19
|
-
post 'lock'
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def unlock
|
|
23
|
-
post 'unlock'
|
|
10
|
+
%w[join leave lock unlock].each do |name|
|
|
11
|
+
define_method name do
|
|
12
|
+
post name
|
|
13
|
+
end
|
|
24
14
|
end
|
|
25
15
|
|
|
26
16
|
def message(message)
|
|
@@ -49,12 +39,10 @@ module AbsenteeCamper
|
|
|
49
39
|
post 'speak', :body => {:message => {:body => message, :type => type}}.to_json
|
|
50
40
|
end
|
|
51
41
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
def post(action, options = {})
|
|
57
|
-
API.post room_url_for(action), options
|
|
42
|
+
%w[get post].each do |method|
|
|
43
|
+
define_method method do |action, options = {}|
|
|
44
|
+
API.send method, room_url_for(action), options
|
|
45
|
+
end
|
|
58
46
|
end
|
|
59
47
|
|
|
60
48
|
def room_url_for(action)
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
module AbsenteeCamper
|
|
2
|
+
class EmailNotifier
|
|
3
|
+
include Logger
|
|
4
|
+
|
|
5
|
+
def initialize(user_id)
|
|
6
|
+
@email_address = user_info(user_id)['email_address']
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def notify(message)
|
|
10
|
+
log "sending email to #{@email_address}"
|
|
11
|
+
Pony.mail :to => @email_address, :body => email_body(message)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
private
|
|
15
|
+
|
|
16
|
+
def user_info(user_id)
|
|
17
|
+
response = Campfire::API.get("/users/#{user_id}.json")
|
|
18
|
+
|
|
19
|
+
if response.code != 200
|
|
20
|
+
user_name = Config.users.detect { |kv| kv[1] == user_id }[0]
|
|
21
|
+
raise "Error while retrieving user info for #{user_name}: #{response.message}"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
user = JSON.parse(response.body)
|
|
25
|
+
user['user']
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def email_body(message)
|
|
29
|
+
body = <<-BODY
|
|
30
|
+
Come back to the campfire! We're having a good time telling ghost stories! Here's one you missed:
|
|
31
|
+
|
|
32
|
+
#{message}
|
|
33
|
+
|
|
34
|
+
#{Config.room_uri}
|
|
35
|
+
BODY
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module AbsenteeCamper
|
|
2
2
|
class Monitor
|
|
3
3
|
include Campfire
|
|
4
|
+
include Logger
|
|
4
5
|
|
|
5
6
|
def initialize
|
|
6
7
|
@room = Room.new(Config.room_id)
|
|
@@ -17,32 +18,6 @@ module AbsenteeCamper
|
|
|
17
18
|
room['room']['users']
|
|
18
19
|
end
|
|
19
20
|
|
|
20
|
-
def user_info(user_id)
|
|
21
|
-
response = API.get("/users/#{user_id}.json")
|
|
22
|
-
|
|
23
|
-
if response.code != 200
|
|
24
|
-
user_name = Config.users.detect { |kv| kv[1] == user_id }[0]
|
|
25
|
-
raise "Error while retrieving user info for #{user_name}: #{response.message}"
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
user = JSON.parse(response.body)
|
|
29
|
-
user['user']
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def email_body(message)
|
|
33
|
-
body = <<-BODY
|
|
34
|
-
Come back to the campfire! We're having a good time telling ghost stories! Here's one you missed:
|
|
35
|
-
|
|
36
|
-
#{message}
|
|
37
|
-
|
|
38
|
-
#{Config.room_uri}
|
|
39
|
-
BODY
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def log(message)
|
|
43
|
-
puts message
|
|
44
|
-
end
|
|
45
|
-
|
|
46
21
|
def start
|
|
47
22
|
log "monitoring room #{Config.room_id} at #{API.base_uri} ..."
|
|
48
23
|
|
|
@@ -57,16 +32,11 @@ module AbsenteeCamper
|
|
|
57
32
|
body.scan(/@\w+/).each do |mention|
|
|
58
33
|
mentioned = mention[1..-1]
|
|
59
34
|
if Config.users.keys.include? mentioned
|
|
60
|
-
user_id = Config.users[mentioned]
|
|
61
|
-
|
|
62
35
|
begin
|
|
63
36
|
# If the user isn't in the room, fire off an email to them
|
|
64
|
-
unless users_in_room(@room).map { |u| u['id'] }.include?
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
log "sending email to #{mentioned} at #{email_address}"
|
|
68
|
-
|
|
69
|
-
Pony.mail :to => email_address, :body => email_body(body)
|
|
37
|
+
unless users_in_room(@room).map { |u| u['id'] }.include? user_id_from_config(mentioned)
|
|
38
|
+
@room.message("[Notified #{mentioned}.]")
|
|
39
|
+
NotificationManager.new(Config.users[mentioned]).send_notifications body
|
|
70
40
|
end
|
|
71
41
|
rescue
|
|
72
42
|
log $!
|
|
@@ -85,6 +55,14 @@ module AbsenteeCamper
|
|
|
85
55
|
|
|
86
56
|
private
|
|
87
57
|
|
|
58
|
+
def user_id_from_config(mentioned)
|
|
59
|
+
if Config.users[mentioned].is_a? Hash
|
|
60
|
+
user_id = Config.users[mentioned]['id']
|
|
61
|
+
else
|
|
62
|
+
user_id = Config.users[mentioned]
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
88
66
|
def retry_connection
|
|
89
67
|
times = 3
|
|
90
68
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module AbsenteeCamper
|
|
2
|
+
class NotificationManager
|
|
3
|
+
include Logger
|
|
4
|
+
|
|
5
|
+
def initialize(user_info)
|
|
6
|
+
if user_info.is_a?(Hash) and user_info['notification_methods']
|
|
7
|
+
user_info['notification_methods'].each do |notifier, initialization_info|
|
|
8
|
+
@notifiers = [].tap do |ary|
|
|
9
|
+
ary << AbsenteeCamper.const_get("#{notifier}Notifier".to_sym).new(initialization_info)
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
else
|
|
13
|
+
# Everyone gets Email notifications if no other notifier is defined.
|
|
14
|
+
# In this case, user_info is the user_id.
|
|
15
|
+
|
|
16
|
+
log "No notification methods defined. Falling back to email notifications."
|
|
17
|
+
@notifiers = [EmailNotifier.new(user_info)]
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def send_notifications(message)
|
|
22
|
+
@notifiers.each { |notifier| notifier.notify message }
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require 'prowl'
|
|
2
|
+
|
|
3
|
+
module AbsenteeCamper
|
|
4
|
+
class ProwlNotifier
|
|
5
|
+
include Logger
|
|
6
|
+
|
|
7
|
+
def initialize(api_key)
|
|
8
|
+
@api_key = api_key
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def notify(message)
|
|
12
|
+
log "sending prowl notification"
|
|
13
|
+
Prowl.add(:apikey => @api_key,
|
|
14
|
+
:application => 'Absentee Camper',
|
|
15
|
+
:event => 'Message',
|
|
16
|
+
:description => message,
|
|
17
|
+
:url => Config.room_uri)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: absentee_camper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.7
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -10,11 +10,11 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2011-09-
|
|
13
|
+
date: 2011-09-21 00:00:00.000000000Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: settingslogic
|
|
17
|
-
requirement: &
|
|
17
|
+
requirement: &70337147411500 !ruby/object:Gem::Requirement
|
|
18
18
|
none: false
|
|
19
19
|
requirements:
|
|
20
20
|
- - ~>
|
|
@@ -22,10 +22,10 @@ dependencies:
|
|
|
22
22
|
version: '2.0'
|
|
23
23
|
type: :runtime
|
|
24
24
|
prerelease: false
|
|
25
|
-
version_requirements: *
|
|
25
|
+
version_requirements: *70337147411500
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: yajl-ruby
|
|
28
|
-
requirement: &
|
|
28
|
+
requirement: &70337147411000 !ruby/object:Gem::Requirement
|
|
29
29
|
none: false
|
|
30
30
|
requirements:
|
|
31
31
|
- - ~>
|
|
@@ -33,10 +33,10 @@ dependencies:
|
|
|
33
33
|
version: '0.8'
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
|
-
version_requirements: *
|
|
36
|
+
version_requirements: *70337147411000
|
|
37
37
|
- !ruby/object:Gem::Dependency
|
|
38
38
|
name: httparty
|
|
39
|
-
requirement: &
|
|
39
|
+
requirement: &70337147410500 !ruby/object:Gem::Requirement
|
|
40
40
|
none: false
|
|
41
41
|
requirements:
|
|
42
42
|
- - ~>
|
|
@@ -44,10 +44,10 @@ dependencies:
|
|
|
44
44
|
version: '0.7'
|
|
45
45
|
type: :runtime
|
|
46
46
|
prerelease: false
|
|
47
|
-
version_requirements: *
|
|
47
|
+
version_requirements: *70337147410500
|
|
48
48
|
- !ruby/object:Gem::Dependency
|
|
49
49
|
name: pony
|
|
50
|
-
requirement: &
|
|
50
|
+
requirement: &70337147410020 !ruby/object:Gem::Requirement
|
|
51
51
|
none: false
|
|
52
52
|
requirements:
|
|
53
53
|
- - ~>
|
|
@@ -55,10 +55,21 @@ dependencies:
|
|
|
55
55
|
version: '1.3'
|
|
56
56
|
type: :runtime
|
|
57
57
|
prerelease: false
|
|
58
|
-
version_requirements: *
|
|
58
|
+
version_requirements: *70337147410020
|
|
59
|
+
- !ruby/object:Gem::Dependency
|
|
60
|
+
name: prowl
|
|
61
|
+
requirement: &70337147409560 !ruby/object:Gem::Requirement
|
|
62
|
+
none: false
|
|
63
|
+
requirements:
|
|
64
|
+
- - ! '>='
|
|
65
|
+
- !ruby/object:Gem::Version
|
|
66
|
+
version: 0.1.3
|
|
67
|
+
type: :runtime
|
|
68
|
+
prerelease: false
|
|
69
|
+
version_requirements: *70337147409560
|
|
59
70
|
- !ruby/object:Gem::Dependency
|
|
60
71
|
name: rspec
|
|
61
|
-
requirement: &
|
|
72
|
+
requirement: &70337147409100 !ruby/object:Gem::Requirement
|
|
62
73
|
none: false
|
|
63
74
|
requirements:
|
|
64
75
|
- - ~>
|
|
@@ -66,7 +77,7 @@ dependencies:
|
|
|
66
77
|
version: 2.6.0
|
|
67
78
|
type: :development
|
|
68
79
|
prerelease: false
|
|
69
|
-
version_requirements: *
|
|
80
|
+
version_requirements: *70337147409100
|
|
70
81
|
description: Monitors a Campfire room for @mentions, and emails the @mentioned user
|
|
71
82
|
with the message if they aren't in the room.
|
|
72
83
|
email:
|
|
@@ -85,7 +96,11 @@ files:
|
|
|
85
96
|
- lib/absentee_camper/campfire/api.rb
|
|
86
97
|
- lib/absentee_camper/campfire/room.rb
|
|
87
98
|
- lib/absentee_camper/config.rb
|
|
99
|
+
- lib/absentee_camper/email_notifier.rb
|
|
100
|
+
- lib/absentee_camper/logger.rb
|
|
88
101
|
- lib/absentee_camper/monitor.rb
|
|
102
|
+
- lib/absentee_camper/notification_manager.rb
|
|
103
|
+
- lib/absentee_camper/prowl_notifier.rb
|
|
89
104
|
- lib/absentee_camper/version.rb
|
|
90
105
|
homepage: ''
|
|
91
106
|
licenses: []
|