milk_cap 0.5.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 ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZDFlZjMxMjY5YTE0NDYxZWRlNTdjYmE1MzlmOGZhMjU4NjA3NTZhNA==
5
+ data.tar.gz: !binary |-
6
+ YTI4MzI0NmJmMzg5ODk1MjAyNmJmMTU3OTExMjU0N2JhZTVjNjdkZg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ ZjljMjIwODA0YzJkMDc0OTEzOWMxMjJhY2Y3OWVkOTA2YzU3YzY0Njg2MTI3
10
+ N2I5ZjQ0ODliMGFkYTNmZWQwZWM4Y2NiYTBkYjEwZjQ4YTI0MTkyNDg4ODcz
11
+ NzQ3Y2JlMTQ2MWE4ZmI4MWM3MjViNmRkMzI0NjBlOTg1ZGU3Mzc=
12
+ data.tar.gz: !binary |-
13
+ NWJmOGJmYTRhM2ExODBjNGU4MTllOWI5OTJkMDgyYWE1YjM3OWQ5NzIyYzc4
14
+ NTA2MmNjODQ4ZThjOWM0Y2NiMjNkMTRiZDgzOTg2MzkxODk0NmJiYjM2ZTI1
15
+ OTEwZDBjODk3MGNhODA4ZmM3MTNkMDA2MjA5YjEyZTQ1NjRjY2Y=
data/CHANGELOG.txt ADDED
@@ -0,0 +1,21 @@
1
+
2
+ = milk_cap CHANGELOG.txt
3
+
4
+ == milk_cap - 0.5.0 released 2014/01/02
5
+
6
+ - rufus-rtm is now milk_cap: updated docs, contacts, gemspec, etc
7
+ - module Rufus is now MilkCap
8
+ - no functional changes
9
+
10
+
11
+ == rufus-rtm - 0.1.3 released 2010/01/24
12
+
13
+ - removed ugly World.include(Rufus::Verbs) (shame on me)
14
+ - ruby 1.9.x friendly
15
+ - removed evil "require 'rubygems'" from rufus/rtm/base.rb
16
+ - can now pass rtm key and secret via method params (Giorgio's request)
17
+
18
+
19
+ == rufus-rtm - 0.1 released 2008/02/14
20
+
21
+ - initial release
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+
2
+ Copyright (c) 2008-2013, John Mettraux, Jeff Leverenz
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,147 @@
1
+
2
+ = milk_cap
3
+
4
+
5
+ == getting it
6
+
7
+ gem install milk_cap
8
+
9
+ or at
10
+
11
+ https://github.com/jleverenz/milk_cap
12
+
13
+
14
+ == credentials
15
+
16
+ 'milk_cap' expects to find RTM credentials in the environment. It will look for:
17
+
18
+ * RTM_API_KEY
19
+ * RTM_SHARED_SECRET
20
+ * RTM_FROB
21
+ * RTM_AUTH_TOKEN
22
+
23
+ (Note since version 0.2, it's OK to not set these environment variables and to pass their values for each method with :api_key, :shared_secret, :frob and :auth_token optional parameters (see test_2 of test/tasks_test.rb))
24
+
25
+ You have to apply for the first two ones at http://www.rememberthemilk.com/services/api/keys.rtm
26
+
27
+ Once you have the API key and the shared secret, you have to get the frob and the auth token. Fire your 'irb' and
28
+
29
+ >> require 'rubygems'
30
+ >> require 'milk_cap/rtm'
31
+
32
+ please visit this URL with your browser and then hit 'enter' :
33
+
34
+ http://www.rememberthemilk.com/services/auth/?api_sig=70036e47c38da170fee431f04e29e8f0&frob=fa794036814b78fddf3e5641fe7c37f80e7d91fc&perms=delete&api_key=7f07e4fc5a944bf8c02a7d1e45c79346
35
+
36
+ visit, the given URL, you should finally be greeted by a message like "You have successfully authorized the application API Application. You may now close this window and continue the authentication process with the application that sent you here.", hit enter...
37
+
38
+ ok, now getting auth token...
39
+
40
+ here are your RTM_FROB and RTM_AUTH_TOKEN, make sure to place them
41
+ in your environment :
42
+
43
+ export RTM_FROB=3cef465718317b837eec2faeb5340fe777d55c7c
44
+ export RTM_AUTH_TOKEN=ca0022d705ea1831543b7cdd2d7e3d707a0e1efb
45
+
46
+ make then sure that all the 4 variables are set in the environment you use for running 'milk_cap'.
47
+
48
+
49
+ == usage
50
+
51
+ require 'rubygems'
52
+ require 'milk_cap/rtm'
53
+
54
+ include MilkCap::RTM
55
+
56
+ #
57
+ # listing tasks
58
+
59
+ tasks = Task.find
60
+ # finding all the tasks
61
+
62
+ tasks = Task.find :filter => "status:incomplete"
63
+ # finding all the incomplete tasks
64
+
65
+ tasks.each do |task|
66
+
67
+ puts "task id #{task.task_id}"
68
+ puts " #{task.name} (#{task.tags.join(",")})"
69
+ puts
70
+ end
71
+
72
+ #
73
+ # adding a task
74
+
75
+ task = Task.add! "study this milk_cap gem"
76
+ # gets added to the 'Inbox' by default
77
+
78
+ puts "task id is #{task.task_id}"
79
+
80
+ #
81
+ # enumerating lists
82
+
83
+ lists = List.find
84
+
85
+ w = lists.find { |l| l.name == 'Work' }
86
+
87
+ puts "my Work list id is #{w.list_id}"
88
+
89
+ #
90
+ # adding a task to a list
91
+
92
+ task = Task.add! "work, more work", :list_id => w.list_id
93
+
94
+ #
95
+ # completing a task
96
+
97
+ task.complete!
98
+
99
+ #
100
+ # deleting a task
101
+
102
+ task.delete!
103
+
104
+
105
+ Note that the methods that change the state of the Remember The Milk dataset have names ending with an exclamation mark.
106
+
107
+ Note as well that, there is a 1 second delay before any request to the RTM server, in order to respect their conditions. This may change in future releases.
108
+
109
+
110
+ = features yet to implement
111
+
112
+ * tags modifications
113
+ * smart lists
114
+ * ...
115
+
116
+
117
+ = dependencies
118
+
119
+ The gem 'rufus-verbs' (http://rufus.rubyforge.org/rufus-verbs)
120
+
121
+
122
+ == issue tracker
123
+
124
+ https://github.com/jleverenz/milk_cap/issues
125
+
126
+
127
+ == source
128
+
129
+ https://github.com/jleverenz/milk_cap
130
+
131
+ git clone git://github.com/jleverenz/milk_cap.git
132
+
133
+
134
+ == contributors
135
+
136
+ * John Mettraux, jmettraux@gmail.com
137
+ * Jeff Leverenz, jeff.leverenz@gmail.com (maintainer)
138
+
139
+
140
+ == origin
141
+
142
+ milk_cap is the successor gem to rufus-rtm[https://github.com/jmettraux/rufus-rtm], originally authored by John Mettraux (jmettraux@gmail.com, http://jmettraux.wordpress.com). rufus-rtm is no longer actively supported.
143
+
144
+
145
+ == license
146
+
147
+ MIT
data/Rakefile ADDED
@@ -0,0 +1,64 @@
1
+
2
+
3
+ $: << File.join( File.dirname(__FILE__), "lib" )
4
+ require 'milk_cap/rtm/base'
5
+
6
+ require 'rubygems'
7
+ require 'rake'
8
+
9
+
10
+ #
11
+ # CLEAN
12
+
13
+ require 'rake/clean'
14
+ CLEAN.include('pkg', 'tmp', 'html')
15
+ task :default => [ :clean ]
16
+
17
+
18
+ #
19
+ # GEM
20
+
21
+ require 'jeweler'
22
+
23
+ Jeweler::Tasks.new do |gem|
24
+
25
+ gem.version = MilkCap::RTM::VERSION
26
+ gem.name = 'milk_cap'
27
+ gem.summary = 'Yet another RememberTheMilk wrapper, successor to rufus-rtm.'
28
+
29
+ gem.description = %{
30
+ Yet another RememberTheMilk wrapper, successor to rufus-rtm.
31
+ }
32
+ gem.email = 'jeff.leverenz@gmail.com'
33
+ gem.homepage = 'http://github.com/jleverenz/milk_cap/'
34
+ gem.authors = [ 'John Mettraux', 'Jeff Leverenz' ]
35
+ gem.licenses = 'MIT'
36
+
37
+ gem.test_file = 'test/test.rb'
38
+
39
+ gem.add_dependency 'rufus-verbs', '>= 1.0.0'
40
+ gem.add_development_dependency 'yard', '>= 0'
41
+ end
42
+ Jeweler::GemcutterTasks.new
43
+
44
+
45
+ #
46
+ # DOC
47
+
48
+ begin
49
+
50
+ require 'yard'
51
+
52
+ YARD::Rake::YardocTask.new do |doc|
53
+ doc.options = [
54
+ '-o', 'html/milk_cap', '--title',
55
+ "milk_cap #{MilkCap::RTM::VERSION}"
56
+ ]
57
+ end
58
+
59
+ rescue LoadError
60
+
61
+ task :yard do
62
+ abort "YARD is not available : sudo gem install yard"
63
+ end
64
+ end
@@ -0,0 +1,105 @@
1
+ #--
2
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
3
+ # of this software and associated documentation files (the "Software"), to deal
4
+ # in the Software without restriction, including without limitation the rights
5
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6
+ # copies of the Software, and to permit persons to whom the Software is
7
+ # furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in
10
+ # all copies or substantial portions of the Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18
+ # THE SOFTWARE.
19
+ #
20
+ # Made in Japan.
21
+ #++
22
+
23
+
24
+ require 'rufus/verbs'
25
+
26
+ require 'json' # gem install 'json' or 'json_pure'
27
+
28
+ begin
29
+
30
+ require 'md5'
31
+
32
+ def md5 (s)
33
+ MD5.md5(s).to_s
34
+ end
35
+
36
+ rescue LoadError # ruby 1.9.x
37
+
38
+ require 'digest/md5'
39
+
40
+ def md5 (s)
41
+ Digest::MD5.hexdigest(s)
42
+ end
43
+ end
44
+
45
+
46
+ module MilkCap
47
+ module RTM
48
+
49
+ VERSION = '0.5.0'
50
+
51
+ AUTH_ENDPOINT = "http://www.rememberthemilk.com/services/auth/"
52
+ REST_ENDPOINT = "http://api.rememberthemilk.com/services/rest/"
53
+
54
+ # Signs the RTM request (sets the 'api_sig' parameter).
55
+ #
56
+ def self.sign (params, secret) #:nodoc:
57
+
58
+ params['api_sig'] = md5(secret + params.sort.flatten.join)
59
+
60
+ params
61
+ end
62
+
63
+ # Calls an API method (milk the cow).
64
+ #
65
+ def self.milk (params={}) #:nodoc:
66
+
67
+ sleep 1
68
+
69
+ endpoint = params.delete(:endpoint)
70
+ endpoint = AUTH_ENDPOINT if endpoint == :auth
71
+ endpoint = endpoint || REST_ENDPOINT
72
+
73
+ ps = params.inject({}) { |r, (k, v)| r[k.to_s] = v; r }
74
+
75
+ ps['api_key'] = params[:api_key] || ENV['RTM_API_KEY']
76
+
77
+ raise 'API_KEY missing from environment or parameters, cannot proceed' \
78
+ unless ps['api_key']
79
+
80
+ ps['frob'] = params[:frob] || ENV['RTM_FROB']
81
+ ps.delete('frob') if ps['frob'] == nil
82
+
83
+ ps['auth_token'] = params[:auth_token] || ENV['RTM_AUTH_TOKEN']
84
+ ps.delete('auth_token') if ps['auth_token'] == nil
85
+
86
+ ps['format'] = 'json'
87
+
88
+ secret = params[:shared_secret] || ENV['RTM_SHARED_SECRET']
89
+
90
+ sign(ps, secret)
91
+
92
+ res = Rufus::Verbs.get(endpoint, :query => ps)
93
+
94
+ JSON.parse(res.body)['rsp']
95
+ end
96
+
97
+ # Requests a timeline from RTM.
98
+ #
99
+ def self.get_timeline #:nodoc:
100
+
101
+ milk(:method => 'rtm.timelines.create')['timeline']
102
+ end
103
+
104
+ end
105
+ end
@@ -0,0 +1,100 @@
1
+ #--
2
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
3
+ # of this software and associated documentation files (the "Software"), to deal
4
+ # in the Software without restriction, including without limitation the rights
5
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6
+ # copies of the Software, and to permit persons to whom the Software is
7
+ # furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in
10
+ # all copies or substantial portions of the Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18
+ # THE SOFTWARE.
19
+ #
20
+ # Made in Japan.
21
+ #++
22
+
23
+
24
+ module MilkCap::RTM
25
+
26
+ def self.auth_get_frob #:nodoc:
27
+
28
+ r = milk(:method => 'rtm.auth.getFrob')
29
+ r['frob']
30
+ end
31
+
32
+ def self.auth_get_frob_and_url #:nodoc:
33
+
34
+ frob = auth_get_frob
35
+
36
+ p = {}
37
+ p['api_key'] = ENV['RTM_API_KEY']
38
+ p['perms'] = 'delete'
39
+ p['frob'] = frob
40
+ sign(p, ENV['RTM_SHARED_SECRET'])
41
+
42
+ [
43
+ frob,
44
+ AUTH_ENDPOINT + '?' + p.collect { |k, v| "#{k}=#{v}" }.join("&")
45
+ ]
46
+ end
47
+
48
+ def self.auth_get_token (frob) #:nodoc:
49
+
50
+ begin
51
+ milk(:method => 'rtm.auth.getToken', :frob => frob)['auth']['token']
52
+ rescue Exception => e
53
+ nil
54
+ end
55
+ end
56
+
57
+ #
58
+ # ensuring the credentials are present...
59
+
60
+ unless ENV['RTM_FROB']
61
+
62
+ frob, auth_url = auth_get_frob_and_url
63
+
64
+ puts <<-EOS
65
+
66
+ please visit this URL with your browser and then hit 'enter' :
67
+
68
+ #{auth_url}
69
+
70
+ EOS
71
+
72
+ STDIN.gets
73
+ puts "ok, now getting auth token...\n"
74
+
75
+ auth_token = auth_get_token frob
76
+
77
+ if auth_token
78
+
79
+ puts <<-EOS
80
+
81
+ here are your RTM_FROB and RTM_AUTH_TOKEN, make sure to place them
82
+ in your environment :
83
+
84
+ export RTM_FROB=#{frob}
85
+ export RTM_AUTH_TOKEN=#{auth_token}
86
+
87
+ EOS
88
+ else
89
+
90
+ puts <<-EOS
91
+
92
+ couldn't get auth token, please retry...
93
+
94
+ EOS
95
+ end
96
+
97
+ exit 0
98
+ end
99
+
100
+ end
@@ -0,0 +1,326 @@
1
+ #--
2
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
3
+ # of this software and associated documentation files (the "Software"), to deal
4
+ # in the Software without restriction, including without limitation the rights
5
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
6
+ # copies of the Software, and to permit persons to whom the Software is
7
+ # furnished to do so, subject to the following conditions:
8
+ #
9
+ # The above copyright notice and this permission notice shall be included in
10
+ # all copies or substantial portions of the Software.
11
+ #
12
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18
+ # THE SOFTWARE.
19
+ #
20
+ # Made in Japan.
21
+ #++
22
+
23
+
24
+ module MilkCap::RTM
25
+
26
+ #
27
+ # A parent class for Task, List and co.
28
+ #
29
+ # Never use directly.
30
+ #
31
+ class MilkResource
32
+
33
+ def initialize (hsh)
34
+
35
+ @hsh = hsh
36
+ @operations = []
37
+ end
38
+
39
+ # Saves the instance back to RTM.
40
+ #
41
+ def save!
42
+
43
+ # TODO : compact !
44
+
45
+ @operations.reverse.each do |method_name, args|
46
+
47
+ self.class.execute method_name, args
48
+ end
49
+ @operations = []
50
+ end
51
+
52
+ protected
53
+
54
+ # a class method for listing attributes that can be found
55
+ # in the hash reply coming from RTM...
56
+ #
57
+ def self.milk_attr (*att_names) #:nodoc:
58
+
59
+ att_names.each do |att_name|
60
+ class_eval %{
61
+ def #{att_name}
62
+ @hsh['#{att_name}']
63
+ end
64
+ }
65
+ end
66
+ end
67
+
68
+ # Calls the milk() method (interacts with the RTM API).
69
+ #
70
+ def self.execute (method_name, args={})
71
+
72
+ args[:method] = "rtm.#{resource_name}.#{method_name}"
73
+
74
+ MilkCap::RTM.milk(args)
75
+ end
76
+
77
+ # Returns the name of the resource as the API knows it
78
+ # (for example 'tasks' or 'lists').
79
+ #
80
+ def self.resource_name
81
+
82
+ self.to_s.split('::')[-1].downcase + 's'
83
+ end
84
+
85
+ # Simply calls the timeline() class method.
86
+ #
87
+ def timeline
88
+
89
+ MilkResource.timeline
90
+ end
91
+
92
+ # Returns the current timeline (fetches one if none has yet
93
+ # been prepared).
94
+ #
95
+ def self.timeline
96
+
97
+ @timeline ||= MilkCap::RTM.get_timeline
98
+ end
99
+
100
+ def queue_operation (method_name, args)
101
+
102
+ @operations << [ method_name, args ]
103
+ end
104
+ end
105
+
106
+ #
107
+ # The RTM Task class.
108
+ #
109
+ class Task < MilkResource
110
+
111
+ def self.task_attr (*att_names) #:nodoc:
112
+
113
+ att_names.each do |att_name|
114
+ class_eval %{
115
+ def #{att_name}
116
+ @hsh['task']['#{att_name}']
117
+ end
118
+ }
119
+ end
120
+ end
121
+
122
+ attr_reader \
123
+ :list_id,
124
+ :taskseries_id,
125
+ :task_id,
126
+ :tags
127
+
128
+ milk_attr \
129
+ :name,
130
+ :modified,
131
+ :participants,
132
+ :url,
133
+ :notes,
134
+ :location_id,
135
+ :created,
136
+ :source
137
+
138
+ task_attr \
139
+ :completed,
140
+ :added,
141
+ :postponed,
142
+ :priority,
143
+ :deleted,
144
+ :has_due_time,
145
+ :estimate,
146
+ :due
147
+
148
+ def initialize (list_id, h)
149
+
150
+ super(h)
151
+
152
+ t = h['task']
153
+
154
+ @list_id = list_id
155
+ @taskseries_id = h['id']
156
+ @task_id = t['id']
157
+
158
+ @tags = TagArray.new(self, h['tags'])
159
+ end
160
+
161
+ # Deletes the task.
162
+ #
163
+ def delete!
164
+
165
+ self.class.execute('delete', prepare_api_args)
166
+ end
167
+
168
+ # Marks the task as completed.
169
+ #
170
+ def complete!
171
+
172
+ self.class.execute('complete', prepare_api_args)
173
+ end
174
+
175
+ # Sets the tags for the task.
176
+ #
177
+ def tags= (tags)
178
+
179
+ tags = tags.split(',') if tags.is_a?(String)
180
+
181
+ @tags = TagArray.new(list_id, tags)
182
+
183
+ queue_operation('setTasks', tags.join(','))
184
+ end
185
+
186
+ def self.find (params={})
187
+
188
+ parse_tasks(execute('getList', params))
189
+ end
190
+
191
+ # Adds a new task (and returns it).
192
+ #
193
+ def self.add! (name, opts = {})
194
+ opts = { list_id: nil, parse: true }.merge(opts)
195
+
196
+ args = {}
197
+ args[:name] = name
198
+ args[:list_id] = opts[:list_id] if opts[:list_id]
199
+ args[:timeline] = MilkCap::RTM.get_timeline
200
+ args[:parse] = 1 unless !opts[:parse]
201
+
202
+ h = execute('add', args)
203
+
204
+ parse_tasks(h)[0]
205
+ end
206
+
207
+ protected
208
+
209
+ def prepare_api_args
210
+ {
211
+ :timeline => timeline,
212
+ :list_id => list_id,
213
+ :taskseries_id => taskseries_id,
214
+ :task_id => task_id
215
+ }
216
+ end
217
+
218
+ def self.parse_tasks (o)
219
+
220
+ o = if o.is_a?(Hash)
221
+
222
+ r = o[resource_name]
223
+ o = r if r
224
+ o['list']
225
+ end
226
+
227
+ o = [ o ] unless o.is_a?(Array)
228
+ # Nota bene : not the same thing as o = Array(o)
229
+
230
+ o.inject([]) do |r, h|
231
+
232
+ list_id = h['id']
233
+ s = h['taskseries']
234
+ r += parse_taskseries(list_id, s) if s
235
+ r
236
+ end
237
+ end
238
+
239
+ def self.parse_taskseries (list_id, o)
240
+
241
+ o = [ o ] unless o.is_a?(Array)
242
+ o.collect { |s| self.new(list_id, s) }
243
+ end
244
+ end
245
+
246
+ class List < MilkResource
247
+
248
+ attr \
249
+ :list_id
250
+
251
+ milk_attr \
252
+ :name, :sort_order, :smart, :archived, :deleted, :position, :locked
253
+
254
+ def initialize (h)
255
+
256
+ super
257
+ @list_id = h['id']
258
+ end
259
+
260
+ def self.find (params={})
261
+
262
+ execute('getList', params)[resource_name]['list'].collect do |h|
263
+ self.new(h)
264
+ end
265
+ end
266
+ end
267
+
268
+ #
269
+ # An array of tasks.
270
+ #
271
+ class TagArray #:nodoc:
272
+ include Enumerable
273
+
274
+ def initialize (task, tags)
275
+
276
+ @task = task
277
+
278
+ @tags = if tags.is_a?(Array)
279
+ tags
280
+ else
281
+ tags['tag']
282
+ end
283
+ end
284
+
285
+ def << (tag)
286
+
287
+ @tags << tag
288
+
289
+ args = prepare_api_args
290
+ args[:tags] = tag
291
+
292
+ @task.queue_operation('addTags', args)
293
+ end
294
+
295
+ def delete (tag)
296
+
297
+ @tags.delete tag
298
+
299
+ args = prepare_api_args
300
+ args[:tags] = tag
301
+
302
+ @task.queue_operation('removeTags', args)
303
+ end
304
+
305
+ def clear
306
+
307
+ @tags.clear
308
+
309
+ args = prepare_api_args
310
+ args[:tags] = ''
311
+
312
+ @task.queue_operation('setTags', args)
313
+ end
314
+
315
+ def join (s)
316
+
317
+ @tags.join(s)
318
+ end
319
+
320
+ def each
321
+
322
+ @tags.each { |e| yield e }
323
+ end
324
+ end
325
+
326
+ end
@@ -0,0 +1,25 @@
1
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
2
+ # of this software and associated documentation files (the "Software"), to deal
3
+ # in the Software without restriction, including without limitation the rights
4
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5
+ # copies of the Software, and to permit persons to whom the Software is
6
+ # furnished to do so, subject to the following conditions:
7
+ #
8
+ # The above copyright notice and this permission notice shall be included in
9
+ # all copies or substantial portions of the Software.
10
+ #
11
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
14
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
15
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
16
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
17
+ # THE SOFTWARE.
18
+ #
19
+ # Made in Japan.
20
+ #++
21
+
22
+
23
+ require 'milk_cap/rtm/base'
24
+ require 'milk_cap/rtm/credentials'
25
+ require 'milk_cap/rtm/resources'
data/lib/milk_cap.rb ADDED
@@ -0,0 +1,2 @@
1
+
2
+ require 'milk_cap/rtm'
data/milk_cap.gemspec ADDED
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+ # stub: milk_cap 0.5.0 ruby lib
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "milk_cap"
9
+ s.version = "0.5.0"
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.authors = ["John Mettraux", "Jeff Leverenz"]
13
+ s.date = "2014-01-02"
14
+ s.description = "\n Yet another RememberTheMilk wrapper, successor to rufus-rtm.\n "
15
+ s.email = "jeff.leverenz@gmail.com"
16
+ s.extra_rdoc_files = [
17
+ "LICENSE.txt",
18
+ "README.rdoc"
19
+ ]
20
+ s.files = [
21
+ "CHANGELOG.txt",
22
+ "LICENSE.txt",
23
+ "README.rdoc",
24
+ "Rakefile",
25
+ "lib/milk_cap.rb",
26
+ "lib/milk_cap/rtm.rb",
27
+ "lib/milk_cap/rtm/base.rb",
28
+ "lib/milk_cap/rtm/credentials.rb",
29
+ "lib/milk_cap/rtm/resources.rb",
30
+ "milk_cap.gemspec",
31
+ "test/tasks_test.rb",
32
+ "test/test.rb"
33
+ ]
34
+ s.homepage = "http://github.com/jleverenz/milk_cap/"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "2.1.11"
38
+ s.summary = "Yet another RememberTheMilk wrapper, successor to rufus-rtm."
39
+ s.test_files = ["test/test.rb"]
40
+
41
+ if s.respond_to? :specification_version then
42
+ s.specification_version = 4
43
+
44
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<rufus-verbs>, [">= 1.0.0"])
46
+ s.add_development_dependency(%q<yard>, [">= 0"])
47
+ else
48
+ s.add_dependency(%q<rufus-verbs>, [">= 1.0.0"])
49
+ s.add_dependency(%q<yard>, [">= 0"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<rufus-verbs>, [">= 1.0.0"])
53
+ s.add_dependency(%q<yard>, [">= 0"])
54
+ end
55
+ end
56
+
@@ -0,0 +1,113 @@
1
+ require 'rubygems'
2
+
3
+ require 'test/unit'
4
+
5
+ $: << File.dirname(__FILE__) + '/../lib'
6
+
7
+ require 'milk_cap/rtm'
8
+
9
+ include MilkCap::RTM
10
+
11
+
12
+ class TasksTest < Test::Unit::TestCase
13
+
14
+ #def setup
15
+ #end
16
+
17
+ #def teardown
18
+ #end
19
+
20
+ def test_0
21
+
22
+ taskname = "milk the cow #{Time.now.to_i}"
23
+
24
+ t0 = Task.add!(taskname)
25
+
26
+ assert_kind_of Task, t0
27
+ assert_equal taskname, t0.name
28
+
29
+ ts = Task.find
30
+
31
+ #puts "tasks : #{ts.size}"
32
+
33
+ t1 = ts.find { |t| t.task_id == t0.task_id }
34
+ assert_equal taskname, t1.name
35
+ assert_equal '', t1.tags.join(',')
36
+
37
+ ts = Task.find :filter => "status:incomplete"
38
+
39
+ #puts "incomplete tasks : #{ts.size}"
40
+
41
+ t1 = ts.find { |t| t.task_id == t0.task_id }
42
+ assert_equal taskname, t1.name
43
+
44
+ t1.delete!
45
+
46
+ ts = Task.find :filter => "status:incomplete"
47
+
48
+ t1 = ts.find { |t| t.task_id == t0.task_id }
49
+ assert_nil t1
50
+ end
51
+
52
+ def test_1
53
+
54
+ lists = List.find
55
+ assert_not_nil(lists.find { |e| e.name == 'Inbox' })
56
+
57
+ work = lists.find { |e| e.name == 'Work' }
58
+
59
+ taskname = "more work #{Time.now.to_i}"
60
+
61
+ t0 = Task.add! taskname, :list_id => work.list_id
62
+
63
+ tasks = Task.find :list_id => work.list_id, :filer => 'status:incomplete'
64
+
65
+ assert_not_nil(tasks.find { |t| t.task_id == t0.task_id })
66
+
67
+ t0.complete!
68
+
69
+ tasks = Task.find :list_id => work.list_id, :filer => 'status:completed'
70
+ assert_not_nil(tasks.find { |t| t.task_id == t0.task_id })
71
+
72
+ t0.delete!
73
+ end
74
+
75
+ def test_2
76
+
77
+ key = ENV.delete('RTM_API_KEY')
78
+ secret = ENV.delete('RTM_SHARED_SECRET')
79
+
80
+ assert_raise RuntimeError do
81
+ lists = List.find
82
+ end
83
+
84
+ assert_not_nil List.find(:api_key => key, :shared_secret => secret)
85
+
86
+ ENV['RTM_API_KEY'] = key
87
+ ENV['RTM_SHARED_SECRET'] = secret
88
+ end
89
+
90
+ def test_smart_add
91
+ taskname = "more work #{Time.now.to_i}"
92
+ smart_add_string = "#{taskname} tomorrow"
93
+ task = Task.add! smart_add_string
94
+
95
+ tasks = Task.find
96
+
97
+ task_created = tasks.find { |t| t.task_id == task.task_id }
98
+ assert !task_created.due.empty?
99
+ assert_equal taskname, task_created.name # 'tomorrow' is stripped as due date
100
+ end
101
+
102
+ def test_turn_smart_add_off
103
+ taskname = "more work #{Time.now.to_i} tomorrow"
104
+ task = Task.add! taskname, :parse => false
105
+
106
+ tasks = Task.find
107
+
108
+ task_created = tasks.find { |t| t.task_id == task.task_id }
109
+ assert task_created.due.empty?
110
+ assert_equal taskname, task_created.name
111
+ end
112
+
113
+ end
data/test/test.rb ADDED
@@ -0,0 +1,3 @@
1
+
2
+ Dir["#{File.dirname(__FILE__)}/*_test.rb"].each { |path| load(path) }
3
+
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: milk_cap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ platform: ruby
6
+ authors:
7
+ - John Mettraux
8
+ - Jeff Leverenz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-01-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rufus-verbs
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: 1.0.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ! '>='
26
+ - !ruby/object:Gem::Version
27
+ version: 1.0.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: yard
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ! '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description: ! "\n Yet another RememberTheMilk wrapper, successor to rufus-rtm.\n
43
+ \ "
44
+ email: jeff.leverenz@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files:
48
+ - LICENSE.txt
49
+ - README.rdoc
50
+ files:
51
+ - CHANGELOG.txt
52
+ - LICENSE.txt
53
+ - README.rdoc
54
+ - Rakefile
55
+ - lib/milk_cap.rb
56
+ - lib/milk_cap/rtm.rb
57
+ - lib/milk_cap/rtm/base.rb
58
+ - lib/milk_cap/rtm/credentials.rb
59
+ - lib/milk_cap/rtm/resources.rb
60
+ - milk_cap.gemspec
61
+ - test/tasks_test.rb
62
+ - test/test.rb
63
+ homepage: http://github.com/jleverenz/milk_cap/
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.1.11
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Yet another RememberTheMilk wrapper, successor to rufus-rtm.
87
+ test_files:
88
+ - test/test.rb