Class: SmsSender::SmsApiSender

Inherits:
Object
  • Object
show all
Defined in:
lib/sms_api_sender.rb

Constant Summary collapse

SMS_API_URL =
"https://ssl.smsapi.pl/send.do"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ SmsApiSender

Returns a new instance of SmsApiSender.



12
13
14
# File 'lib/sms_api_sender.rb', line 12

def initialize logger
  @logger = logger
end

Instance Attribute Details

#eco=(value) ⇒ Object (writeonly)

Sets the attribute eco

Parameters:

  • value

    the value to set the attribute eco to.



10
11
12
# File 'lib/sms_api_sender.rb', line 10

def eco=(value)
  @eco = value
end

#from=(value) ⇒ Object (writeonly)

Sets the attribute from

Parameters:

  • value

    the value to set the attribute from to.



10
11
12
# File 'lib/sms_api_sender.rb', line 10

def from=(value)
  @from = value
end

#login=(value) ⇒ Object (writeonly)

Sets the attribute login

Parameters:

  • value

    the value to set the attribute login to.



10
11
12
# File 'lib/sms_api_sender.rb', line 10

def login=(value)
  @login = value
end

#password=(value) ⇒ Object (writeonly)

Sets the attribute password

Parameters:

  • value

    the value to set the attribute password to.



10
11
12
# File 'lib/sms_api_sender.rb', line 10

def password=(value)
  @password = value
end

#test=(value) ⇒ Object (writeonly)

Sets the attribute test

Parameters:

  • value

    the value to set the attribute test to.



10
11
12
# File 'lib/sms_api_sender.rb', line 10

def test=(value)
  @test = value
end

Instance Method Details

#send_sms(message) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sms_api_sender.rb', line 16

def send_sms message
  url = URI.parse(SMS_API_URL)
  req = Net::HTTP::Post.new(url.path)
  params = basic_params message
  add_extra_params(params)
  req.set_form_data(params)
  @logger.info "Requesting sms api to send message: #{truncated_text(message)}"
  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true
  res = http.start { |http| http.request(req) }
  @logger.info "Sms api request finished processing with response #{res.body}"
  if sms_not_sent? res
    raise SmsApiError.new(res.code)
  end
end