redimap 0.3.1 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f66ce4ef01d017b2f398fd4c5dea85f590623675
4
- data.tar.gz: c78b41faf48bf785ee65264d26863cc86416a439
3
+ metadata.gz: 8ba76df09385c366a60e9b398d4b4609a26aa651
4
+ data.tar.gz: 7c513536095b241ea1614e84efb333c26845bc4f
5
5
  SHA512:
6
- metadata.gz: 55bb403a6af33ac2c787a41724b8f4d3a03e766d0a8026ee0785a7df3a647337bf52a3fd2d05414a36f318fe249044018cea80dc58b49b135f2730721ad0e823
7
- data.tar.gz: 547e2b9b42784d7f5055ee7ebf578ed90bf24ddb05c99e21389e47cb7355184236d0b3347db58cf83df8996ed74fa81da30ee590bbd30a1eacdb04d1fb67ea9b
6
+ metadata.gz: e9d01fb5a28bba8e1df681f42708550e7af1d76ff1ebafd15a8ee77f4af14220e149e8427f5f0b29f9d183023fa95caf259d9d475fbf0c182817a0c2ee478583
7
+ data.tar.gz: 0da97e1f2f3328fdbec7d8cb4b678c3ef01a25a5249fc289dc5d5cd0ffc72ecc19d34935f2ff7f76742a15e969412aec33ba1b28c95b8ea323b43b541406f399
data/README.md CHANGED
@@ -18,21 +18,17 @@ Install using:
18
18
 
19
19
  ## Usage
20
20
 
21
- Ensure that you are setting the required environment variables, perhaps using
22
- Foreman. You'll probably want to at least set:
21
+ View the available options:
23
22
 
24
- IMAP_HOST=imap.gmail.com
25
- IMAP_USERNAME=username@example.com
26
- IMAP_PASSWORD=ssssshhhhhhh
27
- IMAP_MAILBOXES=["INBOX","Sent"]
23
+ $ bundle exec redimap --help
28
24
 
29
- Check and queue new messages and quit:
25
+ Most settings have defaults, but it is necessary to at least set up IMAP.
30
26
 
31
- $ bundle exec redimap
27
+ Check and queue new messages and quit:
32
28
 
33
- Check and queue new messages but run for eternity:
29
+ $ bundle exec redimap --host mail.example.com --user a@example.com --password helpimacarrot
34
30
 
35
- $ bundle exec redimap --eternal
31
+ Use `--eternal` to run eternally.
36
32
 
37
33
 
38
34
  ## Contributions
data/bin/redimap CHANGED
@@ -6,8 +6,6 @@ require 'optparse'
6
6
 
7
7
  require File.expand_path(File.dirname(__FILE__) + '/../lib/redimap')
8
8
 
9
- @logger = Redimap.logger
10
-
11
9
 
12
10
  # = Parse opts
13
11
 
@@ -16,12 +14,96 @@ options = {}
16
14
  OptionParser.new do |opts|
17
15
  opts.banner = "Usage: redimap [options]"
18
16
 
