Permalink
Browse files

Basic task creation

  • Loading branch information...
rahult committed Nov 23, 2011
1 parent 4049d16 commit d52552b0029097fed9a391fcae8ce6ab4509b7ff
Showing with 44 additions and 49 deletions.
  1. +3 −1 bin/ae
  2. +26 −47 lib/asana.rb
  3. +15 −1 spec/asana_spec.rb
View
4 bin/ae
@@ -3,4 +3,6 @@
$:.unshift(File.join(File.dirname(File.dirname(__FILE__)),'lib'))
require 'asana'
-Asana.run(ARGV)
+asana = Asana.new(STDOUT, ARGV)
+asana.deliver!
+puts "hello world"
View
@@ -1,66 +1,45 @@
+require 'yaml'
require 'mail'
-Mail.defaults do
- delivery_method :smtp, {
- :address => "smtp.sendgrid.net",
- :port => '25',
- :domain => "katalyst.com.au",
- :authentication => :plain,
- :user_name => "jason@katalyst.com.au",
- :password => "i9XypcTh2GOptAvK"
- }
-end
class Asana
class Error < RuntimeError
end
- def self.run(argv)
+ def initialize(output=STDOUT, argv=nil)
+ @output = output
+ parse(argv)
+ end
+
+ def parse(argv)
if argv.empty?
- puts "Please add your task"
+ @output.puts "Please provide a task"
+ exit
else
- argv.join(' ')
+ setup
+ @@task = argv.is_a?(Array) ? argv.join("") : argv
end
- rescue Error
- $stderr.puts "#$!"
- exit 1
- rescue Interrupt
- $stderr.puts "Interrupted!"
- exit 130
- end
-
- def initialize(task)
- add_task(task)
end
- def add_task(task=nil)
- mail = Mail.deliver do
- to ' x@mail.asana.com'
- from 'Rahul Trikha <rahul.trikha@gmail.com>'
- subject 'Test task'
- text_part do
- body 'Notes go here'
- end
+ def setup
+ @@settings ||= YAML.load(File.read(File.expand_path('~/.asana.yml')))
+ Mail.defaults do
+ delivery_method :smtp, @@settings[:smtp]
end
end
- def reconfigure
- token = authenticate['token']
- File.open(self.class.config_file,'w') do |f|
- f.puts "auth_token: #{token}"
+ def message
+ Mail.new do
+ to @@settings[:to]
+ from @@settings[:from]
+ subject @@task
end
end
- def self.config_file
- File.expand_path('~/.asana.yml')
- end
-
- def account(auth_token = nil)
- require 'yaml'
- @account ||=
- begin
- reconfigure unless File.exist?(self.class.config_file)
- t = YAML.load(File.read(self.class.config_file))['auth_token']
- account(t)
- end
+ def deliver!
+ result = "Unable to add task to Asana"
+ if message.deliver
+ result = "#{@@task} task added to Asana"
+ end
+ @output.puts result
end
end
View
@@ -1,7 +1,21 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec/spec_helper')
describe Asana do
+ let(:output) { double('output').as_null_object }
+
subject do
- Asana.new('This is a test task')
+ Asana.new(output, "Test")
+ end
+
+ it "it should exit cleanly if no task is provided" do
+ lambda { ::Asana.new(output, "") }.should raise_error SystemExit
+ end
+
+ it "should return a Mail object" do
+ subject.message.class.eql?(Mail::Message)
+ end
+
+ it "should return a success message after delivering a task" do
+ subject.deliver!.eql?("Test task added to Asana")
end
end

0 comments on commit d52552b

Please sign in to comment.