class Mobistar::Client
Constants
- LOGIN_URL
Public Class Methods
new(username, password) { |self| ... }
click to toggle source
# File lib/mobistar.rb, line 35 def initialize username, password @loggedin = nil @agent = Mechanize.new do |ag| ag.follow_meta_refresh = true end if block_given? loginDWR username, password yield self end end
Public Instance Methods
send_sms(number, message)
click to toggle source
# File lib/mobistar.rb, line 46 def send_sms number, message number_parsed = number.kind_of?(Number) ? number : Number.new(number) number = number_parsed.belgian #Ensure valid number raise NotLoggedIn unless @loggedin link = @loggedin.link_with :text => 'Envoyer un e-mail' raise MissingLink unless link send_email = @agent.click link link = send_email.link_with :text => /crire un SMS$/ raise MissingLink unless link #Go to SMS Page and use form send_sms = @agent.click link confirmation = send_sms.form_with(:name => "formulaire"){|form| form['NUMTEL'] = number form['listetel'] = ',,'+number form['corpsms'] = form['msg'] = message form['typesms'] = '2' form['produit'] = '1000' form['delai'] = 'now' }.submit.form_with(:name=>'formulaire').submit return true end
Protected Instance Methods
loginDWR(username, password)
click to toggle source
# File lib/mobistar.rb, line 71 def loginDWR username, password url = LOGIN_URL.gsub(/%\{USERNAME\}/, username).gsub(/%\{PASSWORD\}/, password) loginDWR = @agent.get url if loginDWR.body =~ /dwr.engine._remoteHandleCallback\('0','0',\{(.+)\}\);$/ response = {} $1.split(/,/).each do |keyval| key, val = keyval.split(/:/, 2) val = val[1...-1] if val.start_with?('"') && val.end_with?('"') val = nil if val == "null" val = false if val == "false" val = true if val == "true" response[key] = val end else raise AuthenticationError end auth_cookie = Mechanize::Cookie.new 'SMSESSION', response['cookieSMValue'] auth_cookie.domain = '.mobistar.be' auth_cookie.path = '/' cook = @agent.cookie_jar.add @agent.history.last.uri, auth_cookie raise CookieError, "Cannot add auth cookie to session !!!" unless cook @loggedin = @agent.get response['targetURL'] return true end