Class: Routo::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ Message

Returns a new instance of Message.



8
9
10
11
# File 'lib/routo/message.rb', line 8

def initialize text
  @text = text
  generate_mess_id
end

Instance Attribute Details

#recipientsObject

Returns the value of attribute recipients.



6
7
8
# File 'lib/routo/message.rb', line 6

def recipients
  @recipients
end

#textObject

Returns the value of attribute text.



5
6
7
# File 'lib/routo/message.rb', line 5

def text
  @text
end

Instance Method Details

#send_sms(*numbers) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/routo/message.rb', line 13

def send_sms *numbers
  options = numbers.last.is_a?(Hash) ? numbers.pop : {}
  @recipients = numbers.map{|n| Number.new(n)}
  begin
    parse_response(Net::HTTP.post_form(URI.parse(Routo.http_api_url), params(options)))
  rescue Routo::Exception::SystemError, Routo::Exception::Failed # trying with backup url if Routo returns an internal error
    begin # here a mail error should not prevent the sms to be send
      Pony.mail(:to => Routo.email, :subject => Routo.using_backup_url[:subject], :body => Routo.using_backup_url[:body]) if Routo.email && Routo.using_backup_url.present? && Routo.using_backup_url_sent_at.to_i<(Time.now.to_i-Routo.seconds_between_mails)
      Routo.using_backup_url_sent_at = Time.now
    ensure
      parse_response(Net::HTTP.post_form(URI.parse(Routo.http_api_url_backup), params(options)))
    end
  end
end