argosnap 0.0.4.2 → 0.0.4.3
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 +4 -4
- data/.gitignore +1 -0
- data/bin/argosnap +2 -2
- data/lib/argosnap/balance.rb +17 -10
- data/lib/argosnap/config.rb +7 -5
- data/lib/argosnap/helpers.rb +1 -0
- data/lib/argosnap/install.rb +3 -0
- data/lib/argosnap/notifications.rb +6 -6
- data/lib/argosnap/notifications/mailer.rb +2 -0
- data/lib/argosnap/version.rb +2 -1
- data/test/lib/argosnap/balance_test.rb +17 -0
- data/test/lib/argosnap/options_test.rb +1 -3
- data/test/test_helper.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15e05625d1b29a1f605ceb9231c8834e19fb76a7
|
4
|
+
data.tar.gz: c2470b1958c344712af59df378155a392ab2bafb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60c8ba297c156bc774093c11ab427176721cd349fca743aee64182d59208369e04ceb935432763e6f28217a79cbc3b7d8471c1ed2e596f6135fa7df294576e61
|
7
|
+
data.tar.gz: 42b86588dd17f1904cda331c214a6a6f46d181a51aa0ee83689d225402dfcfe4c486f4f7d049621448e1fb7147c061148e41f861409f34656eb08dc2ce44e0f7
|
data/.gitignore
CHANGED
data/bin/argosnap
CHANGED
@@ -55,11 +55,11 @@ begin
|
|
55
55
|
if options[:notification] == 'mail'
|
56
56
|
Argosnap::Notifications.new.send_mail
|
57
57
|
elsif options[:notification] == 'pushover'
|
58
|
-
Argosnap::Notifications.new.
|
58
|
+
Argosnap::Notifications.new.send_pushover_notification
|
59
59
|
elsif options[:notification] == 'osx'
|
60
60
|
Argosnap::Notifications.new.send_osx_notification
|
61
61
|
elsif options[:notification] == 'osx_check'
|
62
|
-
Argosnap::Notifications.new.
|
62
|
+
Argosnap::Notifications.new.osx_check_and_notify
|
63
63
|
elsif options[:notification] == 'notify'
|
64
64
|
Argosnap::Notifications.new.notify
|
65
65
|
else
|
data/lib/argosnap/balance.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'mechanize'
|
2
2
|
|
3
|
+
# main module
|
3
4
|
module Argosnap
|
4
|
-
|
5
|
+
|
6
|
+
# Given username and a password, fetch balance from www.tarsnap.com
|
5
7
|
class Fetch
|
6
8
|
|
7
9
|
# Elementary configuration file check
|
@@ -16,23 +18,28 @@ module Argosnap
|
|
16
18
|
end
|
17
19
|
end
|
18
20
|
|
21
|
+
# check for login errors
|
22
|
+
def check_login_errors(data)
|
23
|
+
wrong_email_message = 'No user exists with the provided email address; please try again.'
|
24
|
+
wrong_password_message = 'Password is incorrect; please try again.'
|
25
|
+
if data.body.include?(wrong_email_message)
|
26
|
+
config.log_and_abort('Password is incorrect; please try again.')
|
27
|
+
elsif data.body.include?(wrong_password_message)
|
28
|
+
config.log_and_abort('Bad password. Please check your configuration file tarsnap password!')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
19
32
|
# Fetch balance from tarsnap using
|
20
33
|
def balance
|
21
34
|
check_configuration
|
22
35
|
agent = Mechanize.new
|
23
36
|
page = agent.get('https://www.tarsnap.com/account.html')
|
24
|
-
form = page.form_with(:
|
37
|
+
form = page.form_with(action: 'https://www.tarsnap.com/manage.cgi')
|
25
38
|
form.address = config.data[:email]
|
26
39
|
form.password = config.data[:password]
|
27
40
|
panel = agent.submit(form)
|
28
|
-
|
29
|
-
|
30
|
-
if panel.body.include?(wrong_email_message)
|
31
|
-
config.log_and_abort('Password is incorrect; please try again.')
|
32
|
-
elsif panel.body.include?(wrong_password_message)
|
33
|
-
config.log_and_abort('Bad password. Please check your configuration file tarsnap password!')
|
34
|
-
end
|
35
|
-
picodollars = panel.parser.to_s.scan(/\$\d+\.\d+/)[0].scan(/\d+\.\d+/)[0].to_f.round(4)
|
41
|
+
check_login_errors(panel)
|
42
|
+
picodollars = panel.parser.to_s.scan(/\$\d+\.\d+/)[0].scan(/\d+\.\d+/)[0].to_f.round(4)
|
36
43
|
config.logger.info("Current amount of picoUSD: #{picodollars}")
|
37
44
|
picodollars
|
38
45
|
end
|
data/lib/argosnap/config.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'logger'
|
3
3
|
|
4
|
+
# main module
|
4
5
|
module Argosnap
|
6
|
+
|
7
|
+
# Handle configuration files and create 'logger' object
|
5
8
|
class Configuration
|
6
|
-
|
9
|
+
|
10
|
+
# Configuration files hash
|
7
11
|
def files
|
8
12
|
{
|
9
13
|
config: "#{Dir.home}/.argosnap/config.yml",
|
@@ -12,17 +16,16 @@ module Argosnap
|
|
12
16
|
}
|
13
17
|
end
|
14
18
|
|
15
|
-
# logger object
|
19
|
+
# Create the logger object
|
16
20
|
def logger
|
17
21
|
Logger.new(files[:logfile], 10, 1024000)
|
18
22
|
end
|
19
23
|
|
20
|
-
#
|
24
|
+
# Load configuration data as a hash
|
21
25
|
def data
|
22
26
|
YAML::load_file(files[:config])
|
23
27
|
end
|
24
28
|
|
25
|
-
# Check if gem is available
|
26
29
|
def gem_available?(name)
|
27
30
|
Gem::Specification.find_by_name(name)
|
28
31
|
rescue Gem::LoadError
|
@@ -31,7 +34,6 @@ module Argosnap
|
|
31
34
|
Gem.available?(name)
|
32
35
|
end
|
33
36
|
|
34
|
-
# Log and Abort!
|
35
37
|
def log_and_abort(msg)
|
36
38
|
logger.error(msg)
|
37
39
|
Kernel.abort(msg)
|
data/lib/argosnap/helpers.rb
CHANGED
data/lib/argosnap/install.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
|
+
# main module
|
1
2
|
module Argosnap
|
3
|
+
|
4
|
+
# This class handles the available notifications
|
2
5
|
class Notifications
|
3
6
|
|
4
7
|
# When tarsnap balance is bellow threshold notify me
|
@@ -11,14 +14,12 @@ module Argosnap
|
|
11
14
|
end
|
12
15
|
end
|
13
16
|
|
14
|
-
|
15
|
-
def osx_check
|
17
|
+
def osx_check_and_notify
|
16
18
|
if config.data[:threshold] >= Fetch.new.balance
|
17
19
|
send_osx_notification
|
18
20
|
end
|
19
21
|
end
|
20
22
|
|
21
|
-
# send notification via email
|
22
23
|
def send_mail
|
23
24
|
if config.data[:notifications_email]
|
24
25
|
if config.gem_available?('mail')
|
@@ -32,8 +33,7 @@ module Argosnap
|
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
|
-
|
36
|
-
def send_pushover
|
36
|
+
def send_pushover_notification
|
37
37
|
if config.data[:notifications_pushover]
|
38
38
|
require "net/https"
|
39
39
|
require_relative File.expand_path("../notifications/pushover", __FILE__)
|
@@ -45,7 +45,7 @@ module Argosnap
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
# send notification to osx notifications (desktop)
|
48
|
+
# Manually send notification to osx notifications (desktop)
|
49
49
|
def send_osx_notification
|
50
50
|
if config.data[:notifications_osx]
|
51
51
|
if Gem::Platform.local.os == 'darwin'
|
data/lib/argosnap/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Argosnap do
|
4
|
+
before do
|
5
|
+
@balance = Argosnap::Fetch.new.balance
|
6
|
+
@threshold = Argosnap::Configuration.new.data[:threshold]
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'balance is a float' do
|
10
|
+
@balance.must_be_kind_of Float
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'threshold is a float' do
|
14
|
+
@threshold.must_be_kind_of (Fixnum || Float)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: argosnap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.4.
|
4
|
+
version: 0.0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Panagiotis Atmatzidis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- lib/argosnap/notifications/osxnotifications.rb
|
69
69
|
- lib/argosnap/notifications/pushover.rb
|
70
70
|
- lib/argosnap/version.rb
|
71
|
+
- test/lib/argosnap/balance_test.rb
|
71
72
|
- test/lib/argosnap/options_test.rb
|
72
73
|
- test/lib/argosnap/version_test.rb
|
73
74
|
- test/test_helper.rb
|
@@ -96,6 +97,7 @@ signing_key:
|
|
96
97
|
specification_version: 4
|
97
98
|
summary: Command line utility that displays your current tarsnap picoUSD amount.
|
98
99
|
test_files:
|
100
|
+
- test/lib/argosnap/balance_test.rb
|
99
101
|
- test/lib/argosnap/options_test.rb
|
100
102
|
- test/lib/argosnap/version_test.rb
|
101
103
|
- test/test_helper.rb
|