kindlemail 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,11 @@
1
1
  # kindlemail Changelog
2
2
 
3
+ ### 0.2.4
4
+ * Reconfigured KindleMail CLI to be more streamlined
5
+ * Added option to view default kindle address
6
+ * Added -i option
7
+ * Reconfigured configuration class for loading conf files
8
+
3
9
  ### 0.2.3
4
10
  * Added some further validations on the KindleMailer class
5
11
  * Restructured validations
data/TODO.txt CHANGED
@@ -1,10 +1,9 @@
1
- Changes needed for 0.1.4
1
+ Changes needed
2
2
  - Fix "user configuration invalid" message to mention the user can use the -k flag
3
3
  - Fix email configuration file issues?
4
4
 
5
5
  Future stuff: -
6
6
  - Start to think about moving the lib/ stuff out into a different gem and just seeing this as a pure CLI app?
7
- - Add flag to view default kindle address
8
7
  - Add ability to use multiple kindle addresses?
9
8
  - Add ability to add multiple attachments?
10
9
  - Add ability to pass in a web URL point to a file
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.3
1
+ 0.2.4
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{kindlemail}
8
- s.version = "0.2.3"
8
+ s.version = "0.2.4"
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"]
@@ -8,6 +8,10 @@ require 'KindleMailFileDatastore.rb'
8
8
  # This contains all the code needed to run the CLI application
9
9
  module KindleMail
10
10
  class Configuration
11
+
12
+ def load_yaml(file)
13
+ YAML.load_file(file).inject({}){|memo,(k,v)| memo[k.to_sym] = v.to_s; memo}
14
+ end
11
15
  # Create the user framework needed to run the application
12
16
  def configuration_setup
13
17
  dirname = File.expand_path(USER_DIR)
@@ -42,13 +46,39 @@ module KindleMail
42
46
 
43
47
  def get_email_credentials
44
48
  raise ArgumentError, "Cannot find email credentials file #{EMAIL_CONF_FILE}." if !File.exists?(EMAIL_CONF_FILE)
45
- YAML.load_file(EMAIL_CONF_FILE).inject({}){|memo,(k,v)| memo[k.to_sym] = v.to_s; memo}
49
+ begin
50
+ load_yaml(EMAIL_CONF_FILE)
51
+ rescue
52
+ raise StandardError, "Error parsing #{EMAIL_CONF_FILE}"
53
+ end
54
+ end
55
+
56
+ def get_user_credentials
57
+ error_msg = "The configuration file #{USER_CONF_FILE} was found but appears to be invalid/incomplete.\nThe most likely reason for this is the fact that you need to set a default kindle address to send items to.\nYou must edit the file and follow the instructions in the comments before trying again. Alternatively use the -k flag to specify a kindle address to send the item to"
58
+
59
+ raise ArgumentError, "Cannot find user credentials file #{USER_CONF_FILE}." if !File.exists?(USER_CONF_FILE)
60
+ begin
61
+ config = load_yaml(USER_CONF_FILE)
62
+ rescue
63
+ raise StandardError, error_msg
64
+ end
65
+
66
+ raise StandardError, error_msg if config.key?(:kindle_addr) == false || config[:kindle_addr].nil?
67
+ return config
46
68
  end
47
69
  end
48
70
 
49
71
  class Application
50
72
  attr_reader :cmd_parser
51
73
  attr_reader :opts
74
+
75
+ def initialize
76
+ puts "#{VERSION_STRING}\n\n"
77
+ @datastore = KindleMailFileDatastore.new
78
+ @config_manager = KindleMail::Configuration.new
79
+ @config_manager.configuration_setup
80
+ end
81
+
52
82
  def run
53
83
  setup
54
84
  process
@@ -72,19 +102,19 @@ module KindleMail
72
102
  opt :force, "Send the file regardless of whether you have sent it before", :short => "-f", :default => nil
73
103
  opt :show_history, "Show the history of files that have been sent using kindlemail", :short => "-s", :default => nil
74
104
  opt :clear_history, "Clear the history of files that have been sent using kindlemail", :short => "-d", :default => nil
105
+ opt :show_info, "Show information about the way kindlemail is setup", :short => "-i", :default => nil
75
106
  end
76
107
  end
77
108
 
78
109
  def process
79
110
  begin
80
- puts "\n#{VERSION_STRING}\n\n"
81
-
82
- datastore = KindleMailFileDatastore.new
83
- config_manager = KindleMail::Configuration.new
84
- config_manager.configuration_setup
111
+ if(@opts[:show_info_given])
112
+ print_info
113
+ exit
114
+ end
85
115
 
86
116
  if(@opts[:show_history_given])
87
- datastore.print_history
117
+ @datastore.print_history
88
118
  exit
89
119
  end
