sendle 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/README +9 -0
- data/Rakefile +5 -0
- data/VERSION +1 -0
- data/bin/sendle +15 -0
- data/lib/sendle.rb +72 -0
- data/lib/sendle/version.rb +3 -0
- data/sendle.gemspec +29 -0
- metadata +101 -0
data/Gemfile
ADDED
data/README
ADDED
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.1
|
data/bin/sendle
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
3
|
+
|
4
|
+
require 'rb-fsevent'
|
5
|
+
require 'sendle'
|
6
|
+
|
7
|
+
password = nil
|
8
|
+
while(password.nil? || password.empty?)
|
9
|
+
puts 'Please, type your gmail password'
|
10
|
+
system 'stty -echo'
|
11
|
+
password = gets.strip
|
12
|
+
system 'stty echo'
|
13
|
+
end
|
14
|
+
puts 'starting...'
|
15
|
+
sendle = Sendle.new(password)
|
data/lib/sendle.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
require 'yaml'
|
3
|
+
require 'gmail'
|
4
|
+
|
5
|
+
class Sendle
|
6
|
+
attr_reader :last_event, :sha1_checksums_hash, :listener
|
7
|
+
|
8
|
+
def initialize(password)
|
9
|
+
@password = password
|
10
|
+
@sha1_checksums_hash = {}
|
11
|
+
@last_event = Time.now
|
12
|
+
|
13
|
+
configure_listener
|
14
|
+
end
|
15
|
+
|
16
|
+
def send_to_kindle(file)
|
17
|
+
@config ||= YAML::load(File.open("#{ENV['HOME']}/.sendle"))
|
18
|
+
gmail = Gmail.connect(@config["gmail"]["username"], @password)
|
19
|
+
message = gmail.message
|
20
|
+
message.to = @config["kindle"]["email"]
|
21
|
+
message.add_file file
|
22
|
+
message.deliver
|
23
|
+
puts "an email with #{file} is flying on the interwebz!"
|
24
|
+
end
|
25
|
+
|
26
|
+
def file_added(file)
|
27
|
+
puts "file changed: #{file}, sending now..."
|
28
|
+
send_to_kindle(file[0]) unless file.nil? || file.empty?
|
29
|
+
end
|
30
|
+
|
31
|
+
private # shameless copied from: https://github.com/guard/guard/blob/master/lib/guard/listener.rb#L35-63.
|
32
|
+
|
33
|
+
def configure_listener
|
34
|
+
@listener = FSEvent.new
|
35
|
+
@listener.watch Dir.pwd do |directories|
|
36
|
+
@last_event = Time.now
|
37
|
+
file_added(modified_files(directories))
|
38
|
+
end
|
39
|
+
@listener.run
|
40
|
+
end
|
41
|
+
|
42
|
+
def modified_files(dirs, options = {})
|
43
|
+
files = potentially_modified_files(dirs, options).select do |path|
|
44
|
+
File.file?(path) && file_modified?(path) && file_content_modified?(path)
|
45
|
+
end
|
46
|
+
files.map! { |file| file.gsub("#{Dir.pwd}/", '') }
|
47
|
+
end
|
48
|
+
|
49
|
+
def potentially_modified_files(dirs, options = {})
|
50
|
+
match = options[:all] ? "**/*" : "*"
|
51
|
+
Dir.glob(dirs.map { |dir| "#{dir}#{match}" })
|
52
|
+
end
|
53
|
+
|
54
|
+
def file_modified?(path)
|
55
|
+
# Depending on the filesystem, mtime is probably only precise to the second, so round
|
56
|
+
# both values down to the second for the comparison.
|
57
|
+
File.mtime(path).to_i >= last_event.to_i
|
58
|
+
rescue
|
59
|
+
false
|
60
|
+
end
|
61
|
+
|
62
|
+
def file_content_modified?(path)
|
63
|
+
sha1_checksum = Digest::SHA1.file(path).to_s
|
64
|
+
if sha1_checksums_hash[path] != sha1_checksum
|
65
|
+
@sha1_checksums_hash[path] = sha1_checksum
|
66
|
+
true
|
67
|
+
else
|
68
|
+
false
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
data/sendle.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib/', __FILE__)
|
3
|
+
$:.unshift lib unless $:.include?(lib)
|
4
|
+
|
5
|
+
require "sendle/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "sendle"
|
9
|
+
s.version = Sendle::VERSION
|
10
|
+
s.platform = Gem::Platform::RUBY
|
11
|
+
s.authors = ["Ricardo Valeriano"]
|
12
|
+
s.email = ["ricardo@backslashes.net"]
|
13
|
+
s.homepage = "https://github.com/ricardovaleriano/sendle"
|
14
|
+
s.summary = %q{A file system watcher to send new files to your kindle}
|
15
|
+
s.description = %q{A file system watcher to send new files to your kindle}
|
16
|
+
|
17
|
+
s.rubyforge_project = "sendle"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
|
24
|
+
s.executables = ['sendle']
|
25
|
+
|
26
|
+
s.add_runtime_dependency 'gmail', '>= 0.3.4'
|
27
|
+
s.add_runtime_dependency 'rb-fsevent', '>= 0'
|
28
|
+
end
|
29
|
+
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sendle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Ricardo Valeriano
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-05-26 00:00:00 -03:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: gmail
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 3
|
31
|
+
- 4
|
32
|
+
version: 0.3.4
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rb-fsevent
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 0
|
45
|
+
version: "0"
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
description: A file system watcher to send new files to your kindle
|
49
|
+
email:
|
50
|
+
- ricardo@backslashes.net
|
51
|
+
executables:
|
52
|
+
- sendle
|
53
|
+
extensions: []
|
54
|
+
|
55
|
+
extra_rdoc_files: []
|
56
|
+
|
57
|
+
files:
|
58
|
+
- .gitignore
|
59
|
+
- Gemfile
|
60
|
+
- Gemfile.lock
|
61
|
+
- README
|
62
|
+
- Rakefile
|
63
|
+
- VERSION
|
64
|
+
- bin/sendle
|
65
|
+
- lib/sendle.rb
|
66
|
+
- lib/sendle/version.rb
|
67
|
+
- sendle.gemspec
|
68
|
+
has_rdoc: true
|
69
|
+
homepage: https://github.com/ricardovaleriano/sendle
|
70
|
+
licenses: []
|
71
|
+
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
segments:
|
91
|
+
- 0
|
92
|
+
version: "0"
|
93
|
+
requirements: []
|
94
|
+
|
95
|
+
rubyforge_project: sendle
|
96
|
+
rubygems_version: 1.3.7
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: A file system watcher to send new files to your kindle
|
100
|
+
test_files: []
|
101
|
+
|