19
- opts.on("-e", "--eternal", "Run eternally") do |e|
20
- options[:eternal] = true
17
+ opts.separator ""
18
+ opts.separator "Polling:"
19
+
20
+ opts.on("-e", "--[no-]eternal", "Run eternally") do |o|
21
+ options[:eternal] = o
22
+ end
23
+
24
+ opts.on("--polling-interval [N]", "Poll every N seconds when --eternal") do |o|
25
+ options[:polling_interval] = o
26
+ end
27
+
28
+ opts.separator ""
29
+ opts.separator "IMAP:"
30
+
31
+ opts.on("-h", "--imap-host HOST", "Connect IMAP with HOST") do |o|
32
+ options[:imap_host] = o
33
+ end
34
+
35
+ opts.on("--imap-port [PORT]", Integer, "Connect IMAP with PORT") do |o|
36
+ options[:imap_port] = o
37
+ end
38
+
39
+ opts.on("-u", "--imap-username USERNAME", "Connect IMAP with USERNAME") do |o|
40
+ options[:imap_username] = o
41
+ end
42
+
43
+ opts.on("-p", "--imap-password PASSWORD", "Connect IMAP with PASSWORD") do |o|
44
+ options[:imap_password] = o
45
+ end
46
+
47
+ opts.on("--imap-mailboxes [INBOX,IN]", Array, "Read IMAP MAILBOXES") do |o|
48
+ options[:imap_mailboxes] = o
49
+ end
50
+
51
+ opts.separator ""
52
+ opts.separator "Redis:"
53
+
54
+ opts.on("--redis-url [URL]", "Connect Redis to URL") do |o|
55
+ options[:redis_url] = o
56
+ end
57
+
58
+ opts.on("--redis-ns-redimap [NS]", "Namespace Redis 'redimap:' as NS") do |o|
59
+ options[:redis_ns_redimap] = o
60
+ end
61
+
62
+ opts.on("--redis-ns-queue [NS]", "Namespace Redis 'resque:' as NS") do |o|
63
+ options[:redis_ns_queue] = o
64
+ end
65
+
66
+ opts.separator ""
67
+ opts.separator "Other:"
68
+
69
+ opts.on("-v", "--[no-]verbose", "Be somewhat verbose") do |o|
70
+ options[:verbose] = o
71
+ end
72
+
73
+ opts.on_tail("--help", "Show this message") do
74
+ puts opts
75
+ exit
76
+ end
77
+
78
+ opts.on_tail("--version", "Show version") do
79
+ puts "Redimap version:#{Redimap::VERSION}"
80
+ exit
21
81
  end
22
82
  end.parse!
23
83
 
24
84
 
85
+ # = Configure
86
+
87
+ Redimap.configure do |c|
88
+ c.log_level = 'DEBUG' if options[:verbose]
89
+
90
+ c.imap_host = options[:imap_host] if options[:imap_host]
91
+ c.imap_port = options[:imap_port] if options[:imap_port]
92
+ c.imap_username = options[:imap_username] if options[:imap_username]
93
+ c.imap_password = options[:imap_password] if options[:imap_password]
94
+
95
+ c.imap_mailboxes = options[:imap_mailboxes] if options[:imap_mailboxes]
96
+
97
+ c.redis_url = options[:redis_url] if options[:redis_url]
98
+ c.redis_ns_redimap = options[:redis_ns_redimap] if options[:redis_ns_redimap]
99
+ c.redis_ns_queue = options[:redis_ns_queue] if options[:redis_ns_queue]
100
+
101
+ c.polling_interval = options[:polling_interval] if options[:polling_interval]
102
+ end
103
+
104
+ @logger = Redimap.logger
105
+
106
+
25
107
  # = Main loop
26
108
 
27
109
  loop do
data/lib/redimap/base.rb CHANGED
@@ -9,13 +9,15 @@ module Redimap
9
9
 
10
10
  def self.configure
11
11
  yield self.config
12
+
13
+ Redimap.logger.debug { "Configured #{Redimap.config.to_s}" }
12
14
  end
13
15
 
14
16
  def self.logger
15
17
  unless @logger
16
18
  @logger = Logger.new($stdout)
17
19
 
18
- @logger.level = Logger.const_get(ENV['LOG_LEVEL'] || 'INFO')
20
+ @logger.level = Logger.const_get(Redimap.config.log_level)
19
21
  @logger.progname = :Redimap
20
22
  end
21
23
 
@@ -4,6 +4,8 @@ require 'json'
4
4
  module Redimap
5
5
  class Config
6
6
 
7
+ attr_accessor :log_level
8
+
7
9
  attr_accessor :imap_host
8
10
  attr_accessor :imap_port
9
11
  attr_accessor :imap_username
@@ -18,26 +20,23 @@ module Redimap
18
20
  attr_accessor :polling_interval
19
21
 
20
22
  def initialize
