lib/flapjack/gateways/sms_messagenet.rb in flapjack-0.6.53 vs lib/flapjack/gateways/sms_messagenet.rb in flapjack-0.6.54
- old
+ new
@@ -1,31 +1,24 @@
#!/usr/bin/env ruby
require 'em-synchrony'
require 'em-synchrony/em-http'
-require 'flapjack/gateways/base'
-
module Flapjack
module Gateways
class SmsMessagenet
- extend Flapjack::Gateways::Resque
MESSAGENET_URL = 'https://www.messagenet.com.au/dotnet/Lodge.asmx/LodgeSMSMessage'
class << self
- alias_method :orig_bootstrap, :bootstrap
-
- def bootstrap(opts = {})
- return if @bootstrapped
+ def start
@sent = 0
- orig_bootstrap(opts)
end
def perform(notification)
- logger.debug "Woo, got a notification to send out: #{notification.inspect}"
+ @logger.debug "Woo, got a notification to send out: #{notification.inspect}"
notification_type = notification['notification_type']
contact_first_name = notification['contact_first_name']
contact_last_name = notification['contact_last_name']
state = notification['state']
@@ -48,19 +41,19 @@
message += " at #{Time.at(time).strftime('%-d %b %H:%M')}, #{summary}"
notification['message'] = message
# TODO log error and skip instead of raising errors
- if config.nil? || (config.respond_to?(:empty?) && config.empty?)
- logger.error "Messagenet config is missing"
+ if @config.nil? || (@config.respond_to?(:empty?) && @config.empty?)
+ @logger.error "Messagenet config is missing"
return
end
errors = []
- username = config["username"]
- password = config["password"]
+ username = @config["username"]
+ password = @config["password"]
address = notification['address']
message = notification['message']
notification_id = notification['id']
[[username, "Messagenet username is missing"],
@@ -72,29 +65,29 @@
next unless val_err.first.nil? || (val_err.first.respond_to?(:empty?) && val_err.first.empty?)
errors << val_err.last
end
unless errors.empty?
- errors.each {|err| logger.error err }
+ errors.each {|err| @logger.error err }
return
end
query = {'Username' => username,
'Pwd' => password,
'PhoneNumber' => address,
'PhoneMessage' => message}
http = EM::HttpRequest.new(MESSAGENET_URL).get(:query => query)
- logger.debug "server response: #{http.response}"
+ @logger.debug "server response: #{http.response}"
status = (http.nil? || http.response_header.nil?) ? nil : http.response_header.status
if (status >= 200) && (status <= 206)
@sent += 1
- logger.info "Sent SMS via Messagenet, response status is #{status}, " +
+ @logger.info "Sent SMS via Messagenet, response status is #{status}, " +
"notification_id: #{notification_id}"
else
- logger.error "Failed to send SMS via Messagenet, response status is #{status}, " +
+ @logger.error "Failed to send SMS via Messagenet, response status is #{status}, " +
"notification_id: #{notification_id}"
end
end
end