datameter 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +2 -0
- data/datameter.gemspec +24 -0
- data/lib/datameter.rb +14 -0
- data/lib/datameter/browserlike.rb +31 -0
- data/lib/datameter/spectranet_user.rb +21 -0
- data/lib/datameter/version.rb +3 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 047cee11d318716b7e3ba1f361b5337afc9b56d5
|
4
|
+
data.tar.gz: b463f089e6236d06837770855592a9fea50254a8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 037a916c1bfae50689ab10cd60c20db61c6e4e4bbe7aff7e0a3f9ffa14acb127f54cdbfc068102d3d827429fff4223e0e8d1d2a7c235c318f5c2ab61e6455f29
|
7
|
+
data.tar.gz: 1030b3020e5439ff69897623b3e4c91c4a6a63b3523a6ba09da686ddc3ada36bb586effd7e9fcddf72b1e6bed7541fddac382644fdebc261c8e04b2eaa00367b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Lolu Bodunwa
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Datameter
|
2
|
+
|
3
|
+
This is a simple ruby library for getting your internet data balance.
|
4
|
+
|
5
|
+
It works by programmatically visting your ISP's web portal, filling the login form and scraping the data balance off the page.
|
6
|
+
|
7
|
+
It currently works for just Spectranet, but the plan is to include other ISP's.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'datameter'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install datameter
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
|
28
|
+
require 'datameter'
|
29
|
+
balance = Datameter.get_data_balance('ISP', 'userid', 'password')
|
30
|
+
puts balance
|
31
|
+
>>> 7:336:750(GB:MB:KB)
|
32
|
+
Valid values for ISP - "spectranet"
|
33
|
+
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it ( https://github.com/[my-github-username]/datameter/fork )
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/datameter.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'datameter/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "datameter"
|
8
|
+
spec.version = Datameter::VERSION
|
9
|
+
spec.authors = ["Lolu Bodunwa"]
|
10
|
+
spec.email = ["btemilolu@gmail.com"]
|
11
|
+
spec.summary = %q{ISP Data Balance.}
|
12
|
+
spec.description = %q{Get your ISP Internet Data Balance programmatically.}
|
13
|
+
spec.homepage = "http://lolubodunwa.me"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_dependency "mechanize", "2.7.3"
|
24
|
+
end
|
data/lib/datameter.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative "datameter/version"
|
2
|
+
require_relative "datameter/spectranet_user"
|
3
|
+
|
4
|
+
module Datameter
|
5
|
+
def self.get_data_balance(provider, username, pwd)
|
6
|
+
case provider
|
7
|
+
when "spectranet"
|
8
|
+
user = SpectranetUser.new(username, pwd)
|
9
|
+
user.get_data_balance
|
10
|
+
else
|
11
|
+
puts "ISP - #{provider} not available"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
|
3
|
+
module BrowserLike
|
4
|
+
|
5
|
+
def browser
|
6
|
+
@browser ||= Mechanize.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def page
|
10
|
+
@page
|
11
|
+
end
|
12
|
+
|
13
|
+
def visit_link link
|
14
|
+
@page = browser.get link
|
15
|
+
end
|
16
|
+
|
17
|
+
def find_in_page form_id, form_params, path
|
18
|
+
form = page.form_with(:id => form_id) do |f|
|
19
|
+
form_params.each do |key, value|
|
20
|
+
field = f.field_with(:name => key)
|
21
|
+
field.value = value
|
22
|
+
end
|
23
|
+
end.click_button
|
24
|
+
|
25
|
+
page = form
|
26
|
+
|
27
|
+
page.search(path).each do |node|
|
28
|
+
return node.text.strip
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative 'browserlike'
|
2
|
+
class SpectranetUser
|
3
|
+
include BrowserLike
|
4
|
+
attr_reader :username, :password
|
5
|
+
|
6
|
+
URL = 'http://selfcare.spectranet.com.ng'
|
7
|
+
FORM_ID = 'id4'
|
8
|
+
DATA_BALANCE_XPATH = %q{//table[@class='dataTable']/tr[1]/td[2]/label}
|
9
|
+
|
10
|
+
def initialize username, password
|
11
|
+
@username = username
|
12
|
+
@password = password
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_data_balance
|
16
|
+
visit_link URL
|
17
|
+
balance = find_in_page FORM_ID, {'signInForm.username' => username, 'signInForm.password' => password}, DATA_BALANCE_XPATH
|
18
|
+
if balance != 0 then return balance else return nil end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: datameter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lolu Bodunwa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mechanize
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.7.3
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.7.3
|
55
|
+
description: Get your ISP Internet Data Balance programmatically.
|
56
|
+
email:
|
57
|
+
- btemilolu@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- datameter.gemspec
|
68
|
+
- lib/datameter.rb
|
69
|
+
- lib/datameter/browserlike.rb
|
70
|
+
- lib/datameter/spectranet_user.rb
|
71
|
+
- lib/datameter/version.rb
|
72
|
+
homepage: http://lolubodunwa.me
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.4.5.1
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: ISP Data Balance.
|
96
|
+
test_files: []
|