21
- @logger = Redimap.logger
22
-
23
- @imap_host = ENV['IMAP_HOST']
24
- @imap_port = ENV['IMAP_PORT'] || 993
25
- @imap_username = ENV['IMAP_USERNAME']
26
- @imap_password = ENV['IMAP_PASSWORD']
23
+ @log_level = 'INFO'
27
24
 
28
- @imap_mailboxes = JSON.parse(ENV['IMAP_MAILBOXES'] || '["INBOX"]')
25
+ @imap_port = 993
29
26
 
30
- @redis_url = ENV['REDIS_URL'] || "redis://127.0.0.1:6379/0"
31
- @redis_ns_redimap = ENV['REDIS_NS_REDIMAP'] || "redimap"
32
- @redis_ns_queue = ENV['REDIS_NS_QUEUE'] || "resque"
27
+ @imap_mailboxes = ['INBOX']
33
28
 
34
- @polling_interval = (ENV['POLLING_INTERVAL'] || 60).to_i
29
+ @redis_url = 'redis://127.0.0.1:6379/0'
30
+ @redis_ns_redimap = 'redimap'
31
+ @redis_ns_queue = 'resque'
35
32
 
36
- @logger.debug { "Initialized #{to_s}" }
33
+ @polling_interval = 60
37
34
  end
38
35
 
39
36
  def to_s
40
37
  {
38
+ :log_level => @log_level,
39
+
41
40
  :imap_host => @imap_host,
42
41
  :imap_port => @imap_port,
43
42
  :imap_username => @imap_username,
@@ -1,5 +1,5 @@
1
1
  module Redimap
2
2
 
3
- VERSION = "0.3.1"
3
+ VERSION = "0.4.0"
4
4
 
5
5
  end
data/lib/redimap.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require_relative 'redimap/version'
1
2
  require_relative 'redimap/config'
2
3
  require_relative 'redimap/base'
3
4
  require_relative 'redimap/imap_conn'
@@ -4,86 +4,93 @@ require 'spec_helper'
4
4
  describe Redimap::Config do
5
5
 
6
6
  context "Defaults" do
7
- before(:each) do
8
- ENV.stub(:[])
9
-
10
- @config = Redimap::Config.new
7
+ it "log_level should default to INFO" do
8
+ Redimap.config.log_level.should == "INFO"
11
9
  end
12
10
 
13
11
  it "imap_port should default to 993" do
14
- @config.imap_port.should == 993
12
+ Redimap.config.imap_port.should == 993
15
13
  end
16
14
 
17
15
  it "imap_mailboxes should default to [INBOX]" do
18
- @config.imap_mailboxes.should == ['INBOX']
16
+ Redimap.config.imap_mailboxes.should == ['INBOX']
19
17
  end
20
18
 
21
19
  it "redis_url should default to redis://127.0.0.1:6379/0" do
22
- @config.redis_url.should == "redis://127.0.0.1:6379/0"
20
+ Redimap.config.redis_url.should == "redis://127.0.0.1:6379/0"
23
21
  end
24
22
 
25
23
  it "redis_ns_redimap should default to redimap" do
26
- @config.redis_ns_redimap.should == "redimap"
24
+ Redimap.config.redis_ns_redimap.should == "redimap"
27
25
  end
28
26
 
29
27
  it "redis_ns_queue should default to resque" do
30
- @config.redis_ns_queue.should == "resque"
28
+ Redimap.config.redis_ns_queue.should == "resque"
31
29
  end
32
30
 
33
31
  it "polling_interval should default to 60 seconds" do
34
- @config.polling_interval.should == 60
32
+ Redimap.config.polling_interval.should == 60
35
33
  end
36
34
  end
37
35
 
38
36
  context "Non-defaults" do
39
37
  before(:each) do
40
- ENV.stub(:[]).with("IMAP_HOST").and_return("imap.carrot.localhost")
41
- ENV.stub(:[]).with("IMAP_PORT").and_return(666)
42
- ENV.stub(:[]).with("IMAP_USERNAME").and_return("Pachelbel")
43
- ENV.stub(:[]).with("IMAP_PASSWORD").and_return("Canon")
44
- ENV.stub(:[]).with("IMAP_MAILBOXES").and_return('["INBOX","SENT"]')
45
- ENV.stub(:[]).with("REDIS_URL").and_return("redis://127.0.0.1:6379/1")
46
- ENV.stub(:[]).with("REDIS_NS_REDIMAP").and_return("brekyread")
47
- ENV.stub(:[]).with("REDIS_NS_QUEUE").and_return("sidekiq")
48
- ENV.stub(:[]).with("POLLING_INTERVAL").and_return(300)
49
-
50
- @config = Redimap::Config.new
38
+ Redimap.configure do |c|
39
+ c.log_level = "WARN"
40
+
41
+ c.imap_host = "imap.carrot.localhost"
42
+ c.imap_port = 666
43
+ c.imap_username = "Pachelbel"
44
+ c.imap_password = "Canon"
45
+
46
+ c.imap_mailboxes = ['INBOX', 'SENT']
47
+
48
+ c.redis_url = "redis://127.0.0.1:6379/1"
49
+ c.redis_ns_redimap = "brekyread"
50
+ c.redis_ns_queue = "sidekiq"
51
+
52
+ c.polling_interval = 300
53
+ end
54
+ end
55
+
56
+ it "log_level should get set" do
57
+ Redimap.config.log_level.should == "WARN"
51
58
  end
52
59
 
53
- it "imap_host should get set from IMAP_HOST" do
54
- @config.imap_host.should == "imap.carrot.localhost"
60
+ it "imap_host should get set" do
61
+ Redimap.config.imap_host.should == "imap.carrot.localhost"
55
62
  end
56
63
 
57
- it "imap_port should get set from IMAP_PORT" do
58
- @config.imap_port.should == 666
64
+ it "imap_port should get set" do
65
+ Redimap.config.imap_port.should == 666
59
66
  end
60
67
 
61
- it "imap_username should get set from IMAP_USERNAME" do
62
- @config.imap_username.should == "Pachelbel"
68
+ it "imap_username should get set" do
69
+ Redimap.config.imap_username.should == "Pachelbel"
63
70
  end
64
71
 
65
- it "imap_password should get set from IMAP_PASSWORD" do
66
- @config.imap_password.should == "Canon"
72
+ it "imap_password should get set" do
73
+ Redimap.config.imap_password.should == "Canon"
67
74
  end
68
75
 
69
- it "imap_mailboxes should get set from IMAP_MAILBOXES" do
70
- @config.imap_mailboxes.should == ['INBOX', 'SENT']
76
+ it "imap_mailboxes should get set" do
77
+ Redimap.config.imap_mailboxes.should == ['INBOX', 'SENT']
71
78
  end
72
79
 
73
- it "redis_url should get set from REDIS_URL" do
74
- @config.redis_url.should == "redis://127.0.0.1:6379/1"
80
+ it "redis_url should get set" do
81
+ Redimap.config.redis_url.should == "redis://127.0.0.1:6379/1"
75
82
  end
76
83
 
77
- it "redis_ns_redimap should get set from REDIS_NS_REDIMAP" do
78
- @config.redis_ns_redimap.should == "brekyread"
84
+ it "redis_ns_redimap should get set" do
85
+ Redimap.config.redis_ns_redimap.should == "brekyread"
79
86
  end
80
87
 
81
- it "redis_ns_queue should get set from REDIS_NS_QUEUE" do
82
- @config.redis_ns_queue.should == "sidekiq"
88
+ it "redis_ns_queue should get set" do
89
+ Redimap.config.redis_ns_queue.should == "sidekiq"
83
90
  end
84
91
 
85
- it "polling_interval should get set from POLLING_INTERVAL" do
86
- @config.polling_interval.should == 300
92
+ it "polling_interval should get set" do
93
+ Redimap.config.polling_interval.should == 300
87
94
  end
88
95
  end
89
96
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redimap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tiredpixel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-22 00:00:00.000000000 Z
11
+ date: 2013-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis