Class: Mobistar::Client

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

Constant Summary collapse

LOGIN_URL =
"https://res.mobistar.be/imfrontend/dwr/call/plaincall/LoginDwr.checkLogin.dwr?callCount=1&page=%2Ffr%2Fe-services%2Flogin%3FTYPE%3D33554433%26REALMOID%3D06-38929314-8a51-1125-95a9-84e323580cb3%26GUID%3D%26SMAUTHREASON%3D0%26METHOD%3DGET%26SMAGENTNAME%3D%24SM%244T0F5sTwaomxEpeIVaniBrJhN3p12h%252fZ1tlR7msTW8vDiSUgQxpGjnQ5sd3em5iO%26TARGET%3D%24SM%24https%253a%252f%252fmy%252emobistar%252ebe%252fsecured%252fespace-client%252findex%252ehtml&httpSessionId=&scriptSessionId=A542EDD0B6E72E6CE3C3C3D8C3E8F464740&c0-scriptName=LoginDwr&c0-methodName=checkLogin&c0-id=0&c0-e1=string%3A%{USERNAME}&c0-e2=string%3A%{PASSWORD}&c0-e3=string%3Afr&c0-e4=string%3A%2524SM%2524https%25253a%25252f%25252fmy%25252emobistar%25252ebe%25252fsecured%25252fespace-client%25252findex%25252ehtml&c0-e5=string%3Amobistarresidential&c0-param0=Object_Object%3A%7Blogin%3Areference%3Ac0-e1%2C%20password%3Areference%3Ac0-e2%2C%20language%3Areference%3Ac0-e3%2C%20targetUrl%3Areference%3Ac0-e4%2C%20referrer%3Areference%3Ac0-e5%7D&batchId=0"

Instance Method Summary collapse

Constructor Details

#initialize(username, password) ⇒ Client

Returns a new instance of Client.



35
36
37
38
39
40
41
42
43
44
# 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

Instance Method Details

#send_sms(number, message) ⇒ Object

Raises:



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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