argosnap 0.0.4.2 → 0.0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cce8626211d00aa0d0330a8c6fd8e5d0db4bc0fd
4
- data.tar.gz: cff12a72214c7fef2af796067661429b7c5e8d2b
3
+ metadata.gz: 15e05625d1b29a1f605ceb9231c8834e19fb76a7
4
+ data.tar.gz: c2470b1958c344712af59df378155a392ab2bafb
5
5
  SHA512:
6
- metadata.gz: 7d3f867e5616740ee7cb4ac9e2b8c3cf1f972f38c73a9ccfe09eab808a5f3d76ca71e9a42c666a602a79ab93561a24344546b9961b847c541353891626c1510d
7
- data.tar.gz: ea90a440f7d48d92e051e05818884327323a97d5ffa91772811efd69e14701b9e3579137ec8cab82cf15f921b71b616732e68af3e51c7f1d500c6d1e6ab1974c
6
+ metadata.gz: 60c8ba297c156bc774093c11ab427176721cd349fca743aee64182d59208369e04ceb935432763e6f28217a79cbc3b7d8471c1ed2e596f6135fa7df294576e61
7
+ data.tar.gz: 42b86588dd17f1904cda331c214a6a6f46d181a51aa0ee83689d225402dfcfe4c486f4f7d049621448e1fb7147c061148e41f861409f34656eb08dc2ce44e0f7
data/.gitignore CHANGED
@@ -17,3 +17,4 @@ test/version_tmp
17
17
  tmp
18
18
  .DS_Store
19
19
  notes.txt
20
+ *syncthing*
@@ -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.send_pushover
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.osx_check
62
+ Argosnap::Notifications.new.osx_check_and_notify
63
63
  elsif options[:notification] == 'notify'
64
64
  Argosnap::Notifications.new.notify
65
65
  else
@@ -1,7 +1,9 @@
1
1
  require 'mechanize'
2
2
 
3
+ # main module
3
4
  module Argosnap
4
- # Given a username and a password, fetch balance from https://www.tarsnap.com
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(:action => 'https://www.tarsnap.com/manage.cgi')
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
- wrong_email_message = 'No user exists with the provided email address; please try again.'
29
- wrong_password_message = 'Password is incorrect; please try again.'
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
@@ -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
- # configuration files
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
- # Config data in hash
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)
@@ -1,3 +1,4 @@
1
+ # main module
1
2
  module Argosnap
2
3
 
3
4
  # Helper Class
@@ -1,7 +1,10 @@
1
+ # main module
1
2
  require 'fileutils'
2
3
 
3
4
  module Argosnap
4
5
 
6
+ # Install configuration and log files on the system.
7
+ # All program files to go '$HOME/.argosnap'
5
8
  class Install
6
9
 
7
10
  # Install configuration files in the system
@@ -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
- # Use with plist file
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
- # send notification via pushover.net
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'
@@ -1,4 +1,6 @@
1
1
  module Argosnap
2
+
3
+ # Send email notification to the user
2
4
  class Mailer
3
5
 
4
6
  # load configuration files
@@ -1,3 +1,4 @@
1
+ # main module
1
2
  module Argosnap
2
- VERSION = "0.0.4.2"
3
+ VERSION = "0.0.4.3"
3
4
  end
@@ -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
@@ -1,7 +1,5 @@
1
1
  require_relative '../../test_helper'
2
2
 
3
3
  describe Argosnap do
4
- it "return 'help' message" do
5
-
6
- end
4
+
7
5
  end
@@ -1,3 +1,4 @@
1
+ require 'minitest'
1
2
  require 'minitest/autorun'
2
3
  require 'minitest/pride'
3
4
  require File.expand_path('../../lib/argosnap.rb', __FILE__)
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.2
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-26 00:00:00.000000000 Z
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