hoot 0.1.0 → 0.2.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 +4 -4
- data/Gemfile.lock +5 -1
- data/README.md +7 -5
- data/bin/hoot +56 -6
- data/hoot.gemspec +1 -0
- data/lib/hoot/client.rb +76 -23
- data/lib/hoot/keychain.rb +38 -0
- data/lib/hoot/user.rb +11 -65
- data/lib/hoot/version.rb +1 -1
- data/lib/hoot.rb +4 -3
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6fb0cf88115d0e25cb6c94222dbc960a610fb86
|
4
|
+
data.tar.gz: bc8b210c0f496b8405cfa7274ce211091d9157b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ee2b89c29e283fed65ce26616baf71ecc65d5c4f8686db26669be4b940f477f5ddc174dd6eb5395860bd22d3ee1deac1fe923ebd1346d544da29f9d643e59c5
|
7
|
+
data.tar.gz: 8c70ea6ad0a9ff04cc698948037ff754391ca942e44d555be274c9e4b55f650ef714f890ab34bc94636e74f4bf45990fdc8ff570e45fa7d67967f72ce817fcba
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
hoot (0.
|
4
|
+
hoot (0.2.0)
|
5
|
+
commander
|
5
6
|
json
|
6
7
|
netrc
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: https://rubygems.org/
|
10
11
|
specs:
|
12
|
+
commander (4.3.5)
|
13
|
+
highline (~> 1.7.2)
|
14
|
+
highline (1.7.3)
|
11
15
|
json (1.8.3)
|
12
16
|
netrc (0.10.3)
|
13
17
|
rake (10.4.2)
|
data/README.md
CHANGED
@@ -28,23 +28,25 @@ Hoot is not very fancy...
|
|
28
28
|
|
29
29
|
When you first install hoot, you will need to authenticate yourself using the email and password you used in the iOS app.
|
30
30
|
|
31
|
-
|
31
|
+
Execute `hoot login`, and you will be prompted to enter your credentials. To logout, `hoot logout` (you'll still have to remove all traces of Hoot form `~/.netrc`, though your hashed password and email are wiped).
|
32
32
|
|
33
33
|
To use, you can do something like the following,
|
34
34
|
|
35
35
|
sh my-long-process.sh && hoot
|
36
36
|
|
37
|
-
After your scraping tool/parser/long task has been completed, you'll get an alert on your phone.
|
37
|
+
After your scraping tool/parser/long task has been completed, you'll get an alert on your phone, such as the default message.
|
38
38
|
|
39
39
|
> Hoot! Your process has finished! Come back!
|
40
40
|
|
41
|
-
|
41
|
+
If you want to use a custom message, you can use a familiar `git` syntax.
|
42
|
+
|
43
|
+
hoot -m "Your custom message."
|
42
44
|
|
43
|
-
|
45
|
+
## Development
|
44
46
|
|
45
47
|
To add features, I'd recommend also using your own branch of `hedwig` ([ruddfawcett/hedwig](https://github.com/ruddfawcett/hedwig)). You can hack on Hoot with your local copy of Hedwig, and enable development mode using the following:
|
46
48
|
|
47
|
-
|
49
|
+
DEV=true hoot
|
48
50
|
|
49
51
|
## Contributing
|
50
52
|
|
data/bin/hoot
CHANGED
@@ -2,12 +2,62 @@
|
|
2
2
|
|
3
3
|
require 'hoot'
|
4
4
|
|
5
|
-
|
5
|
+
require 'commander/import'
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
HighLine.track_eof = false # Fix for built-in Ruby
|
8
|
+
# Signal.trap('INT') {} # Suppress backtrace when exiting command
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
program :version, Hoot::VERSION
|
11
|
+
program :description, 'This is Hoot! Hoot is a simple command line tool to alert you when a Terminal process has finished, with a push notification right to your device!'
|
12
|
+
|
13
|
+
program :help, 'Author', 'Rudd Fawcett <rudd.fawcett@gmail.com>'
|
14
|
+
program :help, 'Website', 'https://github.com/ruddfawcett'
|
15
|
+
program :help_formatter, :compact
|
16
|
+
|
17
|
+
never_trace!
|
18
|
+
default_command :push
|
19
|
+
|
20
|
+
command :login do |c|
|
21
|
+
c.syntax = 'hoot login'
|
22
|
+
c.description = 'Login into your Hoot account.'
|
23
|
+
|
24
|
+
c.example 'login', 'hoot login'
|
25
|
+
|
26
|
+
c.action do |args, options|
|
27
|
+
Hoot::User.login
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
command :logout do |c|
|
32
|
+
c.syntax = 'hoot logout'
|
33
|
+
c.description = 'Logout of your Hoot account.'
|
34
|
+
|
35
|
+
c.example 'logout', 'hoot logout'
|
36
|
+
|
37
|
+
c.action do |args, options|
|
38
|
+
Hoot::User.logout
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
command :push do |c|
|
43
|
+
c.syntax = 'hoot'
|
44
|
+
c.description = 'Send a push notification; or just use `hoot`!'
|
45
|
+
|
46
|
+
c.option '-m', '--message String', String, 'Send a notification with a custom message.'
|
47
|
+
c.example 'push', 'hoot -m "Custom message."'
|
48
|
+
|
49
|
+
c.action do |args, options|
|
50
|
+
unless Hoot::Keychain.authenticated?
|
51
|
+
abort('You must first login with `hoot login`.')
|
52
|
+
end
|
53
|
+
|
54
|
+
client.push(options.message)
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def client
|
62
|
+
Hoot::Client.new
|
13
63
|
end
|
data/hoot.gemspec
CHANGED
data/lib/hoot/client.rb
CHANGED
@@ -3,6 +3,7 @@ require 'net/https'
|
|
3
3
|
require 'uri'
|
4
4
|
|
5
5
|
module Hoot
|
6
|
+
|
6
7
|
unless ENV['DEV']
|
7
8
|
HEDWING_ENDPOINT = 'https://hedwig.herokuapp.com'
|
8
9
|
else
|
@@ -13,30 +14,58 @@ module Hoot
|
|
13
14
|
attr_accessor :hedwig
|
14
15
|
attr_accessor :credentials
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
def initialize
|
18
|
+
@hedwig = ENV['HEDWING_ENDPOINT'] || HEDWING_ENDPOINT
|
19
|
+
end
|
20
|
+
|
21
|
+
def push(message = nil)
|
22
|
+
@credentials = Hoot::Keychain::credentials
|
20
23
|
|
21
|
-
|
22
|
-
|
24
|
+
if message.nil?
|
25
|
+
message = 'Hoot! Your command has completed! Come back!'
|
26
|
+
end
|
23
27
|
|
24
|
-
|
25
|
-
|
28
|
+
data = {
|
29
|
+
:credentials => {
|
30
|
+
:email => @credentials[0],
|
31
|
+
:password => @credentials[1]
|
32
|
+
},
|
33
|
+
:message => message
|
34
|
+
}
|
26
35
|
|
27
|
-
|
28
|
-
|
29
|
-
|
36
|
+
response = request('send', data)
|
37
|
+
|
38
|
+
if response['result']
|
39
|
+
abort('A Hoot was sent to your device.')
|
40
|
+
end
|
30
41
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
42
|
+
abort('A server error occurred.')
|
43
|
+
end
|
44
|
+
|
45
|
+
def authenticate(credentials)
|
46
|
+
data = {
|
47
|
+
:credentials => {
|
48
|
+
:email => credentials[0],
|
49
|
+
:password => credentials[1]
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
response = request('authenticate', data)
|
54
|
+
|
55
|
+
if response['result']
|
56
|
+
Hoot::Keychain.save(credentials)
|
57
|
+
abort('Authentication successful.')
|
58
|
+
end
|
35
59
|
|
36
|
-
|
60
|
+
puts 'Authentication failed.'
|
37
61
|
|
38
|
-
|
39
|
-
|
62
|
+
Hoot::User::login
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def request(path, data)
|
68
|
+
uri = URI.parse(@hedwig)
|
40
69
|
http = Net::HTTP.new(uri.host, uri.port)
|
41
70
|
|
42
71
|
unless ENV['DEV']
|
@@ -44,12 +73,36 @@ module Hoot
|
|
44
73
|
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
45
74
|
end
|
46
75
|
|
47
|
-
|
76
|
+
data = encode(data)
|
77
|
+
|
78
|
+
request = Net::HTTP::Post.new("/api/v1/#{path}")
|
48
79
|
request.add_field('Content-Type', 'application/json')
|
49
|
-
request.set_form_data(
|
80
|
+
request.set_form_data(data)
|
50
81
|
response = http.request(request)
|
51
82
|
|
52
|
-
response
|
53
|
-
|
83
|
+
JSON.parse(response.body)
|
84
|
+
end
|
85
|
+
|
86
|
+
# http://dev.mensfeld.pl/2012/01/converting-nested-hash-into-http-url-params-hash-version-in-ruby/
|
87
|
+
|
88
|
+
def encode(value, key = nil, out_hash = {})
|
89
|
+
case value
|
90
|
+
when Hash then
|
91
|
+
value.each { |k,v| encode(v, append_key(key,k), out_hash) }
|
92
|
+
out_hash
|
93
|
+
when Array then
|
94
|
+
value.each { |v| encode(v, "#{key}[]", out_hash) }
|
95
|
+
out_hash
|
96
|
+
when nil then ''
|
97
|
+
else
|
98
|
+
out_hash[key] = value
|
99
|
+
out_hash
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def append_key(root_key, key)
|
104
|
+
root_key.nil? ? :"#{key}" : :"#{root_key}[#{key.to_s}]"
|
105
|
+
end
|
106
|
+
|
54
107
|
end
|
55
|
-
end
|
108
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'netrc'
|
2
|
+
require 'digest/sha1'
|
3
|
+
|
4
|
+
module Hoot
|
5
|
+
module Keychain
|
6
|
+
@n = Netrc.read
|
7
|
+
|
8
|
+
public
|
9
|
+
|
10
|
+
def self.authenticated?
|
11
|
+
login, password = @n['hedwig.herokuapp.com']
|
12
|
+
|
13
|
+
if (login.nil? || login == 0) || (password.nil? || password == 0)
|
14
|
+
return false
|
15
|
+
end
|
16
|
+
return true
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.credentials
|
20
|
+
if authenticated?
|
21
|
+
return @n['hedwig.herokuapp.com']
|
22
|
+
end
|
23
|
+
nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.save(credentials)
|
27
|
+
@n['hedwig.herokuapp.com'] = credentials[0], credentials[1]
|
28
|
+
@n.save
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.destroy
|
32
|
+
@n['hedwig.herokuapp.com'] = 0, 0
|
33
|
+
@n.save
|
34
|
+
abort('You were logged out.')
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
data/lib/hoot/user.rb
CHANGED
@@ -1,76 +1,22 @@
|
|
1
|
-
require '
|
2
|
-
require 'io/console'
|
3
|
-
require 'digest/sha1'
|
1
|
+
require 'commander/import'
|
4
2
|
|
5
3
|
module Hoot
|
6
4
|
module User
|
7
|
-
@
|
8
|
-
|
9
|
-
def self.isAuthenticated?
|
10
|
-
@n = Netrc.read
|
11
|
-
login, password = @n['hedwig.herokuapp.com']
|
5
|
+
@client = Hoot::Client.new
|
12
6
|
|
13
|
-
|
14
|
-
|
15
|
-
else
|
16
|
-
true
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.form
|
21
|
-
puts 'Please enter your Hoot credentials.'
|
22
|
-
|
23
|
-
print 'Email: '
|
24
|
-
login = gets.chomp
|
25
|
-
|
26
|
-
while login.length == 0
|
27
|
-
puts 'Please enter an email...'
|
28
|
-
print 'Email: '
|
29
|
-
login = gets.chomp
|
30
|
-
end
|
31
|
-
|
32
|
-
if STDIN.respond_to?(:noecho)
|
33
|
-
def self.get_password(prompt='Password: ')
|
34
|
-
print prompt
|
35
|
-
STDIN.noecho(&:gets).chomp
|
36
|
-
end
|
37
|
-
else
|
38
|
-
def self.get_password(prompt='Password: ')
|
39
|
-
`read -s -p '#{prompt}' password; echo $password`.chomp
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
password = self.get_password
|
7
|
+
def self.login
|
8
|
+
puts 'Enter your Hoot credentials.'
|
44
9
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
10
|
+
email = ask 'Email: '
|
11
|
+
password = Digest::SHA1.hexdigest(password 'Password: ', '*')
|
12
|
+
credentials = [email, password]
|
49
13
|
|
50
|
-
|
51
|
-
|
52
|
-
[login, password]
|
14
|
+
@client.authenticate(credentials)
|
53
15
|
end
|
54
16
|
|
55
|
-
|
56
|
-
|
57
|
-
credentials = self.form
|
58
|
-
|
59
|
-
@n['hedwig.herokuapp.com'] = credentials[0], credentials[1]
|
60
|
-
@n.save
|
61
|
-
|
62
|
-
puts
|
63
|
-
puts 'Your credentials have been saved.'
|
17
|
+
def self.logout
|
18
|
+
Hoot::Keychain.destroy
|
64
19
|
end
|
65
20
|
|
66
|
-
def self.credentials
|
67
|
-
if self.isAuthenticated?
|
68
|
-
login, password = @n['hedwig.herokuapp.com']
|
69
|
-
|
70
|
-
[login, password]
|
71
|
-
else
|
72
|
-
self.authenticate
|
73
|
-
end
|
74
|
-
end
|
75
21
|
end
|
76
|
-
end
|
22
|
+
end
|
data/lib/hoot/version.rb
CHANGED
data/lib/hoot.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'hoot/keychain'
|
2
|
+
require 'hoot/client'
|
3
|
+
require 'hoot/user'
|
4
|
+
require 'hoot/version'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hoot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rudd Fawcett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: netrc
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: commander
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: json
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,6 +96,7 @@ files:
|
|
82
96
|
- "./hoot.gemspec"
|
83
97
|
- "./lib/hoot.rb"
|
84
98
|
- "./lib/hoot/client.rb"
|
99
|
+
- "./lib/hoot/keychain.rb"
|
85
100
|
- "./lib/hoot/user.rb"
|
86
101
|
- "./lib/hoot/version.rb"
|
87
102
|
- bin/hoot
|