Class: Rrtm

Inherits:
Object
  • Object
show all
Defined in:
lib/thartmx.rb

Instance Method Summary collapse

Constructor Details

#initialize(key, secret, token) ⇒ Rrtm

Returns a new instance of Rrtm.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/thartmx.rb', line 10

def initialize(key,secret,token)
	#@rtm = ThaRememberTheMilk.new(@@config['key'],@@config['secret'],@@config['token'])
	@rtm = ThaRememberTheMilk.new(key,secret,token)
	@rtm.use_user_tz = true
	@rtm.debug = false

	# id of the all tasks list
	@allTaskList = String.new 
	
	@lists = lists
	@timeline = @rtm.timelines.create
end

Instance Method Details

#addTask(name) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/thartmx.rb', line 57

def addTask(name) 
	if name =~ /^(@(\w|\s)+@)/
		listname = name.match(/^(@(\w|\s)+@)/)[0][1..-2]
		name.sub!(/^(@(\w|\s)+@)/,'')
	end
	listid = allTaskList
	if listname
	@lists.each do |k,v|
		if v[:name].match(listname)
			listid =  v[:id]
		end
	end
	end

	@rtm.tasks.add :timeline => @timeline, :name =>  name, :parse => '1', :list_id => listid
end

#allTaskListObject



23
24
25
26
27
28
29
30
31
# File 'lib/thartmx.rb', line 23

def allTaskList
	allTaskList = ''
	@lists.each do |k,v|
		if v[:name] == "Inbox"
			allTaskList = v[:id]
		end
	end
	return allTaskList
end

#completeTask(id) ⇒ Object



84
85
86
87
# File 'lib/thartmx.rb', line 84

def completeTask(id)
	v = findTask(id)
	@rtm.tasks.complete :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id
end

#delete(id) ⇒ Object



89
90
91
92
# File 'lib/thartmx.rb', line 89

def delete(id)
	v = findTask(id)
	@rtm.tasks.delete :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id
end

#findList(name) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/thartmx.rb', line 33

def findList(name)
	flist = ''
	name.chomp!
	@lists.each do |k,v|
		if v[:name] == name
			flist = v[:id]
		end
	end
	return flist
end

#findTask(id) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/thartmx.rb', line 74

def findTask(id)
	tt = tasks
	tt.each do |key,val|
		val.each do |k,v|
			return  v if v[:id] == id
		end
	end
	return nil
end

#getTimezoneObject



127
128
129
130
# File 'lib/thartmx.rb', line 127

def getTimezone
	sets = @rtm.settings.getList
	return sets[:timezone]
end

#listsObject



43
44
45
# File 'lib/thartmx.rb', line 43

def lists
	lists = @rtm.lists.getList
end

#postponeTask(id) ⇒ Object



94
95
96
97
# File 'lib/thartmx.rb', line 94

def postponeTask(id)
	v = findTask(id)
	@rtm.tasks.postpone :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id
end

#renameTask(id, newname) ⇒ Object



99
100
101
102
# File 'lib/thartmx.rb', line 99

def renameTask(id,newname)
	v = findTask(id)
	@rtm.tasks.setName :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id, :name => newname
end

#setDueDate(id, due) ⇒ Object



104
105
106
107
# File 'lib/thartmx.rb', line 104

def setDueDate(id,due)
  v = findTask(id)
	@rtm.tasks.setDueDate :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id, :due => due, :parse => 1  
end

#setPriority(id, priority) ⇒ Object



109
110
111
112
# File 'lib/thartmx.rb', line 109

def setPriority(id, priority)
  v = findTask(id)
  @rtm.tasks.setPriority :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id, :priority => priority		
end

#tasks(args = {}) ⇒ Object



47
48
49
50
# File 'lib/thartmx.rb', line 47

def tasks(args = {}) 
	tasks = @rtm.tasks.getList args 
	
end

#tasksAllTaskListObject



52
53
54
# File 'lib/thartmx.rb', line 52

def tasksAllTaskList
	t = tasks :list_id => allTaskList
end

#uncompleteTask(id) ⇒ Object



114
115
116
117
# File 'lib/thartmx.rb', line 114

def uncompleteTask(id)
	v = findTask(id)
	@rtm.tasks.uncomplete :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id
end

#update(params) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/thartmx.rb', line 119

def update(params)
  v = findTask(params['id'])
  @rtm.tasks.setDueDate :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id, :due => params['due'], :parse => 1 
  @rtm.tasks.setName :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id, :name => params['title'] 
  @rtm.tasks.setPriority :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id, :priority => params['priority']
  @rtm.tasks.complete :timeline => @timeline,:list_id =>v.list_id , :taskseries_id => v.taskseries_id, :task_id => v.task_id unless params['complete'].nil?
end