kindlemail 0.2.1 → 0.2.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.
- data/Changelog.md +5 -0
- data/Rakefile +7 -0
- data/TODO.txt +1 -0
- data/VERSION +1 -1
- data/kindlemail.gemspec +6 -2
- data/lib/KindleMailer.rb +21 -7
- data/lib/constants.rb +1 -1
- data/test/test_kindle_mailer.rb +43 -0
- metadata +5 -4
data/Changelog.md
CHANGED
data/Rakefile
CHANGED
@@ -24,4 +24,11 @@ Jeweler::Tasks.new do |gem|
|
|
24
24
|
gem.add_dependency "trollop", "~> 1.16.2"
|
25
25
|
end
|
26
26
|
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
require 'rake/testtask'
|
28
|
+
Rake::TestTask.new(:test) do |test|
|
29
|
+
test.libs << 'lib' << 'test'
|
30
|
+
test.pattern = 'test/**/test_*.rb'
|
31
|
+
test.verbose = true
|
32
|
+
end
|
27
33
|
|
34
|
+
task :default => :test
|
data/TODO.txt
CHANGED
@@ -3,6 +3,7 @@ Changes needed for 0.1.4
|
|
3
3
|
- Fix email configuration file issues?
|
4
4
|
|
5
5
|
Future stuff: -
|
6
|
+
- Start to think about moving the lib/ stuff out into a different gem and just seeing this as a pure CLI app?
|
6
7
|
- Add flag to view default kindle address
|
7
8
|
- Add ability to use multiple kindle addresses?
|
8
9
|
- Add ability to add multiple attachments?
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/kindlemail.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{kindlemail}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Daniel Harper"]
|
@@ -35,7 +35,8 @@ Gem::Specification.new do |s|
|
|
35
35
|
"lib/KindleMail.rb",
|
36
36
|
"lib/KindleMailFileDatastore.rb",
|
37
37
|
"lib/KindleMailer.rb",
|
38
|
-
"lib/constants.rb"
|
38
|
+
"lib/constants.rb",
|
39
|
+
"test/test_kindle_mailer.rb"
|
39
40
|
]
|
40
41
|
s.homepage = %q{http://github.com/djhworld/kindlemail}
|
41
42
|
s.licenses = ["MIT"]
|
@@ -43,6 +44,9 @@ Gem::Specification.new do |s|
|
|
43
44
|
s.required_ruby_version = Gem::Requirement.new(">= 1.9.2")
|
44
45
|
s.rubygems_version = %q{1.3.7}
|
45
46
|
s.summary = %q{Push documents to your kindle via the personal document service}
|
47
|
+
s.test_files = [
|
48
|
+
"test/test_kindle_mailer.rb"
|
49
|
+
]
|
46
50
|
|
47
51
|
if s.respond_to? :specification_version then
|
48
52
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
data/lib/KindleMailer.rb
CHANGED
@@ -4,28 +4,42 @@ class KindleMailer
|
|
4
4
|
attr_accessor :kindle_address
|
5
5
|
attr_accessor :email_credentials
|
6
6
|
def initialize(email_credentials)
|
7
|
+
raise ArgumentError, "You must supply email credentials to use KindleMailer" if email_credentials.nil?
|
7
8
|
@email_credentials = email_credentials
|
8
9
|
end
|
9
10
|
|
10
11
|
def send(kindle_address, file)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
raise ArgumentError, "The file you have specified is not a valid type #{SEE_HELP}" if VALID_FILE_TYPES.include?(File.extname(file)) == false
|
12
|
+
begin
|
13
|
+
validate_kindle_address(kindle_address)
|
14
|
+
@kindle_address = kindle_address
|
15
15
|
|
16
|
-
|
16
|
+
filepath = File.expand_path(file)
|
17
|
+
validate_file_path(filepath)
|
18
|
+
|
19
|
+
puts "Preparing #{File.basename(filepath)} to be sent to #{@kindle_address}"
|
17
20
|
|
18
|
-
begin
|
19
21
|
message = GmailMailer::Message.new(@kindle_address)
|
20
22
|
message.add_attachment(filepath)
|
21
23
|
|
22
24
|
mailer = GmailMailer::Mailer.new(@email_credentials)
|
23
25
|
mailer.send(message)
|
24
|
-
rescue
|
26
|
+
rescue
|
25
27
|
raise
|
26
28
|
end
|
27
29
|
|
28
30
|
puts "#{File.basename(filepath)} was successfully sent to #{@kindle_address}"
|
29
31
|
return true
|
30
32
|
end
|
33
|
+
|
34
|
+
def validate_file_path(filepath)
|
35
|
+
raise ArgumentError, "The file you have specified does not exist #{SEE_HELP}" if filepath.nil? || !File.exist?(filepath)
|
36
|
+
raise ArgumentError, "The file you have specified is not a valid type #{SEE_HELP}" if VALID_FILE_TYPES.include?(File.extname(filepath)) == false
|
37
|
+
return true
|
38
|
+
end
|
39
|
+
|
40
|
+
def validate_kindle_address(addr)
|
41
|
+
raise ArgumentError, "You must supply an address to send this item to" if addr.nil?
|
42
|
+
raise ArgumentError, "#{addr} does not appear to be a valid kindle address" if !addr.end_with?("@kindle.com")
|
43
|
+
return true
|
44
|
+
end
|
31
45
|
end
|
data/lib/constants.rb
CHANGED
@@ -17,7 +17,7 @@ USER_DIR = "~/.kindlemail"
|
|
17
17
|
STORAGE_DIR = USER_DIR + "/.storage"
|
18
18
|
EMAIL_CONF_FILE = File.expand_path(USER_DIR + "/.email_conf")
|
19
19
|
USER_CONF_FILE = File.expand_path(USER_DIR + "/.kindlemail")
|
20
|
-
VERSION = "0.2.
|
20
|
+
VERSION = "0.2.3"
|
21
21
|
VERSION_STRING = "kindlemail #{VERSION} (January 2011). https://github.com/djhworld/kindlemail"
|
22
22
|
FILE_STORE = File.expand_path(STORAGE_DIR + "/sent_files.history")
|
23
23
|
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'KindleMailer.rb'
|
4
|
+
class TestKindleMailer < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@mailer = KindleMailer.new({})
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_constructor_with_nil_credentials
|
11
|
+
assert_raise(ArgumentError) { @mailer = KindleMailer.new(nil) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_send_with_nil_kindle_address
|
15
|
+
assert_raise(ArgumentError) { @mailer.send(nil, "file") }
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_validate_kindle_address_with_nil_addr
|
19
|
+
assert_raise(ArgumentError) { @mailer.validate_kindle_address(nil) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_validate_kindle_address_with_non_kindle_addr
|
23
|
+
assert_raise(ArgumentError) { @mailer.validate_kindle_address("kindlemail@gmail.com") }
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_validate_file_path_with_non_existent_file
|
27
|
+
assert_raise(ArgumentError) { @mailer.validate_file_path("k") }
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_validate_file_path_with_existent_file
|
31
|
+
file = File.expand_path("test/file1.txt")
|
32
|
+
FileUtils.touch(file)
|
33
|
+
assert_nothing_raised { @mailer.validate_file_path(file) }
|
34
|
+
FileUtils.rm(file)
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_validate_file_path_with_erroneous_file_type
|
38
|
+
file = File.expand_path("test/file1.xyz")
|
39
|
+
FileUtils.touch(file)
|
40
|
+
assert_raise(ArgumentError) { @mailer.validate_file_path(file) }
|
41
|
+
FileUtils.rm(file)
|
42
|
+
end
|
43
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
version: 0.2.
|
8
|
+
- 3
|
9
|
+
version: 0.2.3
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Daniel Harper
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- lib/KindleMailFileDatastore.rb
|
135
135
|
- lib/KindleMailer.rb
|
136
136
|
- lib/constants.rb
|
137
|
+
- test/test_kindle_mailer.rb
|
137
138
|
has_rdoc: true
|
138
139
|
homepage: http://github.com/djhworld/kindlemail
|
139
140
|
licenses:
|
@@ -168,5 +169,5 @@ rubygems_version: 1.3.7
|
|
168
169
|
signing_key:
|
169
170
|
specification_version: 3
|
170
171
|
summary: Push documents to your kindle via the personal document service
|
171
|
-
test_files:
|
172
|
-
|
172
|
+
test_files:
|
173
|
+
- test/test_kindle_mailer.rb
|