balance 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +26 -0
- data/bin/balance +16 -0
- data/lib/balance.rb +26 -0
- data/lib/balance/providers/domolink_kaluga.rb +20 -0
- data/lib/balance/providers/locum_ru.rb +18 -0
- data/lib/balance/providers/megafon_moscow.rb +16 -0
- data/lib/balance/providers/mts_moscow.rb +19 -0
- data/lib/balance/version.rb +9 -0
- metadata +97 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Alexey Noskov
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
= Balance
|
2
|
+
|
3
|
+
Balance is a gem automating checking balance for different service providers.
|
4
|
+
|
5
|
+
== Supported providers
|
6
|
+
|
7
|
+
=== Mobile
|
8
|
+
|
9
|
+
* Megafon Moscow (https://www.serviceguide.megafonmoscow.ru/)
|
10
|
+
* MTS Moscow (https://ihelper.mts.ru/SELFCAREPDA/Security.mvc/LogOn)
|
11
|
+
|
12
|
+
=== Internet
|
13
|
+
|
14
|
+
* Domolink Kaluga (http://radius.kaluga.ru)
|
15
|
+
|
16
|
+
=== Hosting
|
17
|
+
|
18
|
+
* Locum (http://locum.ru)
|
19
|
+
|
20
|
+
== Contributors
|
21
|
+
|
22
|
+
* Alexey Noskov (http://github.com/alno)
|
23
|
+
|
24
|
+
Feel free to request pull of new providers.
|
25
|
+
|
26
|
+
Copyright (c) 2011 Alexey Noskov, released under the MIT license
|
data/bin/balance
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
unless ARGV[0] && ARGV[1] && ARGV[2]
|
4
|
+
puts 'Usage: balance [PROVIDER] [LOGIN] [PASSWORD]'
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'rubygems'
|
9
|
+
require 'balance'
|
10
|
+
|
11
|
+
begin
|
12
|
+
puts Balance.provider(ARGV[0]).check(ARGV[1], ARGV[2])
|
13
|
+
rescue
|
14
|
+
puts "N/A"
|
15
|
+
raise $!
|
16
|
+
end
|
data/lib/balance.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
class Balance
|
2
|
+
|
3
|
+
module Providers; end
|
4
|
+
|
5
|
+
class ProviderNotFound < StandardError; end
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
# Register new provider
|
10
|
+
def add_provider! name, provider
|
11
|
+
@providers ||= {}
|
12
|
+
@providers[name.to_s] = provider
|
13
|
+
end
|
14
|
+
|
15
|
+
# Get provider by name
|
16
|
+
def provider name
|
17
|
+
require File.join(File.dirname(__FILE__), 'balance', 'providers', name.to_s)
|
18
|
+
|
19
|
+
@providers[name.to_s].new
|
20
|
+
rescue LoadError
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
|
3
|
+
class Balance::Providers::DomolinkKaluga
|
4
|
+
|
5
|
+
def check( login, password )
|
6
|
+
agent = Mechanize.new
|
7
|
+
|
8
|
+
login_page = agent.get 'http://cabinet.kaluga.ru/klg/www.PageViewer?page_name=S*START_PAGE'
|
9
|
+
login_form = login_page.forms.first
|
10
|
+
login_form.field(:name => 'p_logname').value = login.upcase
|
11
|
+
login_form.field(:name => 'p_pwd').value = password
|
12
|
+
|
13
|
+
result_page = agent.get login_form.submit.meta.first.href
|
14
|
+
|
15
|
+
result_page.parser.css('.dat').text.match(/\d+\.\d+/)[0].to_f
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
Balance.add_provider! 'domolink_kaluga', Balance::Providers::DomolinkKaluga
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
|
3
|
+
class Balance::Providers::LocumRu
|
4
|
+
|
5
|
+
def check( login, password )
|
6
|
+
agent = Mechanize.new
|
7
|
+
|
8
|
+
login_page = agent.get 'http://locum.ru/'
|
9
|
+
login_form = login_page.forms.first
|
10
|
+
login_form.field(:name => 'login_data[login]').value = login
|
11
|
+
login_form.field(:name => 'login_data[password]').value = password
|
12
|
+
|
13
|
+
login_form.submit.parser.css('#cpl-data .section .value .number').first.text.to_f
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
Balance.add_provider! 'locum_ru', Balance::Providers::LocumRu
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
|
3
|
+
class Balance::Providers::MegafonMoscow
|
4
|
+
|
5
|
+
def check( number, password )
|
6
|
+
agent = Mechanize.new
|
7
|
+
agent.user_agent = 'Mozilla/5.0 (Linux; U; Android 2.2; en-us; Desire_A8181 Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
|
8
|
+
agent.get 'https://www.serviceguide.megafonmoscow.ru/'
|
9
|
+
|
10
|
+
p = agent.post 'https://www.serviceguide.megafonmoscow.ru/ps/scc/mobile/', 'MOBILE_MODE' => 'AUTH', 'LOGIN' => number, 'PASSWORD' => password
|
11
|
+
p.parser.css('#statusbalance').text.match(/\d+\.\d+/)[0].to_f
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
Balance.add_provider! 'megafon_moscow', Balance::Providers::MegafonMoscow
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
|
3
|
+
class Balance::Providers::MtsMoscow
|
4
|
+
|
5
|
+
def check( number, password )
|
6
|
+
agent = Mechanize.new
|
7
|
+
agent.user_agent = 'Mozilla/5.0 (Linux; U; Android 2.2; en-us; Desire_A8181 Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'
|
8
|
+
|
9
|
+
login_page = agent.get 'https://ihelper.mts.ru/SELFCAREPDA/Security.mvc/LogOn'
|
10
|
+
login_form = login_page.forms.first
|
11
|
+
login_form.field(:name => 'username').value = number
|
12
|
+
login_form.field(:name => 'password').value = password
|
13
|
+
|
14
|
+
login_form.submit.parser.css('.main p strong strong').text.to_f
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
Balance.add_provider! 'mts_moscow', Balance::Providers::MtsMoscow
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: balance
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Alexey Noskov
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-05 00:00:00 +03:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: mechanize
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: Balance is a gem automating checking balance for different service providers, such as mobile operators, hosting providers.
|
36
|
+
email:
|
37
|
+
- alexey.noskov@gmail.com
|
38
|
+
executables:
|
39
|
+
- balance
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files:
|
43
|
+
- README.rdoc
|
44
|
+
- MIT-LICENSE
|
45
|
+
files:
|
46
|
+
- lib/balance/version.rb
|
47
|
+
- lib/balance/providers/locum_ru.rb
|
48
|
+
- lib/balance/providers/domolink_kaluga.rb
|
49
|
+
- lib/balance/providers/megafon_moscow.rb
|
50
|
+
- lib/balance/providers/mts_moscow.rb
|
51
|
+
- lib/balance.rb
|
52
|
+
- bin/balance
|
53
|
+
- MIT-LICENSE
|
54
|
+
- README.rdoc
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://github.com/alno/balance
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options:
|
61
|
+
- --line-numbers
|
62
|
+
- --inline-source
|
63
|
+
- --title
|
64
|
+
- Rayo CMS
|
65
|
+
- --main
|
66
|
+
- README.rdoc
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
hash: 23
|
84
|
+
segments:
|
85
|
+
- 1
|
86
|
+
- 3
|
87
|
+
- 6
|
88
|
+
version: 1.3.6
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.3.7
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: Balance is a gem automating checking balance for different service providers.
|
96
|
+
test_files: []
|
97
|
+
|