idid 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/bin/idid CHANGED
@@ -37,6 +37,6 @@ else
37
37
  Idid::Delivery.new(config).email task.to_s
38
38
  Idid::Interactive.status "Got it! Let's get some more done!"
39
39
  else
40
- Idid::Interactive.fail "Shoot! An empty message cannot be send!"
40
+ Idid::Interactive.fail "Shoot! An empty message cannot be sent!"
41
41
  end
42
- end
42
+ end
@@ -14,8 +14,10 @@ module Idid
14
14
  :location => '/usr/bin/exim'
15
15
  }
16
16
 
17
- # Public: Name of the project to post to (e.g. project.idonethis.com)
18
- attr_accessor :project
17
+ # Public: Account type for this user
18
+ attr_accessor :account_type
19
+ # Public: Name of the team to post to
20
+ attr_accessor :team
19
21
  # Public: Email address String to use when sending mail.
20
22
  attr_accessor :email
21
23
  # Public: Email delivery configuration
@@ -24,30 +26,54 @@ module Idid
24
26
  # Public: configuration to use with iDoneThis
25
27
  #
26
28
  # options - Hash with configuration options
27
- # project - Name of the project to post to (e.g.
28
- # project.idonethis.com)
29
29
  # email - Email address to use when sending mail.
30
30
  # delivery - Email delivery configuration Hash:
31
31
  # method - Symbol (:smtp|:sendmail|:exim)
32
32
  # options - Configuration Hash for the
33
33
  # delivery method (see:
34
34
  # https://github.com/mikel/mail).
35
+ # team - Name of the team to post to (optional)
35
36
  #
36
37
  # Returns a new Idid::Configuration instance
37
38
  def initialize(options = {})
38
39
  options = read_config.merge options if read_config
39
- raise ArgumentError.new "Provide a project to use." unless options['project']
40
+ raise ArgumentError.new "Provide an account type." unless options['account_type']
41
+ raise ArgumentError.new "Provide a team to use." if options['account_type'] == 'team' && options['team'].nil?
40
42
  raise ArgumentError.new "Provide an email address." unless options['email']
41
43
  raise ArgumentError.new "Provide a delivery method." unless options['delivery']
42
44
 
43
- @project = options['project']
45
+ @account_type = options['account_type']
46
+ @team = options['team']
44
47
  @email = options['email']
45
48
  @delivery = options['delivery']
46
49
  end
47
50
 
51
+ # Public: The email address of IDoneThis to send your updates to. This
52
+ # depends on whether you have a personal or a team account.
53
+ #
54
+ # Returns the String with the right email address to use
55
+ def idonethis_email
56
+ personal_account? ? "today@idonethis.com" : "#{team}@team.idonethis.com"
57
+ end
58
+
59
+ # Public: Determines if current configuration belongs to a personal account
60
+ #
61
+ # Returns boolean
62
+ def personal_account?
63
+ account_type == 'personal'
64
+ end
65
+
66
+ # Public: Determines if current configuration belongs to a team account
67
+ #
68
+ # Returns boolean
69
+ def team_account?
70
+ account_type == 'team'
71
+ end
72
+
48
73
  def write
49
74
  config = {
50
- 'project' => project,
75
+ 'account_type' => account_type,
76
+ 'team' => team,
51
77
  'email' => email,
52
78
  'delivery' => delivery
53
79
  }
data/lib/idid/delivery.rb CHANGED
@@ -24,7 +24,7 @@ module Idid
24
24
 
25
25
  Mail.deliver do
26
26
  from config.email
27
- to "#{config.project}@team.idonethis.com"
27
+ to config.idonethis_email
28
28
  subject "I did this"
29
29
  body message
30
30
  end
@@ -6,9 +6,17 @@ module Idid
6
6
  status "Please take a moment to create a new configuration.."
7
7
  config = user_config
8
8
  config['delivery'] ||= {}
9
- user_config_from_key 'project', "What is the name of your iDoneThis project (look at the url: <project>.idonethis.com)", nil, config
10
- user_config_from_key 'email', "What is your associated email address for this iDoneThis project?", nil, config
11
- user_config_from_key 'method', "How do you want to send emails to iDoneThis? (smtp, sendmail, exim)", 'smtp', config['delivery']
9
+
10
+ user_config_from_key 'account_type', "What kind of iDoneThis account do you have? (personal|team)", 'personal', config
11
+
12
+ if config["account_type"] == 'team'
13
+ user_config_from_key 'team', "What is the name of your iDoneThis team? (check the URL <team>.idonethis.com).", nil, config
14
+ else
15
+ config["team"] = nil
16
+ end
17
+
18
+ user_config_from_key 'email', "What is your associated email address for this iDoneThis account?", nil, config
19
+ user_config_from_key 'method', "How do you want to send emails to iDoneThis? (smtp|sendmail|exim)", 'smtp', config['delivery']
12
20
 
13
21
  case config['delivery']['method']
14
22
  when 'smtp'
data/lib/idid/task.rb CHANGED
@@ -12,7 +12,6 @@ module Idid
12
12
  # Returns an instance of Task
13
13
  def initialize(contents, logdate = nil)
14
14
  @contents = contents
15
- @log = Task.read_log
16
15
  @logdate = logdate || Date.today
17
16
  end
18
17
 
@@ -24,13 +23,13 @@ module Idid
24
23
  def save
25
24
  logdate = @logdate.strftime '%Y-%m-%d'
26
25
 
27
- if @log.has_key? logdate
28
- @log[logdate].push @contents
26
+ if log.has_key? logdate
27
+ log[logdate].push @contents
29
28
  else
