kindlemail 0.2.7 → 0.2.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,9 @@
1
1
  # kindlemail Changelog
2
2
 
3
+ ### 0.2.8
4
+ * Added setup feature to setup the application
5
+ * Moved configuration to a new file
6
+
3
7
  ### 0.2.5
4
8
  * Upgrading to use gmail-mailer 0.4.5
5
9
 
data/README.md CHANGED
@@ -17,7 +17,16 @@ For kindlemail to work you will need three things
17
17
  * Anonymous OAUTH access to your gmail account
18
18
  * Your gmail address will need to be added to the "Your Kindle Approved E-mail List" on Amazon's "Manage Your Kindle" page
19
19
 
20
- ### How to run
20
+ ## How do I get OAUTH credentials for my gmail account?
21
+
22
+ * You will need python installed on your system
23
+ * Follow the instructions from google [located here](http://code.google.com/p/google-mail-xoauth-tools/wiki/XoauthDotPyRunThrough)
24
+
25
+ ## Why OAUTH, why can't I just put my password in?
26
+
27
+ * I don't like the idea of storing passwords, sorry!
28
+
29
+ ## How to run
21
30
  If you want to run kindlemail, do the following
22
31
 
23
32
  If you want the bleeding edge, clone this repository and...
@@ -25,14 +34,8 @@ If you want the bleeding edge, clone this repository and...
25
34
  or if you want a released gem...
26
35
  gem install kindlemail
27
36
 
28
- Run kindlemail to see if it's installed correctly
29
- kindlemail -i
30
-
31
- Modify the file and follow the instructions in the comments to add your gmail credentials
32
- vim ~/.kindlemail/.email_conf
33
-
34
- Modify the file and follow the instructions to add your kindle address
35
- vim ~/.kindlemail/.kindlemail
37
+ Run `setup` to setup kindlemail with your gmail credentials
38
+ kindlemail --setup
36
39
 
37
40
  Send a file to your Kindle!
38
41
  kindlemail ~/books/my_book.mobi
@@ -48,7 +51,7 @@ This is rough code and probably won't work.
48
51
 
49
52
  ## Options
50
53
 
51
- kindlemail 0.2.5. Written by djhworld. https://github.com/djhworld/kindlemail
54
+ kindlemail 0.2.8. Written by djhworld. https://github.com/djhworld/kindlemail
52
55
 
53
56
  kindlemail will send items to your kindle in the simplest possible manner
54
57
 
@@ -78,7 +81,7 @@ This is rough code and probably won't work.
78
81
  --force, -f: Send the file regardless of whether you have sent it before
79
82
  --show-history, -s: Show the history of files that have been sent using kindlemail
80
83
  --clear-history, -d: Clear the history of files that have been sent using kindlemail
84
+ --setup, -e: Setup kindlemail
81
85
  --show-info, -i: Show information about the way kindlemail is setup
82
86
  --version, -v: Print version and exit
83
87
  --help, -h: Show this message
84
-
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.7
1
+ 0.2.8
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{kindlemail}
8
- s.version = "0.2.7"
8
+ s.version = "0.2.8"
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"]
12
- s.date = %q{2011-01-17}
12
+ s.date = %q{2011-01-22}
13
13
  s.default_executable = %q{kindlemail}
14
14
  s.description = %q{Sends documents to a designated kindle address painlessly and via the CLI. No need to fumble around with clumsy attachment boxes so forth, just whack in the documents you want to send and hit enter}
15
15
  s.email = %q{djharperuk@gmail.com}
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
32
32
  "conf_templates/.email_conf",
33
33
  "conf_templates/.kindlemail",
34
34
  "kindlemail.gemspec",
35
+ "lib/Configuration.rb",
35
36
  "lib/KindleMail.rb",
36
37
  "lib/KindleMailFileDatastore.rb",
37
38
  "lib/KindleMailer.rb",
@@ -0,0 +1,93 @@
1
+ require 'yaml'
2
+ require 'constants.rb'
3
+ require 'fileutils'
4
+ class Configuration
5
+ def load_yaml(file)
6
+ YAML.load_file(file).inject({}){|memo,(k,v)| memo[k.to_sym] = v.to_s; memo}
7
+ end
8
+
9
+ # Create the user framework needed to run the application
10
+ def configuration_setup
11
+ dirname = File.expand_path(USER_DIR)
12
+ if !File.exists?(dirname)
13
+ Dir.mkdir(dirname)
14
+ create_storage_dir
15
+ create_staging_dir
16
+ create_user_conf_file
17
+ create_user_email_conf_file
18
+ else
19
+ create_user_conf_file if !File.exists?(USER_CONF_FILE)
20
+ create_storage_dir if !File.exists?(File.expand_path(STORAGE_DIR))
21
+ create_staging_dir if !File.exists?(File.expand_path(STAGING_DIR))
22
+ create_user_email_conf_file if !File.exists?(EMAIL_CONF_FILE)
23
+ end
24
+ end
25
+
26
+ def create_storage_dir
27
+ Dir.mkdir(File.expand_path(STORAGE_DIR))
28
+ end
29
+
30
+ def create_staging_dir
31
+ Dir.mkdir(File.expand_path(STAGING_DIR))
32
+ end
33
+
34
+ def create_user_conf_file
35
+ root = File.expand_path(File.dirname(__FILE__))
36
+ root = File.expand_path("../conf_templates", root)
37
+ FileUtils.cp(File.join(root, '/.kindlemail'), USER_CONF_FILE)
38
+ end
39
+
40
+ def create_user_email_conf_file
41
+ root = File.expand_path(File.dirname(__FILE__))
42
+ root = File.expand_path("../conf_templates", root)
43
+ FileUtils.cp(File.join(root, '/.email_conf'), EMAIL_CONF_FILE)
44
+ end
45
+
46
+ def set_default_kindle_address(address)
47
+ raise ArgumentError, "Error: No email address entered" if address.nil? or address.empty?
48
+
49
+ print "Setting up kindle credentials..."
50
+ File.open(USER_CONF_FILE,"w") do |file|
51
+ file.puts "kindle_addr: #{address}"
52
+ end
53
+ puts "Complete!"
54
+ end
55
+
56
+ def set_email_credentials(token, token_secret, email)
57
+ raise ArgumentError, "Error: Please provide a valid OAUTH token" if token.nil? or token.empty?
58
+ raise ArgumentError, "Error, Please provide a valid OAUTH token secret" if token_secret.nil? or token.empty?
59
+ raise ArgumentError, "Error: Please provide a valid gmail address" if email.nil? or email.empty?
60
+ print "Setting up email credentials..."
61
+ File.open(EMAIL_CONF_FILE, "w") do |file|
62
+ file.puts "smtp_oauth_token: #{token}"
63
+ file.puts "smtp_oauth_token_secret: #{token_secret}"
64
+ file.puts "email #{email}"
65
+ end
66
+ puts "Complete!"
67
+ end
68
+
69
+
70
+ def get_email_credentials
71
+ raise ArgumentError, "Cannot find email credentials file #{EMAIL_CONF_FILE}." if !File.exists?(EMAIL_CONF_FILE)
72
+ begin
73
+ load_yaml(EMAIL_CONF_FILE)
74
+ rescue
75
+ raise StandardError, "Error parsing #{EMAIL_CONF_FILE}"
76
+ end
77
+ end
78
+
79
+ def get_user_credentials
80
+ 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"
81
+
82
+ raise ArgumentError, "Cannot find user credentials file #{USER_CONF_FILE}." if !File.exists?(USER_CONF_FILE)
83
+ begin
84
+ config = load_yaml(USER_CONF_FILE)
85
+ rescue
86
+ raise StandardError, error_msg
87
+ end
88
+
89
+ raise StandardError, error_msg if config.key?(:kindle_addr) == false || config[:kindle_addr].nil?
90
+ return config
91
+ end
92
+ end
93
+
@@ -1,79 +1,10 @@
1
1
  require 'trollop'
2
- require 'yaml'
3
- require 'fileutils'
4
2
  require 'KindleMailer.rb'
5
3
  require 'constants.rb'
6
4
  require 'KindleMailFileDatastore.rb'
7
-
5
+ require 'Configuration.rb'
8
6
  # This contains all the code needed to run the CLI application
9
7
  module KindleMail
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
15
- # Create the user framework needed to run the application
16
- def configuration_setup
17
- dirname = File.expand_path(USER_DIR)
18
- if !File.exists?(dirname)
19
- Dir.mkdir(dirname)
20
- create_storage_dir
21
- create_staging_dir
22
- create_user_conf_file
23
- create_user_email_conf_file
24
- else
25
- create_user_conf_file if !File.exists?(USER_CONF_FILE)
26
- create_storage_dir if !File.exists?(File.expand_path(STORAGE_DIR))
27
- create_staging_dir if !File.exists?(File.expand_path(STAGING_DIR))
28
- create_user_email_conf_file if !File.exists?(EMAIL_CONF_FILE)
29
- end
30
- end
31
-
32
- def create_storage_dir
33
- Dir.mkdir(File.expand_path(STORAGE_DIR))
34
- end
35
-
36
- def create_staging_dir
37
- Dir.mkdir(File.expand_path(STAGING_DIR))
38
- end
39
-
40
- def create_user_conf_file
41
- root = File.expand_path(File.dirname(__FILE__))
42
- root = File.expand_path("../conf_templates", root)
43
- FileUtils.cp(File.join(root, '/.kindlemail'), USER_CONF_FILE)
44
- end
45
-
46
- def create_user_email_conf_file
47
- puts "Creating user email conf file"
48
- root = File.expand_path(File.dirname(__FILE__))
49
- root = File.expand_path("../conf_templates", root)
50
- FileUtils.cp(File.join(root, '/.email_conf'), EMAIL_CONF_FILE)
51
- end
52
-
53
- def get_email_credentials
54
- raise ArgumentError, "Cannot find email credentials file #{EMAIL_CONF_FILE}." if !File.exists?(EMAIL_CONF_FILE)
55
- begin
56
- load_yaml(EMAIL_CONF_FILE)
57
- rescue
58
- raise StandardError, "Error parsing #{EMAIL_CONF_FILE}"
59
- end
60
- end
61
-
62
- def get_user_credentials
63
- 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"
64
-
65
- raise ArgumentError, "Cannot find user credentials file #{USER_CONF_FILE}." if !File.exists?(USER_CONF_FILE)
66
- begin
67
- config = load_yaml(USER_CONF_FILE)
68
- rescue
69
- raise StandardError, error_msg
70
- end
71
-
72
- raise StandardError, error_msg if config.key?(:kindle_addr) == false || config[:kindle_addr].nil?
73
- return config
74
- end
75
- end
76
-
77
8
  class Application
78
9
  attr_reader :cmd_parser
79
10
  attr_reader :opts
@@ -81,7 +12,7 @@ module KindleMail
81
12
  def initialize
82
13
  puts "#{VERSION_STRING}\n\n"
83
14
  @datastore = KindleMailFileDatastore.new
84
- @config_manager = KindleMail::Configuration.new
15
+ @config_manager = Configuration.new
85
16
  @config_manager.configuration_setup
86
17
  end
87
18
 
@@ -108,12 +39,40 @@ module KindleMail
108
39
  opt :force, "Send the file regardless of whether you have sent it before", :short => "-f", :default => nil
109
40
  opt :show_history, "Show the history of files that have been sent using kindlemail", :short => "-s", :default => nil
110
41
  opt :clear_history, "Clear the history of files that have been sent using kindlemail", :short => "-d", :default => nil
42
+ opt :setup, "Setup kindlemail", :default => nil
111
43
  opt :show_info, "Show information about the way kindlemail is setup", :short => "-i", :default => nil
112
44
  end
113
45
  end
114
46
 
115
47
  def process
116
48
  begin
49
+
50
+ if(@opts[:setup_given])
51
+ hyphens = "-"*79
52
+ puts hyphens
53
+ puts "kindlemail setup"
54
+ puts "This will overwrite any settings you have set previously"
55
+ puts hyphens
56
+ print "Kindle address to set as your default address> "
57
+ @config_manager.set_default_kindle_address(gets.chomp.to_s)
58
+
59
+ puts
60
+ puts hyphens
61
+ puts "Gmail Authentication Settings"
62
+ puts "To get a valid anonymous token, use the instructions located here\nhttp://code.google.com/p/google-mail-xoauth-tools/wiki/XoauthDotPyRunThrough"
63
+ puts hyphens
64
+ print "OAUTH Token> "
65
+ token = gets.chomp.to_s
66
+ print "OAUTH Token Secret> "
67
+ token_secret = gets.chomp.to_s
68
+ print "Your gmail address> "
69
+ email = gets.chomp.to_s
70
+
71
+ @config_manager.set_email_credentials(token, token_secret, email)
72
+ puts "\n\nkindlemail setup complete"
73
+ exit
74
+ end
75
+
117
76
  if(@opts[:show_info_given])
118
77
  print_info
119
78
  exit
@@ -182,6 +141,7 @@ module KindleMail
182
141
  puts "Error occured: - \n#{message}"
183
142
  end
184
143
  end
144
+
185
145
  def print_info
186
146
  puts "kindlemail was born out of my own laziness. To put things bluntly"
187
147
  puts "I'm too lazy to pick up my beloved Kindle, get a usb cable, plug"
@@ -33,7 +33,9 @@ class KindleMailer
33
33
  rescue
34
34
  raise
35
35
  ensure
36
- FileUtils.rm(filepath) if(File.extname(filepath).eql?(".mobi"))
36
+ if(!filepath.nil? and File.exist?(filepath))
37
+ FileUtils.rm(filepath) if(File.extname(filepath).eql?(".mobi"))
38
+ end
37
39
  end
38
40
 
39
41
  puts "#{File.basename(file)} was successfully sent to #{@kindle_address}"
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 7
9
- version: 0.2.7
8
+ - 8
9
+ version: 0.2.8
10
10
  platform: ruby
11
11
  authors:
12
12
  - Daniel Harper
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-17 00:00:00 +00:00
17
+ date: 2011-01-22 00:00:00 +00:00
18
18
  default_executable: kindlemail
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -130,6 +130,7 @@ files:
130
130
  - conf_templates/.email_conf
131
131
  - conf_templates/.kindlemail
132
132
  - kindlemail.gemspec
133
+ - lib/Configuration.rb
133
134
  - lib/KindleMail.rb
134
135
  - lib/KindleMailFileDatastore.rb
135
136
  - lib/KindleMailer.rb
@@ -149,7 +150,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
149
150
  requirements:
150
151
  - - ">="
151
152
  - !ruby/object:Gem::Version
152
- hash: 2549843167680941989
153
+ hash: -1738991482516940866
153
154
  segments:
154
155
  - 0
155
156
  version: "0"