Sha256: bc7ebefb0c7109867ffa3786b67535ab19410c4881d0695455ec2985a87a842a

Contents?: true

Size: 1.81 KB

Versions: 21

Compression:

Stored size: 1.81 KB

Contents

#!/usr/bin/env ruby

require 'net/http'
require 'uri'

module Flapjack
  module Notification
    class Sms
      class Messagenet

        def self.sender(notification, options = {})
          logger = options[:logger]
          config = options[:config]

          unless config && (username = config["username"])
            raise RuntimeError.new('sms_messagenet: username is missing')
          end
          unless config && (password = config["password"])
            raise RuntimeError.new('sms_messagenet: password is missing')
          end

          raise RuntimeError.new('address is missing') unless address         = notification['address']
          raise RuntimeError.new('message is missing') unless message         = notification['message']
          raise RuntimeError.new('id is missing')      unless notification_id = notification['id']

          params = { 'Username'     => username,
                     'Pwd'          => password,
                     'PhoneNumber'  => address,
                     'PhoneMessage' => message }

          uri       = URI('https://www.messagenet.com.au/dotnet/Lodge.asmx/LodgeSMSMessage')
          uri.query = URI.encode_www_form(params)
          logger.debug("request_uri: #{uri.request_uri.inspect}")

          Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
            request = Net::HTTP::Get.new uri.request_uri
            response = http.request request
            http_success = ( response.is_a?(Net::HTTPSuccess) == true )
            logger.debug("Flapjack::Notification::SMSMessagenet: response from server: #{response.body}")
            raise RuntimeError.new "Failed to send SMS via messagenet, http response is a #{response.class}, notification_id: #{notification_id}" unless http_success
          end

        end
      end
    end
  end
end


Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
flapjack-0.6.43 lib/flapjack/notification/sms/messagenet.rb
flapjack-0.6.42 lib/flapjack/notification/sms/messagenet.rb
flapjack-0.6.41 lib/flapjack/notification/sms/messagenet.rb
flapjack-0.6.40 lib/flapjack/notification/sms/messagenet.rb
flapjack-0.6.39 lib/flapjack/notification/sms/messagenet.rb
flapjack-0.6.38 lib/flapjack/notification/sms/messagenet.rb
flapjack-0.6.37 lib/flapjack/notification/sms/messagenet.rb
flapjack-0.6.36 lib/flapjack/notification/sms/messagenet.rb
flapjack-0.6.35 lib/flapjack/notification/sms/messagenet.rb
flapjack-0.6.34 lib/flapjack/notification/sms/messagenet.rb
flapjack-0.6.33 lib/flapjack/notification/sms/messagenet.rb
flapjack-0.6.32 lib/flapjack/notification/sms/messagenet.rb
flapjack-0.6.31 lib/flapjack/notification/sms/messagenet.rb
flapjack-0.6.30 lib/flapjack/notification/sms/messagenet.rb
flapjack-0.6.29 lib/flapjack/notification/sms/messagenet.rb
flapjack-0.6.28 lib/flapjack/notification/sms/messagenet.rb
flapjack-0.6.27 lib/flapjack/notification/sms/messagenet.rb
flapjack-0.6.26 lib/flapjack/notification/sms/messagenet.rb
flapjack-0.6.25 lib/flapjack/notification/sms/messagenet.rb
flapjack-0.6.24 lib/flapjack/notification/sms/messagenet.rb