30
- @log[logdate] = [@contents]
29
+ log[logdate] = [@contents]
31
30
  end
32
31
 
33
- Task.write_log @log
32
+ Task.write_log log
34
33
  end
35
34
 
36
35
  # Public: Transform Task into a String
@@ -40,6 +39,10 @@ module Idid
40
39
  @contents
41
40
  end
42
41
 
42
+ def log
43
+ @log ||= Task.read_log
44
+ end
45
+
43
46
  # Public: Lists all activities for a given date.
44
47
  #
45
48
  # date - The String date you wish to show the entries of, in the format
@@ -63,7 +66,7 @@ module Idid
63
66
  #
64
67
  # Returns the String with the location of the log file
65
68
  def self.logfile
66
- logfile = File.join ENV['HOME'], '.idid'
69
+ File.join ENV['HOME'], '.idid'
67
70
  end
68
71
 
69
72
  # Private: Reads the log file into memory.
@@ -87,4 +90,4 @@ module Idid
87
90
  File.open(logfile, 'w') { |f| f.write log.to_json }
88
91
  end
89
92
  end
90
- end
93
+ end
data/lib/idid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Idid
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -1,32 +1,77 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Idid::Configuration do
4
- subject { Idid::Configuration.new('project' => project, 'email' => email, 'delivery' => delivery) }
4
+ subject { configuration }
5
+
6
+ let(:configuration) { Idid::Configuration.new('team' => team, 'email' => email, 'delivery' => delivery, 'account_type' => account_type) }
5
7
  let(:email) { 'foo@example.com' }
6
- let(:project) { 'foobar' }
8
+ let(:team) { 'foobar' }
7
9
  let(:delivery) { {:method => :sendmail} }
10
+ let(:account_type) { 'team' }
8
11
 
9
- its('project') { should eq project }
10
- its('email') { should eq email }
12
+ its('team') { should eq team }
13
+ its('email') { should eq email }
14
+ its('account_type') { should eq account_type }
11
15
 
12
16
  context "when any of the options are missing" do
13
17
  before do
14
18
  Idid::Configuration.any_instance.stub(:read_config) { nil }
15
19
  end
20
+ let(:account_type) { 'personal' }
16
21
 
17
- it 'raises ArgumentError if no email option is passed' do
18
- expect { Idid::Configuration.new('project' => project, 'delivery' => delivery) }.
19
- to raise_error(ArgumentError, /email/)
22
+ it 'raises ArgumentError if no team option is passed while on a team account' do
23
+ expect { Idid::Configuration.new('email' => email, 'delivery' => delivery, 'account_type' => 'team') }.
24
+ to raise_error(ArgumentError, /team/)
20
25
  end
21
26
 
22
- it 'raises ArgumentError if no project option is passed' do
23
- expect { Idid::Configuration.new('email' => email, 'delivery' => delivery) }.
24
- to raise_error(ArgumentError, /project/)
27
+ it 'doesnt raises ArgumentError if no team option is passed while on a personal account' do
28
+ expect { Idid::Configuration.new('email' => email, 'delivery' => delivery, 'account_type' => 'personal') }.
29
+ to_not raise_error
30
+ end
31
+
32
+ it 'raises ArgumentError if no email option is passed' do
33
+ expect { Idid::Configuration.new('team' => team, 'delivery' => delivery, 'account_type' => account_type) }.
34
+ to raise_error(ArgumentError, /email/)
25
35
  end
26
36
 
27
37
  it 'raises ArgumentError if no delivery option is passed' do
28
- expect { Idid::Configuration.new('email' => email, 'project' => project) }.
38
+ expect { Idid::Configuration.new('email' => email, 'team' => team, 'account_type' => account_type) }.
29
39
  to raise_error(ArgumentError, /delivery/)
30
40
  end
41
+
42
+ it 'raises ArgumentError if no account type is passed' do
43
+ expect { Idid::Configuration.new('email' => email, 'team' => team, 'delivery' => delivery) }.
44
+ to raise_error(ArgumentError, /account type/)
45
+ end
46
+ end
47
+
48
+ describe "#idonethis_email" do
49
+ subject { configuration.idonethis_email }
50
+
51
+ context "team account" do
52
+ let(:account_type) { 'team' }
53
+ let(:team) { 'foobar' }
54
+ it { should eq 'foobar@team.idonethis.com' }
55
+ end
56
+
57
+ context "personal account" do
58
+ let(:account_type) { 'personal' }
59
+ it { should eq 'today@idonethis.com' }
60
+ end
31
61
  end
62
+
63
+ describe "#personal_account?" do
64
+ subject { configuration.personal_account? }
65
+
66
+ let(:account_type) { 'personal' }
67
+ it { should be_true }
68
+ end
69
+
70
+ describe "#team_account?" do
71
+ subject { configuration.team_account? }
72
+
73
+ let(:account_type) { 'team' }
74
+ it { should be_true }
75
+ end
76
+
32
77
  end
@@ -7,9 +7,10 @@ describe Idid::Delivery do
7
7
  let(:delivery) { Idid::Delivery.new config }
8
8
  let(:config) do
9
9
  Idid::Configuration.new(
10
- 'project' => 'foo',
10
+ 'team' => 'foo',
11
11
  'email' => 'john@example.com',
12
- 'delivery' => { 'method' => :test }
12
+ 'delivery' => { 'method' => :test },
13
+ 'account_type' => 'team'
13
14
  )
14
15
  end
15
16
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: idid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-08 00:00:00.000000000 Z
12
+ date: 2013-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake