thartm 0.0.22 → 0.0.23

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.
Files changed (5) hide show
  1. data/README.rdoc +252 -1
  2. data/Rakefile +1 -1
  3. data/VERSION +1 -1
  4. data/lib/thartm.rb +1 -1
  5. metadata +3 -3
data/README.rdoc CHANGED
@@ -3,7 +3,9 @@
3
3
  Remember the milk command line interface
4
4
 
5
5
  using rtmapi library
6
- patched to work with the new version of ruby-libxml
6
+ patched to work with the new version of ruby-libxml ( libxml version > 2.7)
7
+ if you're using an older version of libxml please refer to the old
8
+ (and maybe better..) rtmapi gem.
7
9
 
8
10
  To make the cli work you have to obtain an api key
9
11
  and an api secret for remember the milk.
@@ -49,3 +51,252 @@ Mail me at: thamayor [at] gmail [dot] com
49
51
 
50
52
 
51
53
 
54
+
55
+ =========== OLD readme from rtmapi gem ==========
56
+ NOTICE: v0.4+ breaks the API written for v0.3. In order to speed
57
+ things up (a lot), I no longer use the REXML parser, but do it with
58
+ libxml. And I turn string keys into symbols, except for rtm_ids.
59
+ If none of this paragraph makes sense to you, just read on...
60
+
61
+ This is a very bare bones API for Remember the Milk that does a minimum
62
+ of error checking but should be good enough.
63
+
64
+ This is also a bare bones explanation of the Ruby portion.
65
+
66
+ You need to read http://www.rememberthemilk.com/services/api/
67
+ and familiarize yourself with the RTM API.
68
+
69
+ The purpose of this code is to take care of all the grunt work in
70
+ interacting with the API. The rest of this document assumes you know
71
+ how to use Ruby, have a net connection, etc.
72
+
73
+ To get started, you'll need
74
+
75
+ 0. libxml installed. if you are reasonably lucky, a simple
76
+ sudo gem install libxml-ruby
77
+ will do the trick. If that fails, you probably need other packages
78
+ (see http://libxml.rubyforge.org/install.html for more info)
79
+
80
+ You may also want to install tzinfo (sudo gem install tzinfo)
81
+
82
+ 1. An RTM API KEY. See: http://www.rememberthemilk.com/services/api/keys.rtm
83
+
84
+ You'll get back an email with an API_KEY and an API_SHARED_SECRET
85
+
86
+ 2. Here's a program to test if your API key is any good. I suggest
87
+ just doing this in irb.
88
+
89
+ require 'rtmapi'
90
+
91
+ rtm = RememberTheMilk.new( "YOUR_API_KEY", "YOUR_API_SHARED_SECRET" )
92
+ echo_data = rtm.test.echo( 'my_arg_1' => 'my_value_1', 'foo' => 'bar' )
93
+
94
+ echo_data.my_arg_1 # should be 'my_value_1'
95
+ echo_data.foo # should be 'bar'
96
+
97
+ method_names = rtm.reflection_getMethods()
98
+ methods_names.size # as of now (Jun 28, 2006), there are 47 methods...
99
+
100
+ 3. Getting an authorization token.
101
+
102
+ In order to do anything interesting with the API, you have to get a token
103
+ that authorizes you to manipulate the data in an account. The API documentation covers the different modes of authentication at
104
+ http://www.rememberthemilk.com/services/api/authentication.rtm
105
+ (you can skip past "signing requests" -- the API takes care of that for you)
106
+
107
+ Here's a program to print out a URL that you can go to in your browser.
108
+ This will let you get a Token you can use for programming.
109
+
110
+ require 'rtmapi'
111
+ rtm = RememberTheMilk.new( "YOUR_API_KEY", "YOUR_API_SHARED_SECRET" )
112
+ puts rtm.auth_url # returns http://......
113
+
114
+
115
+ if you visit that URL in your browser, you'll be asked to authorize. After
116
+ doing so, you'll either be given a frob value or, if you specified a
117
+ callback URL, your browser will be redirected there with a frob=XXXX paramater
118
+ appended on.
119
+
120
+ you can then take that frob and get an auth token (and store it in a DB or
121
+ whereever)
122
+
123
+ require 'rtmapi'
124
+ rtm = RememberTheMilk.new( "YOUR_API_KEY", "YOUR_API_SHARED_SECRET" )
125
+ auth = rtm.auth.getToken( 'frob' => FROB_VALUE_YOU_WERE_GIVEN )
126
+
127
+ auth.token # the token (also, auth[:token] would work)
128
+ auth.perms # the perms it has (default is 'delete')
129
+ auth.user # a hash of the user object (id, username, fullname)
130
+
131
+
132
+ Return Values
133
+ -------------
134
+
135
+ The Ruby API library tends to return RememberTheMilkHash objects (except for tasks,
136
+ see below).
137
+
138
+ These are like normal hashes, except they implement convenience methods. They also
139
+ expect most of their keys to be symbols, except for when rtm_id's are used as keys
140
+ E.g.,
141
+
142
+ hash = RememberTheMilkHash.new
143
+ hash[:a_key] = 6
144
+ hash.a_key # returns 6
145
+ hash.a_key = 4
146
+ hash.a_key # returns 4
147
+
148
+ lists = @rtm.lists.getList
149
+ lists.keys => ['43254','23424','23424']
150
+ lists['43254'].rtm_id => '43254'
151
+
152
+ Note, you can't initially set a value using the convenience methods, and if
153
+ you access one for which there is no key, it'll throw an exception.
154
+
155
+ Also, if you want to access a parameter that is already a ruby keyword
156
+ (e.g., 'methods'), you'll have to use the standard hash accessors:
157
+
158
+ hash['methods'] will work
159
+ hash.methods will NOT work (you'll get a list of methods that work on a RememberTheMilkHash)
160
+
161
+ [for id specifically, I created a helper method, rtm_id, so
162
+ hash.rtm_id will work and overrode 'id' so that if there is
163
+ an rtm_id, you get that, otherwise you get the object id. And
164
+ 'id' is deprecated, so I don't feel too guilty about that.]
165
+
166
+ In general, you can look at the API to get a sense of whether the ruby
167
+ code will return a Hash, an Array, a String, or a boolean. Also, you
168
+ can look at the test code.
169
+
170
+ If you want to be able to dereference non-existant keys without having
171
+ an exception thrown (dangerous for coding!), do:
172
+ RememberTheMilkHash::strict_keys = false
173
+ and you're all set.
174
+
175
+ For many of the write methods (e.g., rtm.contacts.add), a transaction id
176
+ and the newly written object are returned by the RTM API. I used to just have the
177
+ Ruby wrapper just returns the transaction id info, throwing away whatever the
178
+ particular object is. Now, it returns the modified object with an additional
179
+ element in the hash 'rtm_transaction' which contains a hash of info about the
180
+ transaction (the id and if it is undoable)
181
+
182
+ The test code itself is a little fragile, as it assumes it is accessing a
183
+ particular account that your API key can't access. To get around this,
184
+ I created a cache of the returned data from RTM. This means that the tests
185
+ for you won't contact the RTM server, so you'll have to trust that the
186
+ net communication part works :)
187
+
188
+ Tasks
189
+ -----
190
+
191
+ Tasks get put into a RememberTheMilkTask, which is just this:
192
+
193
+ class RememberTheMilkTask < RememberTheMilkHash
194
+ end
195
+
196
+ But this will allow you to add special functionality to tasks
197
+ (e.g., mixin Enumerable and define <=> based on whatever rules you'd
198
+ like). If there is interest, we can do the same thing for
199
+ groups, lists, etc etc.
200
+
201
+ RememberTheMilkTask also has a number of helper methods, so you can
202
+ do this:
203
+
204
+ task = @rtm.tasks.getList.values[0].values[0] # grabs 1st task off of first list returned by API
205
+ modified_task = task.setTags "tag1,tag2"
206
+ modified_task_2 = modified_task.addTags "tag3"
207
+ modified_task.tags => ['tag1','tag2']
208
+ modified_task_2.tags => ['tag1','tag2', 'tag3']
209
+
210
+ all the methods for rtm.tasks.* have helper methods defined (except for getList)
211
+
212
+ Dates
213
+ -----
214
+
215
+ For now, I convert incoming due dates in tasks to a Time object. I don't
216
+ bother converting all the other dates, but if someone needs those converted
217
+ too, let me know. To convert a Time object to a string RTM expects, do
218
+ Time.now.iso8601 # now time in RTM-expected format (ISO-8601)
219
+
220
+ To convert an ISO-8601 time to a Time object, do Time.parse(string):
221
+ now = Time.now
222
+ now == Time.parse( now.iso8601 )
223
+
224
+ For more info, see http://www.rememberthemilk.com/services/api/dates.rtm
225
+
226
+ RTM will keep track the users' local timezone. The API can do this automatically,
227
+ but you need to require the tzinfo lib first. See: http://tzinfo.rubyforge.org/
228
+ for more info. The default is to give parsed dates in the user's local timezone
229
+ if tzinfo has been required. If you are writing a rails app, I recommend
230
+ putting the tzinfo stuff under ~/lib (along with rtm.rb), and in your environment.rb,
231
+ add this:
232
+ ActiveRecord::Base.default_timezone = :utc # Store all times in the db in UTC
233
+ ENV['TZ'] = 'UTC' # This makes Time.now return time in UTC
234
+
235
+ (I did my testing with tzinfo-0.3.3)
236
+
237
+ Incidentally, at the moment,
238
+ rtm.tasks.setDueDate assumes the date is in the user's timezone when it
239
+ is running with :parse => 1
240
+ The RTM folks may change this behavior in the future.
241
+
242
+ If you don't want dates converted to the user's local TZ, do
243
+ @rtm.use_user_tz = false
244
+
245
+ For now, we cache a user's timezone info (cache index is keyed off of auth_token)
246
+ so it's not too painful to convert a ton of dates. You can call @rtm.logout(auth_token)
247
+ to erase the cache for that user. I need to make that a cleaner interface.
248
+
249
+ Exceptions
250
+ ----------
251
+
252
+ If the RTM API returns an error, the Ruby API throws a RememberTheMilkError.
253
+ There are getters for the raw XML response, the parsed error code
254
+ and the parsed message:
255
+
256
+ error.response # returns a REXML element
257
+ error.error_code # returns a FixNum
258
+ error.message # returns a string
259
+
260
+
261
+
262
+ Debugging
263
+ ---------
264
+ To see copious debugging output,
265
+ rtm.debug = true
266
+
267
+ This will show you the method calls being made, how they are being packaged,
268
+ and what the raw (XML) response from the server is.
269
+
270
+
271
+ Other stuff
272
+ -----------
273
+
274
+ 1. I made heavy use of method_missing so you could write nice looking method
275
+ calls. E.g.,
276
+ rtm.reflection.getMethods()
277
+
278
+ instead of
279
+
280
+ rtm.call_api_method( 'reflection.getMethods' )
281
+
282
+ As long as the RTM API doesn't conflict with Ruby keywords, we should be all
283
+ set. You can always directly invoke call_api_method() if you need/want to.
284
+
285
+ 2. You can use symbols or strings in a RTM method call, and if you
286
+ use a Fixnum, it gets converted to a string.
287
+ so, these are all equivalent:
288
+ rtm.test.echo( 'arg1' => 'value1', 'arg2' => '666', 'arg3' => 'foobar' )
289
+ rtm.test.echo( :arg1 => 'value1', :arg2 => 666, :arg3 => :foobar )
290
+ rtm.test.echo( :arg1 => 'value1', 'arg2' => 666, 'arg3' => :foobar )
291
+
292
+ (We just blindly call to to_s() on every argument to package it up for a
293
+ method call to the RTM API)
294
+
295
+ Other questions/comments/complaints?
296
+ ------------------------------------
297
+
298
+ Email me at yanowitz+rtmapi AT gmail
299
+
300
+ PS: Many thanks to the good folks at RTM for a very useful product!
301
+ If you come up with interesting uses for this API, please drop me a
302
+ line. Thanks.
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ begin
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "thartm"
8
8
  gem.summary = %Q{rtmapi based remember the milk cli.}
9
- gem.description = %Q{rtmapi fixed version with a simple cli added}
9
+ gem.description = %Q{rtmapi fixed version with a simple cli added, rtmapi package fixed to work with libxml2 version > 2.7}
10
10
  gem.email = "thamayor@gmail.com"
11
11
  gem.homepage = "http://github.com/ghedamat/thartm"
12
12
  gem.authors = ["tha"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.22
1
+ 0.0.23
data/lib/thartm.rb CHANGED
@@ -11,7 +11,7 @@ class Rrtm
11
11
  #@rtm = ThaRememberTheMilk.new(@@config['key'],@@config['secret'],@@config['token'])
12
12
  @rtm = ThaRememberTheMilk.new(key,secret,token)
13
13
  @rtm.use_user_tz = true
14
- @rtm.debug = true
14
+ @rtm.debug = false
15
15
 
16
16
  # id of the all tasks list
17
17
  @allTaskList = String.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thartm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
4
+ version: 0.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - tha
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-06-07 00:00:00 +02:00
12
+ date: 2010-06-08 00:00:00 +02:00
13
13
  default_executable: rrtm
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -72,7 +72,7 @@ dependencies:
72
72
  - !ruby/object:Gem::Version
73
73
  version: "0"
74
74
  version:
75
- description: rtmapi fixed version with a simple cli added
75
+ description: rtmapi fixed version with a simple cli added, rtmapi package fixed to work with libxml2 version > 2.7
76
76
  email: thamayor@gmail.com
77
77
  executables:
78
78
  - rrtm