Class: IcalTodoRssServlet

Inherits:
WEBrick::HTTPServlet::AbstractServlet
  • Object
show all
Defined in:
lib/vpim/agent/scraps.rb

Instance Method Summary collapse

Instance Method Details

#do_GET(req, resp) ⇒ Object

Raises:

  • (WEBrick::HTTPStatus::OK)


208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/vpim/agent/scraps.rb', line 208

def do_GET(req, resp)   
  rss = RSS::Maker.make("0.9") do |maker|
    title = $ics_todo_title
    link = 'http:///'
    maker.channel.title = title
    maker.channel.link = link
    maker.channel.description = title
    maker.channel.language = 'en-us'

    # These are required, or RSS::Maker silently returns nil!
    maker.image.url = "maker.image.url"
    maker.image.title = "maker.image.title"

    Dir[ $ical_folder + "/*.ics" ].each do |file|
      # TODO: use the open with a block variant
      Vpim::Icalendar.decode(File.open(file)).each do |cal|
        cal.todos.each do |todo|
          if !todo.status || todo.status.upcase != "COMPLETED"
            item = maker.items.new_item
            item.title = todo.summary
            item.link =  todo.properties['url'] || link
            item.description = todo.description || todo.summary
          end
        end
      end
    end
  end

  resp.body = rss.to_s
  resp['content-type'] = 'text/xml'

  raise WEBrick::HTTPStatus::OK
end