Class: Kaede::SyoboiCalendar

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

Defined Under Namespace

Classes: HttpError

Constant Summary collapse

HOST =
'cal.syoboi.jp'
PORT =
80

Instance Method Summary collapse

Constructor Details

#initializeSyoboiCalendar

Returns a new instance of SyoboiCalendar.



20
21
22
# File 'lib/kaede/syoboi_calendar.rb', line 20

def initialize
  @http = Net::HTTP.new(HOST, PORT)
end

Instance Method Details

#cal_chk(params = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/kaede/syoboi_calendar.rb', line 24

def cal_chk(params = {})
  path = '/cal_chk.php'
  q = params.map { |k, v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}" }.join('=')
  if !q.empty?
    path += '?' + q
  end
  res = @http.get(path)
  case res
  when Net::HTTPOK
    Program.from_xml(Nokogiri::HTML.parse(res.body))
  else
    raise HttpError.new(res)
  end
end