Class: VcfBdayIcsServlet

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)


105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/vpim/agent/scraps.rb', line 105

def do_GET(req, resp)
  cal = Vpim::Icalendar.create

  open($vcf_bday_file) do |vcf|
    Vpim::Vcard.decode(vcf).each do |card|
      begin
        bday = card.birthday
        if bday
          cal.push Vpim::Icalendar::Vevent.create_yearly(
            card.birthday,
            "Birthday for #{card['fn'].strip}"
            )
          $stderr.puts "#{card['fn']} -> bday #{cal.events.last.dtstart}"
        end
      rescue
        $stderr.puts $!
        $stderr.puts $!.backtrace.join("\n")
      end
    end
  end

  resp.body = cal.encode
  resp['content-type'] = 'text/calendar'

  # Is this necessary, or is it default?
  raise WEBrick::HTTPStatus::OK
end