mobistar 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Rakefile +32 -0
- data/bin/mobistar-phonebook +33 -0
- data/bin/mobistar-sms +55 -0
- data/lib/mobistar.rb +98 -0
- data/lib/mobistar/config.rb +17 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ba5402da9aeb0a5b9ee2aeb4e85871fb2282be15
|
4
|
+
data.tar.gz: 4e37f7eaa9b8816e784e88b780b265966cce139e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 808972f8e59b89ff818a46fea99240dc7b53e84d8ed90857358f548e35e51ad1f51cb0aa9568aaf710196f33b32faa3d126c5fb9d41d280d407886fc7667d8da
|
7
|
+
data.tar.gz: 8f8e2358d34b82a3ddd23e5bb1fd4ef6c6230e153096ace17fe0f1c4e650a06294282281050fcf0d53e1f3ce6cebac9ddbb7e5e73408e75dd08c1a15c714e895
|
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rubygems/package_task'
|
3
|
+
|
4
|
+
spec = Gem::Specification.new do |s|
|
5
|
+
s.platform = Gem::Platform::RUBY
|
6
|
+
s.summary = "Mobistar web services"
|
7
|
+
s.description = 'A client for the web services of the belgian mobile operator Mobistar'
|
8
|
+
s.name = 'mobistar'
|
9
|
+
s.version = '0.1'
|
10
|
+
s.authors = ['Titouan Christophe']
|
11
|
+
s.email = 'titouanchristophe@gmail.com'
|
12
|
+
s.executables += ['mobistar-sms', 'mobistar-phonebook']
|
13
|
+
s.homepage = 'https://github.com/titouanc/mobistar'
|
14
|
+
s.bindir = 'bin'
|
15
|
+
s.require_path = 'lib'
|
16
|
+
s.add_runtime_dependency "mechanize"
|
17
|
+
s.add_runtime_dependency "highline"
|
18
|
+
s.files = FileList['lib/*', 'lib/mobistar/*', 'bin/*', 'Rakefile'].to_a
|
19
|
+
s.licenses = ['GPL']
|
20
|
+
end
|
21
|
+
|
22
|
+
package = Gem::PackageTask.new spec do |pkg|
|
23
|
+
pkg.need_zip = true
|
24
|
+
pkg.need_tar = true
|
25
|
+
end
|
26
|
+
|
27
|
+
task :default => :repackage
|
28
|
+
|
29
|
+
desc "Build and install gem"
|
30
|
+
task :install => ["pkg/#{package.name}.gem"] do |t|
|
31
|
+
sh "gem install #{t.prerequisites.first}"
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'mobistar'
|
4
|
+
require 'mobistar/config'
|
5
|
+
|
6
|
+
Mobistar.load_config!
|
7
|
+
|
8
|
+
Mobistar::Config[:phonebook] = {} unless Mobistar::Config.key? :phonebook
|
9
|
+
|
10
|
+
if ARGV.empty?
|
11
|
+
maxlen = Mobistar::Config[:phonebook].keys.inject 0 do |maxlen, name|
|
12
|
+
maxlen = (name.length > maxlen) ? name.length : maxlen
|
13
|
+
end
|
14
|
+
|
15
|
+
Mobistar::Config[:phonebook].each do |name, number|
|
16
|
+
puts "#{name.capitalize.rjust maxlen}: #{Mobistar::Number.new(number).human}"
|
17
|
+
end
|
18
|
+
else
|
19
|
+
Action = ARGV.shift
|
20
|
+
case Action.downcase
|
21
|
+
when 'add'
|
22
|
+
begin
|
23
|
+
number = Mobistar::Number.new(ARGV.pop).belgian
|
24
|
+
rescue Mobistar::InvalidGSMNumber
|
25
|
+
abort "Invalid phone number #{number}"
|
26
|
+
end
|
27
|
+
name = ARGV*' '
|
28
|
+
abort "Invalid name" if name.empty?
|
29
|
+
Mobistar::Config[:phonebook][name.downcase] = number
|
30
|
+
else
|
31
|
+
abort "Unknow action #{Action}"
|
32
|
+
end
|
33
|
+
end
|
data/bin/mobistar-sms
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "mobistar"
|
4
|
+
require "mobistar/config"
|
5
|
+
require "highline/import"
|
6
|
+
|
7
|
+
#Load configuration
|
8
|
+
Mobistar.load_config!
|
9
|
+
|
10
|
+
if ARGV.length < 2
|
11
|
+
puts "Usage: #{File.basename $0} [@Username] RECIPIENT MESSAGE"
|
12
|
+
puts "RECIPIENT could be an entry from the phonebook"
|
13
|
+
puts "Default username: #{Mobistar::Config[:username]}" if Mobistar::Config.key? :username
|
14
|
+
exit
|
15
|
+
end
|
16
|
+
|
17
|
+
#Parse username, or retrieve it from config
|
18
|
+
if ARGV.first.start_with?('@')
|
19
|
+
Username = ARGV.shift[1..-1]
|
20
|
+
Mobistar::Config[:username] = Username
|
21
|
+
elsif Mobistar::Config.key? :username
|
22
|
+
Username = Mobistar::Config[:username]
|
23
|
+
else
|
24
|
+
abort "No username provided !!!"
|
25
|
+
end
|
26
|
+
|
27
|
+
#Parse phone number, or retrieve it from phonebook
|
28
|
+
dest = ARGV.shift.downcase
|
29
|
+
if Mobistar::Config.key?(:phonebook) && Mobistar::Config[:phonebook].key?(dest)
|
30
|
+
dest = Mobistar::Config[:phonebook][dest]
|
31
|
+
end
|
32
|
+
begin
|
33
|
+
Recipient = Mobistar::Number.new(dest)
|
34
|
+
rescue Mobistar::InvalidGSMNumber => err
|
35
|
+
abort "#{dest} isn't a valid belgian gsm number and isn't in the phonebook"
|
36
|
+
end
|
37
|
+
|
38
|
+
Message = ARGV*' '
|
39
|
+
abort "Empty message !!!" if Message.strip.empty?
|
40
|
+
|
41
|
+
Password = ask("Enter Mobistar client password for \033[1m#{Username}\033[0m"){|q|
|
42
|
+
q.echo = false
|
43
|
+
}
|
44
|
+
abort "No password given" if Password.empty?
|
45
|
+
|
46
|
+
print "Sending #{Message} to #{Recipient.human}... "
|
47
|
+
$stdout.flush
|
48
|
+
|
49
|
+
begin
|
50
|
+
Mobistar::Client.new Username, Password do |client|
|
51
|
+
puts "done !" if client.send_sms Recipient, Message
|
52
|
+
end
|
53
|
+
rescue Mobistar::AuthenticationError, Mobistar::MissingLink, Mobistar::CookieError
|
54
|
+
abort "Unable to connect to Mobistar web services"
|
55
|
+
end
|
data/lib/mobistar.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require "mechanize"
|
2
|
+
|
3
|
+
module Mobistar
|
4
|
+
class CookieError < Exception; end
|
5
|
+
class AuthenticationError < Exception; end
|
6
|
+
class MissingLink < Exception; end
|
7
|
+
class InvalidGSMNumber < Exception; end
|
8
|
+
class NotLoggedIn < Exception; end
|
9
|
+
|
10
|
+
class Number
|
11
|
+
def initialize string
|
12
|
+
if string =~ /^(\+32|0)4([7-9]\d{7})$/
|
13
|
+
@num = $2
|
14
|
+
else
|
15
|
+
raise InvalidGSMNumber, "#{string} isn't a valid belgian gsm number !"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def international
|
20
|
+
"+324#{@num}"
|
21
|
+
end
|
22
|
+
|
23
|
+
def belgian
|
24
|
+
"04#{@num}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def human group=2
|
28
|
+
"04#{@num[0..1]}/#{@num[2..-1].gsub(/(\d{#{group}})/, '\1.')[0...-1]}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Client
|
33
|
+
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"
|
34
|
+
|
35
|
+
def initialize username, password
|
36
|
+
@loggedin = nil
|
37
|
+
@agent = Mechanize.new do |ag|
|
38
|
+
ag.follow_meta_refresh = true
|
39
|
+
end
|
40
|
+
if block_given?
|
41
|
+
loginDWR username, password
|
42
|
+
yield self
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def send_sms number, message
|
47
|
+
number_parsed = number.kind_of?(Number) ? number : Number.new(number)
|
48
|
+
number = number_parsed.belgian #Ensure valid number
|
49
|
+
|
50
|
+
raise NotLoggedIn unless @loggedin
|
51
|
+
link = @loggedin.link_with :text => 'Envoyer un e-mail'
|
52
|
+
raise MissingLink unless link
|
53
|
+
send_email = @agent.click link
|
54
|
+
link = send_email.link_with :text => /crire un SMS$/
|
55
|
+
raise MissingLink unless link
|
56
|
+
|
57
|
+
#Go to SMS Page and use form
|
58
|
+
send_sms = @agent.click link
|
59
|
+
confirmation = send_sms.form_with(:name => "formulaire"){|form|
|
60
|
+
form['NUMTEL'] = number
|
61
|
+
form['listetel'] = ',,'+number
|
62
|
+
form['corpsms'] = form['msg'] = message
|
63
|
+
form['typesms'] = '2'
|
64
|
+
form['produit'] = '1000'
|
65
|
+
form['delai'] = 'now'
|
66
|
+
}.submit.form_with(:name=>'formulaire').submit
|
67
|
+
return true
|
68
|
+
end
|
69
|
+
|
70
|
+
protected
|
71
|
+
def loginDWR username, password
|
72
|
+
url = LOGIN_URL.gsub(/%\{USERNAME\}/, username).gsub(/%\{PASSWORD\}/, password)
|
73
|
+
loginDWR = @agent.get url
|
74
|
+
|
75
|
+
if loginDWR.body =~ /dwr.engine._remoteHandleCallback\('0','0',\{(.+)\}\);$/
|
76
|
+
response = {}
|
77
|
+
$1.split(/,/).each do |keyval|
|
78
|
+
key, val = keyval.split(/:/, 2)
|
79
|
+
val = val[1...-1] if val.start_with?('"') && val.end_with?('"')
|
80
|
+
val = nil if val == "null"
|
81
|
+
val = false if val == "false"
|
82
|
+
val = true if val == "true"
|
83
|
+
response[key] = val
|
84
|
+
end
|
85
|
+
else
|
86
|
+
raise AuthenticationError
|
87
|
+
end
|
88
|
+
|
89
|
+
auth_cookie = Mechanize::Cookie.new 'SMSESSION', response['cookieSMValue']
|
90
|
+
auth_cookie.domain = '.mobistar.be'
|
91
|
+
auth_cookie.path = '/'
|
92
|
+
cook = @agent.cookie_jar.add @agent.history.last.uri, auth_cookie
|
93
|
+
raise CookieError, "Cannot add auth cookie to session !!!" unless cook
|
94
|
+
@loggedin = @agent.get response['targetURL']
|
95
|
+
return true
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Mobistar
|
4
|
+
ConfigFile = File.join(ENV['HOME'], '.mobistar.yml')
|
5
|
+
Config = {}
|
6
|
+
|
7
|
+
def self.load_config!
|
8
|
+
if File.exists? ConfigFile
|
9
|
+
Config.merge! YAML.load_file(ConfigFile)
|
10
|
+
end
|
11
|
+
at_exit do
|
12
|
+
File.open(ConfigFile, 'w') do |f|
|
13
|
+
f.puts YAML.dump(Config)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mobistar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Titouan Christophe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mechanize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: highline
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A client for the web services of the belgian mobile operator Mobistar
|
42
|
+
email: titouanchristophe@gmail.com
|
43
|
+
executables:
|
44
|
+
- mobistar-sms
|
45
|
+
- mobistar-phonebook
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- lib/mobistar.rb
|
50
|
+
- lib/mobistar/config.rb
|
51
|
+
- bin/mobistar-phonebook
|
52
|
+
- bin/mobistar-sms
|
53
|
+
- Rakefile
|
54
|
+
homepage: https://github.com/titouanc/mobistar
|
55
|
+
licenses:
|
56
|
+
- GPL
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.0.2
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Mobistar web services
|
78
|
+
test_files: []
|