{"id":554,"date":"2008-02-23T12:06:21","date_gmt":"2008-02-23T17:06:21","guid":{"rendered":"http:\/\/blogs.n1zyy.com\/n1zyy\/2008\/02\/23\/dork\/"},"modified":"2008-02-23T12:06:21","modified_gmt":"2008-02-23T17:06:21","slug":"dork","status":"publish","type":"post","link":"https:\/\/blogs.n1zyy.com\/n1zyy\/2008\/02\/23\/dork\/","title":{"rendered":"Dork"},"content":{"rendered":"<p>Yesterday was, for all intents and purposes, a snow day. They closed the school down at 1. Of course, I had no classes anyway, just some work that could be done anywhere. But this was a <em>snow day<\/em>. You don&#8217;t do work. At least, not the work you&#8217;re supposed to.<\/p>\n<p>Kyle, always being curious about the hardware side of things, sent me a link to the <a href=\"http:\/\/\">RoomWizard<\/a> downloads page after fishing out the hardware specs elsewhere. There were two things that interested me&#8211;one was that you could download a firmware image. The other was that they had a PDF of how to use their API.<\/p>\n<p>Wait&#8230; API? That means&#8230; it&#8217;d be trivial to write an interface to these things!<\/p>\n<p>The problem is that the manual never mentions the actual address of the API, which is just accessed over HTTP and returns XML. They give a few examples&#8211;\/rwconnector is used most often. But alas, \/rwconnector on these throws a 404.<\/p>\n<p>Somewhat discouraged, I started poking around the firmware image. It&#8217;s a .tar.gz, and extracts&#8230; a (fairly) normal Linux filesystem. Besides some juicy stuff that I hope admins are instructed to change (there are several privileged user accounts), I also found some neat stuff. For one, it&#8217;s based on SuSE, but a very trimmed-down version. And it&#8217;s basically a full-functioning Linux machine, including an SMTP server, Apache Tomcat, etc.<\/p>\n<p>But then I hit gold. There&#8217;s a configuration file for Tomcat, which mentions one URL of \/Connector. So I fired it up and tried it in on one of the systems. Bingo!<\/p>\n<p>So then I read a bit more of the API manual. It&#8217;s actually very simple&#8211;you can retrieve, edit, and delete bookings. (The edit and booking doesn&#8217;t let you do anything you can&#8217;t do via the web interface, by the way, lest anyone think this is a security flaw.) You get an XML document back with results.<\/p>\n<p>So then I had to figure out how to get PHP to parse XML. It turns out that PHP actually has <em>several<\/em> ways to do it, including SimpleXML and DOM objects. I spent a while learning it and by the end of the day, I had a prototype working that would get reservations for the next 24 hours and parse out the information. (Small tip&#8211;don&#8217;t try to &#8220;escape&#8221; colons when dealing with XML. They denote a namespace. When you get rb:name, for example, the tag name is just <em>name<\/em>, in the rb namespace. Knowing this a little sooner would have saved me about half an hour of, &#8220;This code is so simple! Why doesn&#8217;t it work?!&#8221;)<\/p>\n<p>The next step is to insert all of this into an SQL database, and then write a nice viewer for it. And also to experiment with adding bookings, although that should just require changing a line of code.<\/p>\n<p>I haven&#8217;t actually written code to do timing, but it feels like it&#8217;s 1-2 seconds for me to get the XML data back, which suggests that the bottleneck is in its little database. Short-term, I want to write myself a little interface that will parse all the data, cache it, and give me a faster interface. Long-term, I want to try to see if I can get the library to adopt this, and have <em>it<\/em> be the booking mechanism. You can store them to a local database, and then have a background process use the API to push reservations out to the respective RoomWizards, so that they continue to function normally. But when people view the page, it&#8217;ll just get it all from the local database, meaning that the whole &#8220;Get the listings via API&#8221; thing is no longer necessary. (Unless you want to rebuild the database in case of a disk failure!)<\/p>","protected":false},"excerpt":{"rendered":"<p>Yesterday was, for all intents and purposes, a snow day. They closed the school down at 1. Of course, I had no classes anyway, just some work that could be done anywhere. But this was a snow day. You don&#8217;t &hellip; <a href=\"https:\/\/blogs.n1zyy.com\/n1zyy\/2008\/02\/23\/dork\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4,10,18,19,22,26],"tags":[],"class_list":["post-554","post","type-post","status-publish","format-standard","hentry","category-business","category-computers","category-ideas","category-ocd","category-performance","category-programming","category-school"],"_links":{"self":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/554","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/comments?post=554"}],"version-history":[{"count":0,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/554\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/media?parent=554"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/categories?post=554"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/tags?post=554"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}