From 2a2d7f24ba78bba32451305c59fe808f89170930 Mon Sep 17 00:00:00 2001 From: Alex Young Date: Fri, 10 Apr 2015 16:15:22 +0100 Subject: Split AQL into two to enable easier console testing --- lib/mauve/notifiers/sms_aql.rb | 41 +++++++++++++++++++++++++++++++---------- 1 file 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={}) -- cgit v1.2.1