Last active
January 27, 2017 13:04
-
-
Save charger/47dcd85a54954303c6ef to your computer and use it in GitHub Desktop.
Using Turbo SMS service with ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#для работы этого кода нужно установить гем 'savon' | |
#для этого выполните: gem install savon | |
#или пропишите в Gemfile: gem 'savon' | |
class TurboSMS | |
LOGIN = '...' # не забудьте активировать SOAP шлюз в личном кабинете и создать логин/пароль | |
PASSWORD = '...' | |
SENDER = 'MySite' #не забудьте добавить эту подпись в личном кабинете | |
def get_balance | |
response = logged_client.call(:get_credit_balance) | |
response.body.try(:[],:get_credit_balance_response).try(:[], :get_credit_balance_result) | |
end | |
def send_sms(phone, text) | |
response = logged_client.call(:send_sms, message: { sender: SENDER, destination: phone, text: text }) | |
response.body.try(:[],:send_sms_response).try(:[], :send_sms_result).try(:[], :result_array) | |
end | |
def logged_client | |
return @logged_client if @logged_client | |
client ||= Savon.client(wsdl: 'http://turbosms.in.ua/api/wsdl.html') | |
response = client.call(:auth, message: { login: LOGIN, password: PASSWORD } ) | |
@logged_client = Savon.client(wsdl: 'http://turbosms.in.ua/api/wsdl.html', headers: { 'Cookie' => response.http.headers['Set-Cookie'] }) | |
end | |
end | |
#Пример использования | |
#TurboSMS.new.get_balance => "10.0" | |
#TurboSMS.new.send_sms('+380...', 'Test message') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment