Class: TelenorSMS
- Inherits:
-
Object
- Object
- TelenorSMS
- Defined in:
- lib/telenorsms.rb
Instance Method Summary collapse
-
#initialize(username, password) ⇒ TelenorSMS
constructor
A new instance of TelenorSMS.
- #login(username, password) ⇒ Object
- #send(message, recipients) ⇒ Object
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" login 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 login username, password forms = @agent.get(@login_url).forms login_form = nil forms.each {|form| login_form = form if form.action == "https://telenormobil.no/minesider/login.do" } login_form.j_username = username login_form.j_password = password @agent.submit(login_form) 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 , recipients Guard::require != nil && != "", "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. = sms_form. end |