90
120
 
@@ -102,7 +132,7 @@ module KindleMail
102
132
 
103
133
  if(do_it)
104
134
  print "Clearing file history"
105
- datastore.clear_history
135
+ @datastore.clear_history
106
136
  puts "...done"
107
137
  end
108
138
  exit
@@ -112,15 +142,13 @@ module KindleMail
112
142
  raise ArgumentError, "Please specify a file to send (or use the -h option to see help)"
113
143
  end
114
144
 
115
- mailer = KindleMailer.new(config_manager.get_email_credentials)
116
-
117
- kindle_address = ""
145
+ mailer = KindleMailer.new(@config_manager.get_email_credentials)
118
146
 
147
+ kindle_address = ""
119
148
  if(!@opts[:kindle_address_given])
120
149
  # no -k flag specified, see if a configuration file has been set
121
150
  if(File.exist?(USER_CONF_FILE))
122
- config = YAML.load_file(USER_CONF_FILE).inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
123
- raise ArgumentError, "The configuration file #{USER_CONF_FILE} was found but appears to be invalid/incomplete.\nThe most likely reason for this is the fact that you need to set a default kindle address to send items to.\nYou must edit the file and follow the instructions in the comments before trying again. Alternatively use the -k flag to specify a kindle address to send the item to" if config.key?(:kindle_addr) == false || config[:kindle_addr].nil?
151
+ config = @config_manager.get_user_credentials
124
152
  kindle_address = config[:kindle_addr]
125
153
  else
126
154
  raise ArgumentError, "No address has been specified to send the item to.\nEither add an address in #{USER_CONF_FILE} or use the -kindle_address (-k) option"
@@ -134,18 +162,49 @@ module KindleMail
134
162
  file_to_send = ARGV[0]
135
163
 
136
164
  if(!force_send)
137
- if(datastore.file_exists?(kindle_address, File.basename(file_to_send)))
165
+ if(@datastore.file_exists?(kindle_address, File.basename(file_to_send)))
138
166
  raise ArgumentError, "This file has already been sent to #{kindle_address}. Use the --force (-f) option if you want to resend it"
139
167
  end
140
168
  end
141
169
 
142
170
  send_result = mailer.send(kindle_address, file_to_send)
143
- datastore.add_entry(kindle_address,File.basename(file_to_send)) if send_result
171
+ @datastore.add_entry(kindle_address,File.basename(file_to_send)) if send_result
144
172
 
145
173
  rescue ArgumentError => message
146
174
  puts "#{message}"
175
+ rescue => message
176
+ puts "Error occured: - \n#{message}"
147
177
  end
178
+ end
179
+ def print_info
180
+ puts "kindlemail was born out of my own laziness. To put things bluntly"
181
+ puts "I'm too lazy to pick up my beloved Kindle, get a usb cable, plug"
182
+ puts "it into my computer, drag and drop books and documents to it,"
183
+ puts "unplug the usb cable. Too ardous and involves getting up."
184
+ puts
185
+ puts "So I wrote this, it's simple, a bit rubbish, probably doesn't work"
186
+ puts "properly but it's useful when I just want to fire off a .mobi book"
187
+ puts "to my Kindle and forget about it until later."
188
+ puts
189
+ puts "Amazon have made a great service with the Personal Document Service,"
190
+ puts "although it's worth reminding users of the 3G Kindle that they will"
191
+ puts "be charged for using this service"
192
+ puts
193
+ puts "If you hate this application, supress your hatred and tell me what"
194
+ puts "you hate about it so I can change it"
195
+ puts
196
+ puts "Version: #{VERSION}"
197
+ puts "Homepage: #{HOMEPAGE}"
198
+ puts "Author: #{AUTHOR}"
199
+ puts
148
200
 
201
+ begin
202
+ config = @config_manager.get_user_credentials
203
+ rescue
204
+ puts "You do not appear to have a valid user credentials file!"
205
+ else
206
+ puts "Default kindle address: #{config[:kindle_addr]}\n\n"
207
+ end
149
208
  end
150
209
  end
151
210
  end
@@ -17,7 +17,9 @@ 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.3"
21
- VERSION_STRING = "kindlemail #{VERSION} (January 2011). https://github.com/djhworld/kindlemail"
20
+ VERSION = "0.2.4"
21
+ HOMEPAGE = "https://github.com/djhworld/kindlemail"
22
+ AUTHOR = "djhworld"
23
+ VERSION_STRING = "kindlemail #{VERSION}. Written by #{AUTHOR}. #{HOMEPAGE}"
22
24
  FILE_STORE = File.expand_path(STORAGE_DIR + "/sent_files.history")
23
25
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 3
9
- version: 0.2.3
8
+ - 4
9
+ version: 0.2.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Harper