argosnap 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 58c0e9370c15fdbea9a88293750f435b115c448d
4
+ data.tar.gz: ebf0309dbbe124b0aa99ec8e283331f4dfafaba5
5
+ SHA512:
6
+ metadata.gz: 44019bb49bb27233a27157488c3e2d159b5b20bd381f3121f024c8446283e82965fe11d72c3e171a1d766e52c89b5ec34587307e7f7a7e06172112bc98d794da
7
+ data.tar.gz: 43ea9a9b559d741d336c1fa91ac65be6b74c1b48b37ece810cb5b293e82df1b8b96749b69597b4adf012fe0f6127dffc42f3897e57cab7a5e567ed34ebed81cc
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+ gem 'mechanize', '2.7.3'
3
+ gem 'terminal-notifier', '1.6.0'
4
+ gem 'plist', '3.1.0'
5
+
6
+ # Specify your gem's dependencies in argosnap.gemspec
7
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Panagiotis Atmatzidis
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,58 @@
1
+ # Argosnap
2
+
3
+ This gem allows you to displays your current amount of picodollars along with [OSX notifications](http://support.apple.com/kb/ht5362) when your [tarsnap account](http://www.tarsnap.com/) falls bellow a predefined threshold of [picodollars](http://www.tarsnap.com/picoUSD-why.html).
4
+
5
+ ## Installation
6
+
7
+ Install the gem via rubygems:
8
+
9
+ $ gem install argosnap plist mechanize terminal-notifier
10
+
11
+ ## Configure
12
+
13
+ Run `install` for the script to create the configuration file like:
14
+
15
+ $ argosnap -i config
16
+
17
+ Then we configure the `config.yml` file which looks like this:
18
+
19
+ ---
20
+ :email: sample@email.com
21
+ :password: p4sw0rd3
22
+ :threshold: 10
23
+ :seconds: 7200
24
+
25
+ Just put your tarsnap login credentials. You can omit the other two variables if you are not using an OSX system. To view your account use the command:
26
+
27
+ $ argosnap -p
28
+
29
+
30
+ ## Configure Launchd under MacOSX
31
+
32
+ In the `config.yml` adjust the `threshold` and `seconds` options as you see fit. Threshold is the amount of *picodollars* bellow which you'd like to start seeing notifications and the `seconds` consists of the time window. Then type:
33
+
34
+ $ argosnap -i cron
35
+
36
+ Now just start the installed `.plist` file and you're done.
37
+
38
+ ## Options
39
+
40
+ To run an osx notification use the command:
41
+
42
+ $ argosnap -p osx
43
+ Current balance (picodollars): 4.8812
44
+
45
+ To get the amount of picodollars as an integer type:
46
+
47
+ $ argosnap -p clean
48
+ 4.8812
49
+
50
+ That's all :-)
51
+
52
+ ## Contributing
53
+
54
+ 1. Fork it ( http://github.com/atmosx/argosnap/fork )
55
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
56
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
57
+ 4. Push to the branch (`git push origin my-new-feature`)
58
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require "bundler/gem_tasks"
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'lib/argosnap'
8
+ t.test_files = FileList['test/lib/argosnap/*_test.rb']
9
+ t.verbose = true
10
+ end
11
+
12
+ task :default => :test
data/argosnap.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'argosnap/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "argosnap"
8
+ spec.version = Argosnap::VERSION
9
+ spec.authors = ["Panagiotis Atmatzidis"]
10
+ spec.email = ["atma@convalesco.org"]
11
+ spec.summary = %q{Display osx notifications when tarsnap account runs out of picodollars}
12
+ spec.description = %q{A ruby script displays OSX notifications with current ballance. If the balance of picodollars falls bellow a specific threshold}
13
+ spec.homepage = "https://github.com/atmosx/argosnap"
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.5"
22
+ spec.add_development_dependency "rake"
23
+ end
data/bin/argosnap ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative File.expand_path('../../lib/argosnap', __FILE__)
3
+ require 'optparse'
4
+
5
+ options = {}
6
+
7
+ opt_parser = OptionParser.new do |opt|
8
+ opt.banner = "argosnap #{Argosnap::VERSION} ( https://github.com/atmosx/argosnap/ )\nUsage: argosnap [OPTIONS]"
9
+ opt.separator ""
10
+ opt.separator " version: dislay version"
11
+ opt.separator " install [config]: installs configure file 'config.yml'"
12
+ opt.separator " install [cron]: installs Launchd script under OSX"
13
+ opt.separator " print: prints the output in picodollars"
14
+ opt.separator " print [osx]: print osx notification"
15
+ opt.separator " print [clean]: prints only the picollars (float rounded in 4 decimals), to use in cli"
16
+ opt.separator ""
17
+
18
+ opt.on("-v","--version","display version") do |version|
19
+ options[:version] = version
20
+ end
21
+
22
+ opt.on("-i","--install [OPTION]", "install configuration files") do |install|
23
+ options[:install] = install || 'config'
24
+ end
25
+
26
+ opt.on("-p","--print [OPTION]","fetch current amount in picodollars") do |print|
27
+ options[:print] = print || 'default'
28
+ end
29
+
30
+ opt.on("-h","--help","help") do |h|
31
+ options[:help] = h
32
+ puts opt_parser
33
+ end
34
+ end
35
+
36
+ # Execution flow
37
+ begin
38
+ opt_parser.parse!
39
+ if options[:version]
40
+ puts Argosnap::VERSION
41
+ elsif options[:install]
42
+ if options[:install] == 'config'
43
+ Argosnap::Install.new.config
44
+ elsif options[:install] == 'cron'
45
+ Argosnap::OSXNotifications.new.install_launchd_script
46
+ end
47
+ elsif options[:help]
48
+ # do nothing - avoids double printing of 'opt_parser'
49
+ elsif options[:print]
50
+ if options[:print] == 'osx'
51
+ Argosnap::OSXNotifications.new.display
52
+ elsif options[:print] == 'default'
53
+ b = Argosnap::Fetch.new.balance
54
+ puts "Current balance (picodollars): #{b}"
55
+ elsif options[:print] == 'clean'
56
+ b = Argosnap::Fetch.new.balance
57
+ puts b
58
+ else
59
+ puts "Option not recognized"
60
+ end
61
+ else
62
+ puts opt_parser
63
+ end
64
+ rescue OptionParser::InvalidOption => e
65
+ puts "No such option! Type 'argosnap -h' for help!"
66
+ exit
67
+ end
data/files/local.sh ADDED
@@ -0,0 +1,15 @@
1
+ #!/bin/bash
2
+
3
+ # Load RVM into a shell session *as a function*
4
+ if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
5
+ # First try to load from a user install
6
+ source "$HOME/.rvm/scripts/rvm"
7
+ elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
8
+ # Then try to load from a root install
9
+ source "/usr/local/rvm/scripts/rvm"
10
+ else
11
+ printf "ERROR: An RVM installation was not found.\n"
12
+ fi
13
+
14
+ # Executable now should be in path
15
+ argosnap -p osx
@@ -0,0 +1,39 @@
1
+ require 'yaml'
2
+ require 'mechanize'
3
+ require 'logger'
4
+
5
+ module Argosnap
6
+ # Given a username and a password, fetch balance from http://www.tarsnap.com
7
+ class Fetch
8
+ def initialize
9
+ begin
10
+ user = ENV['USER']
11
+ raise ArgumentError.new("Please make sure you run 'asnap install' in order to install configuration files, before running asnap!") unless File.exists?("#{Dir.home}/.argosnap/config.yml")
12
+ r = YAML::load_file("#{Dir.home}/.argosnap/config.yml")
13
+ logfile = "#{Dir.home}/.argosnap/argosnap.log"
14
+ @email, @password, @threshold, @logger, @agent = r[:email], r[:password], r[:threshold], Logger.new(logfile), Mechanize.new
15
+ rescue ArgumentError => e
16
+ puts e.message
17
+ # puts e.backtrace
18
+ exit
19
+ end
20
+ end
21
+
22
+ # Fetch balance from tarsnap using mechanize
23
+ def balance
24
+ begin
25
+ page = @agent.get('https://www.tarsnap.com/account.html')
26
+ form = page.form_with(:action => 'https://www.tarsnap.com/manage.cgi')
27
+ form.address = @email
28
+ form.password = @password
29
+ panel = @agent.submit(form)
30
+ picodollars = panel.parser.to_s.scan(/\$\d+\.\d+/)[0].scan(/\d+\.\d+/)[0].to_f.round(4) # I'm the feeling that this can be done in a prettier way
31
+ @logger.info "Execution ended successfully! Picodollars: #{picodollars}"
32
+ picodollars
33
+ rescue Exception => e
34
+ @logger.error "A problem with tarsnap notification occured:"
35
+ @logger.error "#{e}"
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,22 @@
1
+ require 'logger'
2
+ require 'yaml'
3
+ require 'plist'
4
+
5
+ module Argosnap
6
+ class Install
7
+ # Install 'config.yml'
8
+ def config
9
+ url = 'http://atmosx.github.com/argosnap'
10
+ raise ArgumentError.new("This gem is made for UNIX! Please check the website for details #{url} !") unless %w{ darwin linux freebsd openbsd netbsd }.include? Gem::Platform.local.os
11
+ begin
12
+ Dir.mkdir(File.join(Dir.home, ".argosnap"), 0700) unless Dir.exists?("/Users/#{ENV['USER']}/.argosnap")# permissions are a-rwx,u+rwx
13
+ config = {email: 'tarsnap_email', password: 'tarsnap_password', threshold: 10, seconds: 7200}
14
+ File.open("#{Dir.home}/.argosnap/config.yml", "w") {|f| f.write(config.to_yaml)}
15
+ puts "1. Edit the configuration file: #{Dir.home}/.argosnap/config.yml"
16
+ puts "2. Launch argosnap by typing in the terminal: argosnap -p"
17
+ rescue Exception => e
18
+ puts e.message
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,53 @@
1
+ require 'terminal-notifier'
2
+ require_relative File.expand_path('../balance', __FILE__)
3
+ require 'yaml'
4
+
5
+ module Argosnap
6
+ class OSXNotifications
7
+ def initialize
8
+ begin
9
+ user = ENV['USER']
10
+ raise ArgumentError.new("This command is made for Darwin! Please check the website for details #{url} !") unless Gem::Platform.local.os == 'darwin'
11
+ r = YAML::load_file("#{Dir.home}/.argosnap/config.yml")
12
+ logfile = "#{Dir.home}/.argosnap/argosnap.log"
13
+ @threshold, @logger, @picodollars, @time_interval = r[:threshold], Logger.new(logfile), Argosnap::Fetch.new.balance, r[:seconds]
14
+ rescue ArgumentError => e
15
+ puts e.message
16
+ # puts e.backtrace
17
+ exit
18
+ end
19
+ end
20
+
21
+ # Creates launchd script with user's variables
22
+ def install_launchd_script
23
+ raise ArgumentError.new("Please make sure you run 'asnap install' in order to install configuration files, before running asnap!") unless File.exists?("#{Dir.home}/.argosnap/config.yml")
24
+ user = ENV['USER']
25
+ c = "#{Dir.home}/.argosnap/config.yml"
26
+ begin
27
+ launch_agents = "/Users/#{user}/Library/LaunchAgents/"
28
+ # start_script loads the RVM environment.
29
+ start_script = File.expand_path('../../../files/local.sh', __FILE__)
30
+ if Dir.exists?(launch_agents)
31
+ filename = "org.#{user}.argosnap.plist"
32
+ if File.exist?("#{launch_agents}#{filename}")
33
+ puts "Please delete file: #{launch_agents}#{filename} before proceeding!"
34
+ else
35
+ hash = {"Label"=>"#{filename.scan(/(.+)(?:\.[^.]+)/).flatten[0]}", "ProgramArguments"=>["#{start_script}"], "StartInterval"=> @time_interval, "RunAtLoad"=>true}
36
+ File.open("#{launch_agents}#{filename}", 'w') {|f| f.write(hash.to_plist)}
37
+ puts "Launchd script is installed. Type 'launchctl load -w #{launch_agents}#{filename}' to load the plist."
38
+ end
39
+ else
40
+ puts "No '#{launch_agents}' directory found! Aborting installation."
41
+ end
42
+ rescue Exception => e
43
+ puts e.message
44
+ # puts e.backtrace
45
+ end
46
+ end
47
+
48
+ # Display notifications
49
+ def display
50
+ TerminalNotifier.notify("Current balance: #{@picodollars}", :title => 'TarSnap', :subtitle => 'balance running out') if @picodollars < @threshold.to_i
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module Argosnap
2
+ VERSION = "0.0.2"
3
+ end
data/lib/argosnap.rb ADDED
@@ -0,0 +1,10 @@
1
+ # argosnap module
2
+
3
+ require_relative File.expand_path("../argosnap/version", __FILE__)
4
+ require_relative File.expand_path("../argosnap/install", __FILE__)
5
+ require_relative File.expand_path("../argosnap/balance", __FILE__)
6
+ require_relative File.expand_path("../argosnap/osxnotify", __FILE__)
7
+ # require 'argosnap/install'
8
+ # require 'argosnap/balance'
9
+ # require 'argosnap/version'
10
+ # require 'argosnap/osxnotify'
@@ -0,0 +1,7 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Argosnap do
4
+ it "return 'help' message" do
5
+
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Argosnap do
4
+ it "must be defined" do
5
+ Argosnap::VERSION.wont_be_nil
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/pride'
3
+ require File.expand_path('../../lib/argosnap.rb', __FILE__)
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: argosnap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Panagiotis Atmatzidis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-21 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: A ruby script displays OSX notifications with current ballance. If the
42
+ balance of picodollars falls bellow a specific threshold
43
+ email:
44
+ - atma@convalesco.org
45
+ executables:
46
+ - argosnap
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - argosnap.gemspec
56
+ - bin/argosnap
57
+ - files/local.sh
58
+ - lib/argosnap.rb
59
+ - lib/argosnap/balance.rb
60
+ - lib/argosnap/install.rb
61
+ - lib/argosnap/osxnotify.rb
62
+ - lib/argosnap/version.rb
63
+ - test/lib/argosnap/options_test.rb
64
+ - test/lib/argosnap/version_test.rb
65
+ - test/test_helper.rb
66
+ homepage: https://github.com/atmosx/argosnap
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.1.10
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Display osx notifications when tarsnap account runs out of picodollars
90
+ test_files:
91
+ - test/lib/argosnap/options_test.rb
92
+ - test/lib/argosnap/version_test.rb
93
+ - test/test_helper.rb