vnstat-ruby 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +49 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -5
- data/Gemfile +4 -10
- data/Gemfile.lock +29 -75
- data/LICENSE.txt +18 -17
- data/README.md +1 -3
- data/Rakefile +4 -25
- data/lib/vnstat-ruby.rb +2 -0
- data/lib/vnstat.rb +17 -2
- data/lib/vnstat/configuration.rb +4 -2
- data/lib/vnstat/document.rb +6 -1
- data/lib/vnstat/error.rb +2 -0
- data/lib/vnstat/errors/executable_not_found.rb +2 -0
- data/lib/vnstat/errors/unknown_interface.rb +2 -0
- data/lib/vnstat/interface.rb +4 -1
- data/lib/vnstat/interface_collection.rb +2 -0
- data/lib/vnstat/parser.rb +4 -2
- data/lib/vnstat/result.rb +8 -5
- data/lib/vnstat/result/date_delegation.rb +2 -0
- data/lib/vnstat/result/day.rb +4 -1
- data/lib/vnstat/result/hour.rb +6 -2
- data/lib/vnstat/result/minute.rb +5 -2
- data/lib/vnstat/result/month.rb +6 -2
- data/lib/vnstat/result/time_comparable.rb +2 -0
- data/lib/vnstat/system_call.rb +10 -7
- data/lib/vnstat/traffic.rb +2 -0
- data/lib/vnstat/traffic/base.rb +2 -0
- data/lib/vnstat/traffic/daily.rb +2 -0
- data/lib/vnstat/traffic/hourly.rb +2 -0
- data/lib/vnstat/traffic/monthly.rb +2 -0
- data/lib/vnstat/traffic/tops.rb +2 -0
- data/lib/vnstat/utils.rb +2 -0
- data/lib/vnstat/version.rb +5 -0
- data/vnstat-ruby.gemspec +36 -109
- metadata +27 -65
- data/.codeclimate.yml +0 -14
- data/spec/lib/vnstat/configuration_spec.rb +0 -72
- data/spec/lib/vnstat/document_spec.rb +0 -54
- data/spec/lib/vnstat/errors/executable_not_found_spec.rb +0 -5
- data/spec/lib/vnstat/errors/unknown_interface_spec.rb +0 -5
- data/spec/lib/vnstat/interface_collection_spec.rb +0 -194
- data/spec/lib/vnstat/interface_spec.rb +0 -327
- data/spec/lib/vnstat/result/day_spec.rb +0 -39
- data/spec/lib/vnstat/result/hour_spec.rb +0 -43
- data/spec/lib/vnstat/result/minute_spec.rb +0 -54
- data/spec/lib/vnstat/result/month_spec.rb +0 -39
- data/spec/lib/vnstat/result_spec.rb +0 -86
- data/spec/lib/vnstat/system_call_spec.rb +0 -209
- data/spec/lib/vnstat/traffic/daily_spec.rb +0 -109
- data/spec/lib/vnstat/traffic/hourly_spec.rb +0 -153
- data/spec/lib/vnstat/traffic/monthly_spec.rb +0 -46
- data/spec/lib/vnstat/traffic/tops_spec.rb +0 -48
- data/spec/lib/vnstat/utils_spec.rb +0 -130
- data/spec/lib/vnstat_spec.rb +0 -61
- data/spec/spec_helper.rb +0 -98
- data/spec/support/shared_examples/shared_examples_for_date_delegation.rb +0 -19
- data/spec/support/shared_examples/shared_examples_for_traffic_collection.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1147fd1dc7aa2c9d3990b48e410a1a2f68e8ecd3e5dfc390116131f703050624
|
4
|
+
data.tar.gz: 5804a8055fc72e8f5dd9fefe888072524ebd8ee842fa26194b45130106dbc170
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e2be0b328f5b8df0dea239b8c2554d812afc439c89798844fe80dc2edf4fb5f1841ffd1036c3470763fca10a2cc21d90a816043030e89bd250edf3151f3ccb6
|
7
|
+
data.tar.gz: b163535f90d28910ec626e7d3e997c426addb363dfa50b242f5d0a384b0e9b92ceeeadc000a3d4a1d3af52934125b0ecaab6b6409b7b088448c0f810713f1861
|
data/.gitignore
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
coverage.data
|
4
|
+
|
5
|
+
# rdoc generated
|
6
|
+
rdoc
|
7
|
+
|
8
|
+
# yard generated
|
9
|
+
doc
|
10
|
+
.yardoc
|
11
|
+
|
12
|
+
# bundler
|
13
|
+
.bundle
|
14
|
+
|
15
|
+
# jeweler generated
|
16
|
+
pkg
|
17
|
+
|
18
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
19
|
+
#
|
20
|
+
# * Create a file at ~/.gitignore
|
21
|
+
# * Include files you want ignored
|
22
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
23
|
+
#
|
24
|
+
# After doing this, these files will be ignored in all your git projects,
|
25
|
+
# saving you from having to 'pollute' every project you touch with them
|
26
|
+
#
|
27
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
28
|
+
#
|
29
|
+
# For MacOS:
|
30
|
+
#
|
31
|
+
#.DS_Store
|
32
|
+
|
33
|
+
# For TextMate
|
34
|
+
#*.tmproj
|
35
|
+
#tmtags
|
36
|
+
|
37
|
+
# For emacs:
|
38
|
+
#*~
|
39
|
+
#\#*
|
40
|
+
#.\#*
|
41
|
+
|
42
|
+
# For vim:
|
43
|
+
#*.swp
|
44
|
+
|
45
|
+
# For redcar:
|
46
|
+
#.redcar
|
47
|
+
|
48
|
+
# For rubinius:
|
49
|
+
#*.rbc
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
vnstat-ruby
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.5.0
|
data/.travis.yml
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
sudo: false
|
1
2
|
language: ruby
|
2
3
|
rvm:
|
3
|
-
- '2.
|
4
|
-
- '2.
|
5
|
-
- '2.
|
6
|
-
- '2.3
|
7
|
-
- '2.
|
4
|
+
- '2.1.10'
|
5
|
+
- '2.2.8'
|
6
|
+
- '2.3.6'
|
7
|
+
- '2.4.3'
|
8
|
+
- '2.5.0'
|
9
|
+
before_install: gem install bundler -v 1.14.6
|
8
10
|
script: bundle exec rspec
|
9
11
|
addons:
|
10
12
|
code_climate:
|
data/Gemfile
CHANGED
@@ -1,12 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source 'https://rubygems.org'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
gem 'codeclimate-test-reporter', '0.6.0', require: false
|
8
|
-
gem 'jeweler', '~> 2.0', '>= 2.0.1'
|
9
|
-
gem 'rspec', '~> 3.0'
|
10
|
-
gem 'rubocop', '~> 0'
|
11
|
-
gem 'yard', '~> 0'
|
12
|
-
end
|
5
|
+
# Specify your gem's dependencies in vnstat-ruby.gemspec
|
6
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,62 +1,23 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
vnstat-ruby (2.0.0)
|
5
|
+
nokogiri (~> 1.8)
|
6
|
+
|
1
7
|
GEM
|
2
|
-
remote:
|
8
|
+
remote: https://rubygems.org/
|
3
9
|
specs:
|
4
|
-
|
5
|
-
public_suffix (~> 2.0, >= 2.0.2)
|
6
|
-
ast (2.3.0)
|
7
|
-
builder (3.2.3)
|
8
|
-
codeclimate-test-reporter (0.6.0)
|
9
|
-
simplecov (>= 0.7.1, < 1.0.0)
|
10
|
-
descendants_tracker (0.0.4)
|
11
|
-
thread_safe (~> 0.3, >= 0.3.1)
|
10
|
+
ast (2.4.0)
|
12
11
|
diff-lcs (1.2.5)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
descendants_tracker (~> 0.0.1)
|
20
|
-
faraday (~> 0.8, < 0.10)
|
21
|
-
hashie (>= 1.2)
|
22
|
-
multi_json (>= 1.7.5, < 2.0)
|
23
|
-
nokogiri (~> 1.6.0)
|
24
|
-
oauth2
|
25
|
-
hashie (3.5.5)
|
26
|
-
highline (1.7.8)
|
27
|
-
jeweler (2.1.2)
|
28
|
-
builder
|
29
|
-
bundler (>= 1.0)
|
30
|
-
git (>= 1.2.5)
|
31
|
-
github_api (~> 0.11.0)
|
32
|
-
highline (>= 1.6.15)
|
33
|
-
nokogiri (>= 1.5.10)
|
34
|
-
rake
|
35
|
-
rdoc
|
36
|
-
semver
|
37
|
-
json (2.1.0)
|
38
|
-
jwt (1.5.6)
|
39
|
-
mini_portile2 (2.1.0)
|
40
|
-
multi_json (1.12.1)
|
41
|
-
multi_xml (0.6.0)
|
42
|
-
multipart-post (2.0.0)
|
43
|
-
nokogiri (1.6.8.1)
|
44
|
-
mini_portile2 (~> 2.1.0)
|
45
|
-
oauth2 (1.3.1)
|
46
|
-
faraday (>= 0.8, < 0.12)
|
47
|
-
jwt (~> 1.0)
|
48
|
-
multi_json (~> 1.3)
|
49
|
-
multi_xml (~> 0.5)
|
50
|
-
rack (>= 1.2, < 3)
|
51
|
-
parser (2.4.0.0)
|
52
|
-
ast (~> 2.2)
|
12
|
+
mini_portile2 (2.3.0)
|
13
|
+
nokogiri (1.8.2)
|
14
|
+
mini_portile2 (~> 2.3.0)
|
15
|
+
parallel (1.12.1)
|
16
|
+
parser (2.5.0.4)
|
17
|
+
ast (~> 2.4.0)
|
53
18
|
powerpack (0.1.1)
|
54
|
-
|
55
|
-
|
56
|
-
rainbow (2.2.2)
|
57
|
-
rake
|
58
|
-
rake (12.0.0)
|
59
|
-
rdoc (5.1.0)
|
19
|
+
rainbow (3.0.0)
|
20
|
+
rake (10.5.0)
|
60
21
|
rspec (3.3.0)
|
61
22
|
rspec-core (~> 3.3.0)
|
62
23
|
rspec-expectations (~> 3.3.0)
|
@@ -70,34 +31,27 @@ GEM
|
|
70
31
|
diff-lcs (>= 1.2.0, < 2.0)
|
71
32
|
rspec-support (~> 3.3.0)
|
72
33
|
rspec-support (3.3.0)
|
73
|
-
rubocop (0.
|
74
|
-
|
34
|
+
rubocop (0.53.0)
|
35
|
+
parallel (~> 1.10)
|
36
|
+
parser (>= 2.5)
|
75
37
|
powerpack (~> 0.1)
|
76
|
-
rainbow (>=
|
38
|
+
rainbow (>= 2.2.2, < 4.0)
|
77
39
|
ruby-progressbar (~> 1.7)
|
78
40
|
unicode-display_width (~> 1.0, >= 1.0.1)
|
79
|
-
ruby-progressbar (1.
|
80
|
-
|
81
|
-
|
82
|
-
docile (~> 1.1.0)
|
83
|
-
json (>= 1.8, < 3)
|
84
|
-
simplecov-html (~> 0.10.0)
|
85
|
-
simplecov-html (0.10.0)
|
86
|
-
thread_safe (0.3.6)
|
87
|
-
unicode-display_width (1.2.1)
|
88
|
-
yard (0.9.9)
|
41
|
+
ruby-progressbar (1.9.0)
|
42
|
+
unicode-display_width (1.3.0)
|
43
|
+
yard (0.9.12)
|
89
44
|
|
90
45
|
PLATFORMS
|
91
46
|
ruby
|
92
47
|
|
93
48
|
DEPENDENCIES
|
94
|
-
bundler (~> 1.
|
95
|
-
|
96
|
-
jeweler (~> 2.0, >= 2.0.1)
|
97
|
-
nokogiri (~> 1.6)
|
49
|
+
bundler (~> 1.14)
|
50
|
+
rake (~> 10.0)
|
98
51
|
rspec (~> 3.0)
|
99
|
-
rubocop (~> 0)
|
100
|
-
|
52
|
+
rubocop (~> 0.53)
|
53
|
+
vnstat-ruby!
|
54
|
+
yard (~> 0.9.12)
|
101
55
|
|
102
56
|
BUNDLED WITH
|
103
|
-
1.
|
57
|
+
1.16.1
|
data/LICENSE.txt
CHANGED
@@ -1,20 +1,21 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
2
|
|
3
|
-
|
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:
|
3
|
+
Copyright (c) 2018 Tobias Casper
|
10
4
|
|
11
|
-
|
12
|
-
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
13
11
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# vnstat-ruby
|
2
2
|
|
3
|
-
[![Code Climate](https://codeclimate.com/github/tlux/vnstat-ruby/badges/gpa.svg)](https://codeclimate.com/github/tlux/vnstat-ruby)
|
4
|
-
[![Test Coverage](https://codeclimate.com/github/tlux/vnstat-ruby/badges/coverage.svg)](https://codeclimate.com/github/tlux/vnstat-ruby/coverage)
|
5
3
|
[![Build Status](https://travis-ci.org/tlux/vnstat-ruby.svg?branch=master)](https://travis-ci.org/tlux/vnstat-ruby)
|
6
4
|
[![Gem Version](https://badge.fury.io/rb/vnstat-ruby.svg)](https://badge.fury.io/rb/vnstat-ruby)
|
7
5
|
|
@@ -15,7 +13,7 @@ maintained by Teemu Toivola.
|
|
15
13
|
|
16
14
|
### Prerequisites
|
17
15
|
|
18
|
-
* Ruby 2.
|
16
|
+
* Ruby 2.1.0 or greater
|
19
17
|
* Make sure you have `vnstat` CLI installed by running `which vnstat`.
|
20
18
|
|
21
19
|
On Ubuntu you can get the vnstat package via `apt-get install vnstat`.
|
data/Rakefile
CHANGED
@@ -1,27 +1,6 @@
|
|
1
|
-
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require "rspec/core/rake_task"
|
2
3
|
|
3
|
-
|
4
|
-
require 'bundler'
|
5
|
-
begin
|
6
|
-
Bundler.setup(:default, :development)
|
7
|
-
rescue Bundler::BundlerError => e
|
8
|
-
$stderr.puts e.message
|
9
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
-
exit e.status_code
|
11
|
-
end
|
12
|
-
require 'rake'
|
13
|
-
require 'jeweler'
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
14
5
|
|
15
|
-
|
16
|
-
# gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
|
17
|
-
gem.name = 'vnstat-ruby'
|
18
|
-
gem.homepage = 'http://github.com/tlux/vnstat-ruby'
|
19
|
-
gem.license = 'MIT'
|
20
|
-
gem.summary = 'A Ruby wrapper for vnstat.'
|
21
|
-
gem.description = 'Uses the the vnstat CLI to track your network traffic.'
|
22
|
-
gem.email = 'tobias.casper@gmail.com'
|
23
|
-
gem.authors = ['Tobias Casper']
|
24
|
-
# dependencies defined in Gemfile
|
25
|
-
end
|
26
|
-
|
27
|
-
Jeweler::RubygemsDotOrgTasks.new
|
6
|
+
task default: :spec
|
data/lib/vnstat-ruby.rb
CHANGED
data/lib/vnstat.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'vnstat/version'
|
6
|
+
require 'time'
|
3
7
|
|
4
8
|
##
|
5
9
|
# The Vnstat namespace.
|
@@ -58,8 +62,19 @@ module Vnstat
|
|
58
62
|
##
|
59
63
|
# Returns information for the currently installed version of vnstat.
|
60
64
|
#
|
65
|
+
# @deprecated Please use {#cli_version} instead.
|
61
66
|
# @return [String]
|
62
67
|
def version
|
68
|
+
warn '[DEPRECATION] `Vnstat.version` is deprecated. Please use ' \
|
69
|
+
'`Vnstat.cli_version` instead.'
|
70
|
+
cli_version
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
# Returns information for the currently installed version of vnstat.
|
75
|
+
#
|
76
|
+
# @return [String]
|
77
|
+
def cli_version
|
63
78
|
Utils.call_executable('-v')
|
64
79
|
end
|
65
80
|
end
|
data/lib/vnstat/configuration.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Vnstat
|
2
4
|
##
|
3
5
|
# A class encapsulating configurations of the Vnstat environment.
|
4
6
|
#
|
5
|
-
#
|
6
|
-
# executable.
|
7
|
+
# @!attribute executable_path
|
8
|
+
# @return The location of the vnstat executable.
|
7
9
|
class Configuration
|
8
10
|
##
|
9
11
|
# Initializes the {Configuration}.
|
data/lib/vnstat/document.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'nokogiri'
|
4
|
+
|
1
5
|
module Vnstat
|
2
6
|
# A class encapsulating document data.
|
3
7
|
#
|
4
|
-
#
|
8
|
+
# @!attribute [r] data
|
9
|
+
# @return [Nokogiri::XML::Document] The underlying XML document.
|
5
10
|
class Document
|
6
11
|
##
|
7
12
|
# Initializes the document.
|
data/lib/vnstat/error.rb
CHANGED
data/lib/vnstat/interface.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Vnstat
|
2
4
|
##
|
3
5
|
# A class encapsulating traffic information for a specific network interface.
|
4
6
|
#
|
5
|
-
#
|
7
|
+
# @!attribute [r] id
|
8
|
+
# @return [String] The network interface identifier.
|
6
9
|
class Interface < Document
|
7
10
|
attr_reader :id
|
8
11
|
|
data/lib/vnstat/parser.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Vnstat
|
2
4
|
##
|
3
5
|
# A module containing several utility methods responsible for document
|
@@ -36,8 +38,8 @@ module Vnstat
|
|
36
38
|
date = extract_date_from_xml_element(element)
|
37
39
|
hour = element.xpath('time/hour').text.to_i
|
38
40
|
minute = element.xpath('time/minute').text.to_i
|
39
|
-
|
40
|
-
|
41
|
+
offset = Time.now.strftime('%:z')
|
42
|
+
Time.new(date.year, date.month, date.day, hour, minute, 0, offset)
|
41
43
|
end
|
42
44
|
|
43
45
|
##
|