Skip to content

Instantly share code, notes, and snippets.

@sergeych
Created December 8, 2015 19:43
Show Gist options
  • Save sergeych/b32e1c9fe282589a79ce to your computer and use it in GitHub Desktop.
Save sergeych/b32e1c9fe282589a79ce to your computer and use it in GitHub Desktop.
Send SMS using qtelecom.ru service
require 'net/smtp'
# Интерфейс отправки SMS при помощи службы qtelecom.ru.
# Требует установки переменных QTELECOM_LOGIN, QTELECOM_PASSWORD. Работает через единственный на
# данный момент рабочий из их протоколов (может у меня логин был неполноценный?) - SMTP.
#
# Thread safe.
#
# Enjoy ;) [email protected]
#
class QtelecomSms
if defined?(Rails) && Rails.env.test?
@@deliveries = []
# in test more use TwilioSms.deliveries array which holds { to:, text:} objects
def self.deliveries
@@deliveries
end
# send an SMS
def self.send to:, text:, **kwargs
@@deliveries << OpenStruct.new({ to: to, text: text })
end
else
# send an SMS
def self.send to:, text:, **kwargs
to.is_a?(Array) or to = [to]
Net::SMTP.start('sms.qtelecom.ru', 2525, 'propetrovich.ru',
QTELECOM_LOGIN, QTELECOM_PASSWORD, :plain) do |client|
to.each { |number|
client.send_message "Content-Type: text/plain; charset=utf-8\n\n#{text}",
nil,
"#{number}@sms.qtelecom.ru"
}
end
nil
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment