teambox-things-sync 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +10 -1
- data/VERSION +1 -1
- data/lib/teambox-things-sync.rb +38 -3
- data/lib/teambox-things-sync/base.rb +23 -8
- data/lib/teambox-things-sync/cache/base_cache.rb +19 -0
- data/lib/teambox-things-sync/cache/task_list_cache.rb +9 -0
- data/lib/teambox-things-sync/cache/user_name_cache.rb +10 -0
- data/spec/spec_helper.rb +8 -1
- data/spec/teambox-things-sync/cache/task_list_cache_spec.rb +14 -0
- data/spec/teambox-things-sync/cache/user_name_cache_spec.rb +15 -0
- data/spec/teambox-things-sync_spec.rb +71 -3
- data/teambox-things-sync.gemspec +9 -5
- metadata +10 -6
- data/lib/teambox-things-sync/task_list_cache.rb +0 -17
- data/spec/teambox-things-sync/task_list_cache_spec.rb +0 -5
data/Rakefile
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
1
3
|
begin
|
2
|
-
require 'rubygems'
|
3
4
|
require 'jeweler'
|
4
5
|
Jeweler::Tasks.new do |gemspec|
|
5
6
|
gemspec.name = "teambox-things-sync"
|
@@ -14,3 +15,11 @@ begin
|
|
14
15
|
rescue LoadError
|
15
16
|
puts "Jeweler not available. Install it with: gem install jeweler"
|
16
17
|
end
|
18
|
+
|
19
|
+
namespace :command do
|
20
|
+
desc "Run command with using current folder files (not gem)'"
|
21
|
+
task :test do
|
22
|
+
require 'lib/teambox-things-sync.rb'
|
23
|
+
require 'lib/teambox-things-sync/command'
|
24
|
+
end
|
25
|
+
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/lib/teambox-things-sync.rb
CHANGED
@@ -6,10 +6,45 @@ require 'timeout'
|
|
6
6
|
module TeamboxThingsSync
|
7
7
|
autoload :Base, File.dirname(__FILE__) + '/teambox-things-sync/base'
|
8
8
|
autoload :ConfigStore, File.dirname(__FILE__) + '/teambox-things-sync/config_store'
|
9
|
-
|
9
|
+
module Cache
|
10
|
+
autoload :BaseCache, File.dirname(__FILE__) + '/teambox-things-sync/cache/base_cache'
|
11
|
+
autoload :TaskListCache, File.dirname(__FILE__) + '/teambox-things-sync/cache/task_list_cache'
|
12
|
+
autoload :UserNameCache, File.dirname(__FILE__) + '/teambox-things-sync/cache/user_name_cache'
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
16
|
module Things
|
13
|
-
|
14
|
-
|
17
|
+
# adds additional properties that doesn't exist in original gem
|
18
|
+
additional_properties = %{properties :tag_names, :due_date}
|
19
|
+
Todo.module_eval(additional_properties)
|
20
|
+
|
21
|
+
class Todo
|
22
|
+
|
23
|
+
attr_accessor :was_in_today
|
24
|
+
|
25
|
+
# Moves todo to Today list if it's due today or in the past, or user
|
26
|
+
# put it there manually
|
27
|
+
def move_to_today_if_necessary
|
28
|
+
tomorrow_midnight = Time.parse((Date.today+1).to_s)
|
29
|
+
if (self.due_date && self.due_date < tomorrow_midnight) || was_in_today
|
30
|
+
self.move(Things::List.today)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def remember_today_listing
|
35
|
+
@was_in_today = Things::Todo.today.any? {|t| t.name == self.name}
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.find(name_or_id)
|
39
|
+
todo = super
|
40
|
+
todo.remember_today_listing if todo
|
41
|
+
return todo
|
42
|
+
end
|
43
|
+
|
44
|
+
def save
|
45
|
+
todo = super
|
46
|
+
todo.move_to_today_if_necessary if todo
|
47
|
+
return todo
|
48
|
+
end
|
49
|
+
end
|
15
50
|
end
|
@@ -60,7 +60,10 @@ module TeamboxThingsSync
|
|
60
60
|
def mark_as_done_at_remote(project)
|
61
61
|
@client.tasks.each do |task|
|
62
62
|
things_todo = Things::Todo.find(task.name)
|
63
|
-
|
63
|
+
|
64
|
+
#TODO: clean it up
|
65
|
+
if !things_todo.nil? && things_todo.completed? && is_task_open?(task.status) &&
|
66
|
+
!Things::App.lists.trash.reference.todos.name.get.include?(things_todo.name)
|
64
67
|
# API isn't great right now, so we update task as resolved
|
65
68
|
# and add the new comment to it
|
66
69
|
@client.update_project_task(project.permalink, task.id, {:status => 3})
|
@@ -74,7 +77,9 @@ module TeamboxThingsSync
|
|
74
77
|
|
75
78
|
# fetches current task data from remote
|
76
79
|
def fetch_tasks_from_remote(project, person_id)
|
77
|
-
task_list_cache = TaskListCache.new(@client,
|
80
|
+
task_list_cache = Cache::TaskListCache.new(@client,
|
81
|
+
{:project_permalink => project.permalink})
|
82
|
+
@user_name_cache = Cache::UserNameCache.new(@client)
|
78
83
|
@client.tasks.each do |task|
|
79
84
|
# grab only tasks assigned to current user
|
80
85
|
if task.assigned_id == person_id
|
@@ -82,9 +87,10 @@ module TeamboxThingsSync
|
|
82
87
|
# update only those that aren't completed in both local and remote
|
83
88
|
if is_task_open?(task.status) || !things_todo.completed?
|
84
89
|
things_todo.project = Base.find_or_create_project_in_things(project.name)
|
85
|
-
things_todo.notes =
|
86
|
-
|
87
|
-
|
90
|
+
things_todo.notes = build_notes(project.permalink,
|
91
|
+
task.task_list_id, task.id)
|
92
|
+
things_todo.tag_names = task_list_cache[task.task_list_id]
|
93
|
+
|
88
94
|
unless task.due_on.nil?
|
89
95
|
things_todo.due_date = Time.parse(task.due_on)
|
90
96
|
end
|
@@ -95,9 +101,8 @@ module TeamboxThingsSync
|
|
95
101
|
else
|
96
102
|
things_todo.open
|
97
103
|
end
|
98
|
-
|
99
|
-
things_todo.
|
100
|
-
things_todo.save
|
104
|
+
|
105
|
+
things_todo.save
|
101
106
|
log "\"#{task.name}\" has been saved in Things.app"
|
102
107
|
end
|
103
108
|
end
|
@@ -113,6 +118,16 @@ module TeamboxThingsSync
|
|
113
118
|
# end
|
114
119
|
end
|
115
120
|
|
121
|
+
def build_notes(project_permalink, task_list_id, task_id)
|
122
|
+
notes = task_url(project_permalink, task_list_id, task_id)+"\n\n"
|
123
|
+
@client.project_task_comments(project_permalink, task_id).reverse.each do |c|
|
124
|
+
unless c.body.nil? || c.body.empty?
|
125
|
+
notes << "#{@user_name_cache[c.user_id]} @ #{c.updated_at}:\n #{c.body} \n----------\n\n"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
notes
|
129
|
+
end
|
130
|
+
|
116
131
|
# finds person_id in given project
|
117
132
|
def find_person_id(project_permalink)
|
118
133
|
project_people = @client.project_people(project_permalink)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module TeamboxThingsSync
|
2
|
+
# saves unnecessary API queries for task list names
|
3
|
+
module Cache
|
4
|
+
class BaseCache
|
5
|
+
def initialize(client, config = {})
|
6
|
+
@data = {}
|
7
|
+
@client = client
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
|
11
|
+
def [](id)
|
12
|
+
if @data[id].nil?
|
13
|
+
@data[id] = query_api(id)
|
14
|
+
end
|
15
|
+
@data[id]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -5,4 +5,11 @@ require 'things'
|
|
5
5
|
require 'time'
|
6
6
|
require 'timeout'
|
7
7
|
require 'rspec'
|
8
|
-
|
8
|
+
|
9
|
+
Dir["#{File.dirname(__FILE__)}/../lib/*.rb"].each {|f| require f}
|
10
|
+
|
11
|
+
module Things
|
12
|
+
def self.names_of_todos_in_today_list
|
13
|
+
Things::App.lists.today.reference.todos.name.get
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe "TeamboxThingsSync::Cache::TaskListCache" do
|
4
|
+
it "should query teambox api, get and return task name" do
|
5
|
+
@client = double
|
6
|
+
to_return = Hashie::Mash.new(:name => "test")
|
7
|
+
|
8
|
+
task_list_cache = TeamboxThingsSync::Cache::TaskListCache.new(@client,
|
9
|
+
{:project_permalink => "testing"})
|
10
|
+
@client.should_receive(:project_task_list).with("testing", 1).
|
11
|
+
and_return(to_return)
|
12
|
+
task_list_cache[1].should == "test"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe "TeamboxThingsSync::Cache::UserNameCache" do
|
4
|
+
it "should query teambox api, get and return user name" do
|
5
|
+
@client = double
|
6
|
+
to_return = Hashie::Mash.new(:first_name => "John", :last_name => "Smith")
|
7
|
+
|
8
|
+
user_name_cache = TeamboxThingsSync::Cache::UserNameCache.new(@client)
|
9
|
+
@client.should_receive(:user).with(22).
|
10
|
+
and_return(to_return)
|
11
|
+
user_name_cache[22].should == "John Smith"
|
12
|
+
@client.should_not_receive(:user)
|
13
|
+
user_name_cache[22]
|
14
|
+
end
|
15
|
+
end
|
@@ -1,5 +1,73 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe
|
4
|
-
|
5
|
-
|
3
|
+
describe "Things::Todo" do
|
4
|
+
|
5
|
+
describe "#move_to_today_if_necessary" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
Things::App.instance.empty_trash
|
9
|
+
@todo = TeamboxThingsSync::Base.find_or_create_todo_in_things('TEST - Foo')
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be moved to Today if due date is today" do
|
13
|
+
@todo.due_date = Time.now
|
14
|
+
@todo.save
|
15
|
+
Things::names_of_todos_in_today_list.should include(@todo.name)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be moved to Today if due date is in the past" do
|
19
|
+
@todo.due_date = Time.now-60*60*24*2
|
20
|
+
@todo.save
|
21
|
+
Things::names_of_todos_in_today_list.should include(@todo.name)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should not be moved to Today if due date is in the future" do
|
25
|
+
@todo.due_date = Time.now+60*60*24
|
26
|
+
@todo.save
|
27
|
+
Things::names_of_todos_in_today_list.should_not include(@todo.name)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be moved to Today if user put it manually into Today and then it was resetted by Things::Todo" do
|
31
|
+
@todo.save
|
32
|
+
@todo.move(Things::List.today)
|
33
|
+
@todo = TeamboxThingsSync::Base.find_or_create_todo_in_things('TEST - Foo')
|
34
|
+
@todo.save
|
35
|
+
Things::names_of_todos_in_today_list.should include(@todo.name)
|
36
|
+
end
|
37
|
+
|
38
|
+
after do
|
39
|
+
@todo.delete
|
40
|
+
Things::App.instance.empty_trash
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#remember_today_listing" do
|
46
|
+
|
47
|
+
before do
|
48
|
+
Things::App.instance.empty_trash
|
49
|
+
@todo = TeamboxThingsSync::Base.find_or_create_todo_in_things('TEST - Foo')
|
50
|
+
@todo.save
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return true if todo existed in Today before updating" do
|
54
|
+
@todo.move(Things::List.today)
|
55
|
+
@todo = TeamboxThingsSync::Base.find_or_create_todo_in_things('TEST - Foo')
|
56
|
+
@todo.save
|
57
|
+
@todo.was_in_today.should be_true
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should return false if todo didn't exist in Today before updating" do
|
61
|
+
@todo = TeamboxThingsSync::Base.find_or_create_todo_in_things('TEST - Foo')
|
62
|
+
@todo.save
|
63
|
+
@todo.was_in_today.should be_false
|
64
|
+
end
|
65
|
+
|
66
|
+
after do
|
67
|
+
@todo.delete
|
68
|
+
Things::App.instance.empty_trash
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
data/teambox-things-sync.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{teambox-things-sync}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Arkadiusz Holko"]
|
12
|
-
s.date = %q{2010-09-
|
12
|
+
s.date = %q{2010-09-17}
|
13
13
|
s.default_executable = %q{teambox-things-sync}
|
14
14
|
s.email = %q{fastred@fastred.org}
|
15
15
|
s.executables = ["teambox-things-sync"]
|
@@ -28,12 +28,15 @@ Gem::Specification.new do |s|
|
|
28
28
|
"bin/teambox-things-sync",
|
29
29
|
"lib/teambox-things-sync.rb",
|
30
30
|
"lib/teambox-things-sync/base.rb",
|
31
|
+
"lib/teambox-things-sync/cache/base_cache.rb",
|
32
|
+
"lib/teambox-things-sync/cache/task_list_cache.rb",
|
33
|
+
"lib/teambox-things-sync/cache/user_name_cache.rb",
|
31
34
|
"lib/teambox-things-sync/command.rb",
|
32
35
|
"lib/teambox-things-sync/config_store.rb",
|
33
|
-
"lib/teambox-things-sync/task_list_cache.rb",
|
34
36
|
"spec/spec_helper.rb",
|
35
37
|
"spec/teambox-things-sync/base_spec.rb",
|
36
|
-
"spec/teambox-things-sync/task_list_cache_spec.rb",
|
38
|
+
"spec/teambox-things-sync/cache/task_list_cache_spec.rb",
|
39
|
+
"spec/teambox-things-sync/cache/user_name_cache_spec.rb",
|
37
40
|
"spec/teambox-things-sync_spec.rb",
|
38
41
|
"teambox-things-sync.gemspec"
|
39
42
|
]
|
@@ -45,7 +48,8 @@ Gem::Specification.new do |s|
|
|
45
48
|
s.test_files = [
|
46
49
|
"spec/spec_helper.rb",
|
47
50
|
"spec/teambox-things-sync/base_spec.rb",
|
48
|
-
"spec/teambox-things-sync/task_list_cache_spec.rb",
|
51
|
+
"spec/teambox-things-sync/cache/task_list_cache_spec.rb",
|
52
|
+
"spec/teambox-things-sync/cache/user_name_cache_spec.rb",
|
49
53
|
"spec/teambox-things-sync_spec.rb"
|
50
54
|
]
|
51
55
|
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Arkadiusz Holko
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-17 00:00:00 +02:00
|
18
18
|
default_executable: teambox-things-sync
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -81,12 +81,15 @@ files:
|
|
81
81
|
- bin/teambox-things-sync
|
82
82
|
- lib/teambox-things-sync.rb
|
83
83
|
- lib/teambox-things-sync/base.rb
|
84
|
+
- lib/teambox-things-sync/cache/base_cache.rb
|
85
|
+
- lib/teambox-things-sync/cache/task_list_cache.rb
|
86
|
+
- lib/teambox-things-sync/cache/user_name_cache.rb
|
84
87
|
- lib/teambox-things-sync/command.rb
|
85
88
|
- lib/teambox-things-sync/config_store.rb
|
86
|
-
- lib/teambox-things-sync/task_list_cache.rb
|
87
89
|
- spec/spec_helper.rb
|
88
90
|
- spec/teambox-things-sync/base_spec.rb
|
89
|
-
- spec/teambox-things-sync/task_list_cache_spec.rb
|
91
|
+
- spec/teambox-things-sync/cache/task_list_cache_spec.rb
|
92
|
+
- spec/teambox-things-sync/cache/user_name_cache_spec.rb
|
90
93
|
- spec/teambox-things-sync_spec.rb
|
91
94
|
- teambox-things-sync.gemspec
|
92
95
|
has_rdoc: true
|
@@ -122,5 +125,6 @@ summary: Simple ruby app for Teambox and Things.app syncing
|
|
122
125
|
test_files:
|
123
126
|
- spec/spec_helper.rb
|
124
127
|
- spec/teambox-things-sync/base_spec.rb
|
125
|
-
- spec/teambox-things-sync/task_list_cache_spec.rb
|
128
|
+
- spec/teambox-things-sync/cache/task_list_cache_spec.rb
|
129
|
+
- spec/teambox-things-sync/cache/user_name_cache_spec.rb
|
126
130
|
- spec/teambox-things-sync_spec.rb
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module TeamboxThingsSync
|
2
|
-
class TaskListCache
|
3
|
-
|
4
|
-
def initialize(client, project_name)
|
5
|
-
@data = {}
|
6
|
-
@client = client
|
7
|
-
@project_name = project_name
|
8
|
-
end
|
9
|
-
|
10
|
-
def [](task_list_id)
|
11
|
-
if @data[task_list_id].nil?
|
12
|
-
@data[task_list_id] = @client.project_task_list(@project_name, task_list_id).name
|
13
|
-
end
|
14
|
-
@data[task_list_id]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|