Skip to content
Browse files

Put shared logic into Pushr::Notifier::Base

  • Loading branch information...
1 parent 251606d commit f7688c6c8e9aa235f90fadb5bfbeeecd6e3a70d8 @karmi committed
Showing with 28 additions and 16 deletions.
  1. +1 −1 config.example.yml
  2. +27 −15 pushr.rb
View
2 config.example.yml
@@ -20,4 +20,4 @@ notifiers:
password: ~
# IRC is also possible, see http://github.com/karmi/pushr_notifiers/blob/master/irc.rb
# - irc:
- # uri: 'irc://irc.freenode.cz:6667/test'
+ # uri: 'irc://irc.freenode.net:6667/test'
View
42 pushr.rb
@@ -33,33 +33,45 @@ class Notifier
# Inherit from this class in your notifiers
# See eg. http://github.com/karmi/pushr_notifiers/blob/master/irc.rb
class Base
- def deliver!
- raise NoMethodError, "you need to implement this method in your notifier"
- end
- def configured?
- false
- end
- end
- # Twitter notifications (default)
- class Twitter < Base
+ include Pushr::Logger
attr_reader :config
def initialize(config={})
@config = config
- Pushr::Logger::LOGGER.fatal('Twitter notifier') { "Twitter not configured" } unless configured?
+ log.fatal("#{self.class.name}") { "Notifier not configured!" } unless configured?
end
- def deliver!(notification)
- return unless configured?
- message = if notification.success
+ # Implement this method for your particular notification method
+ def deliver!
+ raise NoMethodError, "You need to implement 'deliver!' method in your notifier"
+ end
+
+ private
+
+ # Over-ride this method to send diferent message
+ def message(notification)
+ if notification.success
"Deployed #{notification.application} with revision #{notification.repository.info.revision}#{notification.repository.info.message.slice(0, 100)}"
else
- "FAIL! Deploying #{notification.application} failed. Check log for details."
+ "FAIL! Deploying #{notification.application} failed. Check deploy.log for details."
end
- %x[curl --silent --data status='#{message}' http://#{config['username']}:#{config['password']}@twitter.com/statuses/update.json]
+ end
+
+ # Implement this method to check for notifier configuration
+ def configured?
+ raise NoMethodError, "You need to implement 'configured?' method in your notifier"
+ end
+
+ end
+
+ # Twitter notifications (default)
+ class Twitter < Base
+ def deliver!(notification)
+ return unless configured?
+ %x[curl --silent --data status='#{message(notification)}' http://#{config['username']}:#{config['password']}@twitter.com/statuses/update.json]
end
private

0 comments on commit f7688c6

Please sign in to comment.
Something went wrong with that request. Please try again.