aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Young <alex@bytemark.co.uk>2015-04-10 16:15:22 +0100
committerAlex Young <alex@bytemark.co.uk>2015-04-10 16:15:22 +0100
commit2a2d7f24ba78bba32451305c59fe808f89170930 (patch)
tree082668b7f750a153937a34e8030e6d3c819f97f9 /lib
parent515f84ded70a67170df664b2222501e28d58b9f5 (diff)
Split AQL into two to enable easier console testing
Diffstat (limited to 'lib')
-rw-r--r--lib/mauve/notifiers/sms_aql.rb41
1 files changed, 31 insertions, 10 deletions
diff --git a/lib/mauve/notifiers/sms_aql.rb b/lib/mauve/notifiers/sms_aql.rb
index 82b83bc..77cd012 100644
--- a/lib/mauve/notifiers/sms_aql.rb
+++ b/lib/mauve/notifiers/sms_aql.rb
@@ -7,26 +7,30 @@ module Mauve
require 'net/https'
- class AQL
+ # Simple SMS-sending wrapper. Use like so:
+ #
+ # aql = Mauve::Notifiers::Sms::AQLGateway.new(username, password)
+ # aql.send_sms(to_number="077711234567",
+ # from_number="0190412345678",
+ # message="This is my message!")
+ class AQLGateway
GATEWAY = "https://gw1.aql.com/sms/sms_gw.php"
- attr_writer :username, :password, :from
- attr_reader :name
-
- def initialize(name)
- @name = name
+ def initialize(username, password)
+ @username = username
+ @password = password
end
- def send_alert(destination, alert, all_alerts, conditions = {})
+ def send_sms(destination, from, message, flash=0)
uri = URI.parse(GATEWAY)
opts_string = {
:username => @username,
:password => @password,
- :destination => normalize_number(destination),
- :message => prepare_message(destination, alert, all_alerts, conditions),
+ :destination => destination,
+ :message => message,
:originator => @from,
- :flash => @flash ? 1 : 0
+ :flash => flash
}.map { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join("&")
http = Net::HTTP.new(uri.host, uri.port)
@@ -48,6 +52,23 @@ module Mauve
false
end
end
+ end # class AQLGateway
+
+
+ class AQL
+
+ attr_writer :username, :password, :from
+ attr_reader :name
+
+ def initialize(name)
+ @name = name
+ end
+
+ def send_alert(destination, alert, all_alerts, conditions = {})
+ to = normalize_number(destination)
+ msg = prepare_message(destination, alert, all_alerts, conditions)
+ AQLGateway.new(@username, @password).send_sms(to, @from, msg)
+ end
protected
def prepare_message(destination, alert, all_alerts, conditions={})