Class: TelenorSMS

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

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ TelenorSMS

Returns a new instance of TelenorSMS.



12
13
14
15
16
17
18
19
20
# File 'lib/telenorsms.rb', line 12

def initialize username, password
  Guard::require username != nil && username != "", "username must be specified"
  Guard::require password != nil && password != "", "password must be specified"

  @agent = Mechanize.new
  @agent.user_agent_alias = "Windows IE 6"
  @login_url = "https://telenormobil.no/minesider/login.do"
   username, password
end

Instance Method Details

#login(username, password) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/telenorsms.rb', line 22

def  username, password
  forms = @agent.get(@login_url).forms
   = nil
  forms.each {|form|  = form if form.action == "https://telenormobil.no/minesider/login.do" }
  .j_username = username
  .j_password = password
  @agent.submit()

  if @agent.page.uri.to_s == @login_url then
    error = @agent.page / "div[id='main_content']" / "div[class='section error']" / "span"
    if error != nil then raise error.inner_html end
  end
end

#send(message, recipients) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/telenorsms.rb', line 36

def send message, recipients
  Guard::require message != nil && message != "", "Must contain message"
  Guard::require recipients != nil && recipients != "", "Must contain recipients"

  @agent.get "https://telenormobil.no/norm/telenor/sms/send.do"
  sms_form = nil
  @agent.page.forms.each{|form| sms_form = form if form.action == "/norm/telenor/sms/send/process.do" }
  sms_form.toAddress = recipients
  sms_form.message = message
  sms_form.click_button
end