7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/websms/sender.rb', line 7
def self.send_message(to, text)
return false if to.empty?
raise ArgumentError, "Empty text, wont send it" if text.empty?
c = Websms.configuration
sms_gateway = "http://websms.ru/http_in4.asp"
sms_user = c.api_user
sms_password = c.api_password
number = to.gsub(/[^\d]/, '')
text = "#{c.client_id}: #{text}" if c.client_id
etext = text.gsub(' ', '%20')
etext = Iconv.conv('windows-1251', 'utf-8', etext)
from_phone = c.alfanum_from ? "&fromPhone=#{c.alfanum_from}" : ''
request = "#{sms_gateway}?http_username=#{sms_user}&http_password=#{sms_password}#{from_phone}&Phone_list=#{number}&Message=#{etext}"
c = Curl::Easy.perform(request)
end
|