blib/script/DummyServer.pl untested

filter: Statementstmt 0.0% 0 / 101 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 9 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 139 CC 9 SCAR 37.3
CC
9
Cov
0%
main
90.0
BEGIN
2.0
BEGIN
2.0
CRAP 41.6
1 #!/usr/bin/env perl -w # -*- cperl; cperl-indent-level: 4 -*-
2 ## no critic qw(ProhibitCallsToUnexportedSubs RestrictLongStrings ProhibitImplicitNewlines RequireASCII)
3 use strict;
4 use warnings;
5  
6 use utf8;
7 use 5.014000;
8  
9 our $VERSION = '0.100';
10  
11 use CGI qw/:all/;
12 use Getopt::Long;
13 use HTTP::Server::Brick;
14 use HTTP::Status qw(:constants status_message);
15 use Pod::Usage;
16 use Pod::Usage::CommandLine;
17  
18 use Readonly;
19 Readonly::Scalar my $EMPTY => q{};
20 Readonly::Scalar my $SPACE => q{ };
21 Readonly::Scalar my $SLASH => q{/};
22 Readonly::Scalar my $FALLBACK_OUTPUT => q{PHP};
23 Readonly::Scalar my $CONNECTOR_PORT => 18_081;
24 Readonly::Scalar my $MAX_REQUESTS => 100;
25 Readonly::Scalar my $API_KEY => q{TEST};
26 Readonly::Scalar my $API_VERSION => q{v1};
27 Readonly::Scalar my $CHARSET => q{; charset=utf-8};
28 Readonly::Scalar my $ROOT => qq{/$API_VERSION/};
29 Readonly::Scalar my $STRIP_QUERY => qr{^/[?]}sxm;
30  
31 Readonly::Array my @GETOPT_CONFIG =>
32 qw(no_ignore_case bundling auto_version auto_help);
33 Readonly::Array my @GETOPTIONS => ( q{port|p=s}, q{verbose|v+}, );
34 Readonly::Hash my %OPTS_DEFAULT => ( 'port' => $CONNECTOR_PORT, );
35 Readonly::Hash my %OUTPUT => (
36 'json' => q{application/json},
37 'xml' => q{text/xml},
38 'php' => q{text/plain},
39 );
40 Readonly::Hash my %RESPONSE => (
41 'version' => {
42 'json' => q{{
43 "version": [
44 {
45 "version": "v1",
46 "build": "0.0.1"
47 }
48 ]
49 }},
50 'xml' => q{<?xml version="1.0" encoding="UTF-8"?>
51 <list type="version" itemcount="1">
52 <item>
53 <version><![CDATA[v1]]></version>
54 <build><![CDATA[0.0.1]]></build>
55 </item>
56 </list>},
57 'php' =>
58 q{a:1:{s:7:"version";a:1:{i:0;a:2:{s:7:"version";s:2:"v1";s:5:"build";s:5:"0.0.1";}}}},
59 },
60 'latest_article' => {
61 'json' => q{{
62 "latest_article": [
63 [
64 {
65 "id": "156833"
66 "type": "article",
67 "title": "Zeker honderd doden bij vliegramp in Tripoli"
68 "description": "Bij een vliegtuigongeluk op de luchthaven van de Libische hoofdstad Tripoli zouden 103 doden zijn gevallen."
69 "published": "2010-05-12 10:26:00"
70 "last_update": "2010-05-12 09:11:04"
71 "thumbnail_xs": http://content.nos.nl/data/image/xs/2010/07/30/175416.jpg
72 "thumbnail_s": http://content.nos.nl/data/image/s/2010/07/30/175416.jpg
73 "thumbnail_m": http://content.nos.nl/data/image/m/2010/07/30/175416.jpg
74 "link": http://nos.nl/artikel/156833-zeker-honderd-doden-bij-vliegramp-in-tripoli.html
75 "keywords": [
76 "libië"
77 "doden"
78 "tripoli"
79 "vliegtuig"
80 "crash"
81 "Seizoen 2009/2010"
82 ]
83 },
84 {
85 "id": "156845"
86 "type": "article",
87 "title": "Groei Nederlandse economie neemt af"
88 "description": "De Nederlandse economie is in het eerste kwartaal van het jaar gegroeid, maar de groei is lager dan in de twee voorgaande kwartalen."
89 "published": "2010-05-12 10:06:02"
90 "last_update": "2010-05-12 10:11:04"
91 "thumbnail_xs": http://content.nos.nl/data/image/xs/2010/07/30/175416.jpg
92 "thumbnail_s": http://content.nos.nl/data/image/s/2010/07/30/175416.jpg
93 "thumbnail_m": http://content.nos.nl/data/image/m/2010/07/30/175416.jpg
94 "link": http://nos.nl/artikel/156845-groei-nederlandse-economie-neemt-af.html
95 "keywords": [
96 "economie"
97 "cbs"
98 "kwartaalcijfers"
99 "groei"
100 ]
101 }
102 ]
103 ]}},
104 'xml' => q{<?xml version="1.0" encoding="UTF-8"?>
105 <list type="article" itemcount="10">
106 <article>
107 <id>175418</id>
108 <type>article</type>
109 <title><![CDATA[Geen schot in Belgische formatie]]></title>
110 <description><![CDATA[In België is er anderhalve maand na de verkiezingen nog geen zicht op de vorming van een kabinet.]]></description>
111 <published><![CDATA[2010-07-30 20:29:04]]></published>
112 <last_update><![CDATA[2010-07-30 20:35:06]]></last_update>
113 <thumbnail_xs><![CDATA[http://content.nos.nl/data/image/xs/2010/05/25/159715.jpg]]></thumbnail_xs>
114 <thumbnail_s><![CDATA[http://content.nos.nl/data/image/s/2010/05/25/159715.jpg]]></thumbnail_s>
115 <thumbnail_m><![CDATA[http://content.nos.nl/data/image/m/2010/05/25/159715.jpg]]></thumbnail_m>
116 <link><![CDATA[http://nos.nl/artikel/175418-geen-schot-in-belgische-formatie.html]]></link>
117 <keywords>
118 <keyword><![CDATA[belgië]]></keyword>
119 <keyword><![CDATA[Vlaanderen]]></keyword>
120 <keyword><![CDATA[Elio di Rupo]]></keyword>
121 <keyword><![CDATA[kabinetsformatie]]></keyword>
122 </keywords>
123 </article>
124 </list>},
125 },
126 'latest_video' => {
127 'json' => q{{
128 "latest_video": [
129 [
130 {
131 "id": "175327"
132 "type": "video",
133 "title": "28 doden door bosbranden Rusland"
134 "description": "In Rusland zijn bij bosbranden zeker 28 doden gevallen. Veel huizen zijn in vlammen opgegaan, en duizenden mensen zijn geëvacueerd. Rusland heeft te kampen met de heetste zomer in ruim honderd jaar. Door de extreme droogte is de natuur extra kwetsbaar voor bosbranden."
135 "published": "2010-07-30 22:25:06"
136 "last_update": "2010-07-30 15:43:07"
137 "thumbnail_xs": http://content.nos.nl/data/video/xs/2010/07/30/300710_18_zui-CNO1007300Z_1.jpg
138 "thumbnail_s": http://content.nos.nl/data/video/s/2010/07/30/300710_18_zui-CNO1007300Z_1.jpg
139 "thumbnail_m": http://content.nos.nl/data/video/m/2010/07/30/300710_18_zui-CNO1007300Z_1.jpg
140 "link": http://nos.nl/video/175327-28-doden-door-bosbranden-rusland.html
141 "embedcode": "<object width="550" height="309"><param name="movie" value="http://s.nos.nl/swf/embed/nos_partner_video.swf?tcmid=tcm-5-776295&amp;platform=open&amp;partner=user"></param><param name="wmode" value="transparent"></param><param name="allowScriptAccess" value="always"></param><param name="allowfullscreen" value="true"></param><embed src="http://s.nos.nl/swf/embed/nos_partner_video.swf?tcmid=tcm-5-776295&amp;platform=open&amp;partner=user" type="application/x-shockwave-flash" wmode="transparent" width="550" height="309" allowfullscreen="true" allowScriptAccess="always"></embed></object>"
142 "keywords": [
143 "bosbranden"
144 "droogte"
145 "hitte"
146 "Rusland"
147 ]
148 },
149 {
150 "id": "175424"
151 "type": "video",
152 "title": "Duisburg verwacht tienduizenden bezoekers rouwdienst"
153 "description": "Duisburg maakt zich op voor een dag van rouw. Morgen wordt het drama met de Love Parade van vorige week herdacht. Daarbij vielen 21 doden. Om elf uur begint de rouwdienst, waarbij bondskanselier Angela Merkel aanwezig is en naar verwachting tienduizenden rouwenden, misschien zelfs wel 100.000. Sommige inwoners van Duisburg zien dat met angst tegemoet."
154 "published": "2010-07-30 20:55:06"
155 "last_update": "2010-07-30 21:05:08"
156 "thumbnail_xs": http://content.nos.nl/data/video/xs/2010/07/30/300710_18_zui-CNO1007300Z_1.jpg
157 "thumbnail_s": http://content.nos.nl/data/video/s/2010/07/30/300710_18_zui-CNO1007300Z_1.jpg
158 "thumbnail_m": http://content.nos.nl/data/video/m/2010/07/30/300710_18_zui-CNO1007300Z_1.jpg
159 "link": http://nos.nl/video/175424-duisburg-verwacht-tienduizenden-bezoekers-rouwdienst.html
160 "embedcode": "<object width="550" height="309"><param name="movie" value="http://s.nos.nl/swf/embed/nos_partner_video.swf?tcmid=tcm-5-776295&amp;platform=open&amp;partner=user"></param><param name="wmode" value="transparent"></param><param name="allowScriptAccess" value="always"></param><param name="allowfullscreen" value="true"></param><embed src="http://s.nos.nl/swf/embed/nos_partner_video.swf?tcmid=tcm-5-776295&amp;platform=open&amp;partner=user" type="application/x-shockwave-flash" wmode="transparent" width="550" height="309" allowfullscreen="true" allowScriptAccess="always"></embed></object>"
161 "keywords": [
162 "herdenking"
163 "Duisburg"
164 "Duitsland"
165 "rouwdienst"
166 "Love Parade"
167 ]
168 }
169 ]
170 ]
171 }},
172 'xml' => q{<?xml version="1.0" encoding="UTF-8"?>
173 <list type="latest_video" itemcount="2">
174 <video>
175 <id>175327</id>
176 <type>video</type>
177 <title><![CDATA[28 doden door bosbranden Rusland]]></title>
178 <description><![CDATA[In Rusland zijn bij bosbranden zeker 28 doden gevallen. Veel huizen zijn in vlammen opgegaan, en duizenden mensen zijn geëvacueerd. Rusland heeft te kampen met de heetste zomer in ruim honderd jaar. Door de extreme droogte is de natuur extra kwetsbaar voor bosbranden.]]></description>
179 <published><![CDATA[2010-07-30 22:25:06]]></published>
180 <last_update><![CDATA[2010-07-30 15:43:07]]></last_update>
181 <thumbnail_xs><![CDATA[http://content.nos.nl/data/video/xs/2010/07/30/300710_15_ru2-CNO1007300Z_1.jpg]]></thumbnail_xs>
182 <thumbnail_s><![CDATA[http://content.nos.nl/data/video/s/2010/07/30/300710_15_ru2-CNO1007300Z_1.jpg]]></thumbnail_s>
183 <thumbnail_m><![CDATA[http://content.nos.nl/data/video/m/2010/07/30/300710_15_ru2-CNO1007300Z_1.jpg]]></thumbnail_m>
184 <link><![CDATA[http://nos.nl/video/175327-28-doden-door-bosbranden-rusland.html]]></link>
185 <embedcode><![CDATA[<object width="550" height="309"><param name="movie" value="http://s.nos.nl/swf/embed/nos_partner_video.swf?tcmid=tcm-5-776295&amp;platform=open&amp;partner=user"></param><param name="wmode" value="transparent"></param><param name="allowScriptAccess" value="always"></param><param name="allowfullscreen" value="true"></param><embed src="http://s.nos.nl/swf/embed/nos_partner_video.swf?tcmid=tcm-5-776295&amp;platform=open&amp;partner=user" type="application/x-shockwave-flash" wmode="transparent" width="550" height="309" allowfullscreen="true" allowScriptAccess="always"></embed></object>]]></embedcode>
186 <keywords>
187 <keyword><![CDATA[bosbranden]]></keyword>
188 <keyword><![CDATA[droogte]]></keyword>
189 <keyword><![CDATA[hitte]]></keyword>
190 <keyword><![CDATA[Rusland]]></keyword>
191 </keywords>
192 </video>
193 <video>
194 <id>175424</id>
195 <type>video</type>
196 <title><![CDATA[Duisburg verwacht tienduizenden bezoekers rouwdienst]]></title>
197 <description><![CDATA[Duisburg maakt zich op voor een dag van rouw. Morgen wordt het drama met de Love Parade van vorige week herdacht. Daarbij vielen 21 doden. Om elf uur begint de rouwdienst, waarbij bondskanselier Angela Merkel aanwezig is en naar verwachting tienduizenden rouwenden, misschien zelfs wel 100.000. Sommige inwoners van Duisburg zien dat met angst tegemoet.]]></description>
198 <published><![CDATA[2010-07-30 20:55:06]]></published>
199 <last_update><![CDATA[2010-07-30 21:05:08]]></last_update>
200 <thumbnail_xs><![CDATA[http://content.nos.nl/data/video/xs/2010/07/30/300710_15_ru2-CNO1007300Z_1.jpg]]></thumbnail_xs>
201 <thumbnail_s><![CDATA[http://content.nos.nl/data/video/s/2010/07/30/300710_15_ru2-CNO1007300Z_1.jpg]]></thumbnail_s>
202 <thumbnail_m><![CDATA[http://content.nos.nl/data/video/m/2010/07/30/300710_15_ru2-CNO1007300Z_1.jpg]]></thumbnail_m>
203 <link><![CDATA[http://nos.nl/video/175424-duisburg-verwacht-tienduizenden-bezoekers-rouwdienst.html]]></link>
204 <embedcode><![CDATA[<object width="550" height="309"><param name="movie" value="http://s.nos.nl/swf/embed/nos_partner_video.swf?tcmid=tcm-5-776295&amp;platform=open&amp;partner=user"></param><param name="wmode" value="transparent"></param><param name="allowScriptAccess" value="always"></param><param name="allowfullscreen" value="true"></param><embed src="http://s.nos.nl/swf/embed/nos_partner_video.swf?tcmid=tcm-5-776295&amp;platform=open&amp;partner=user" type="application/x-shockwave-flash" wmode="transparent" width="550" height="309" allowfullscreen="true" allowScriptAccess="always"></embed></object>]]></embedcode>
205 <keywords>
206 <keyword><![CDATA[herdenking]]></keyword>
207 <keyword><![CDATA[Duisburg]]></keyword>
208 <keyword><![CDATA[Duitsland]]></keyword>
209 <keyword><![CDATA[rouwdienst]]></keyword>
210 <keyword><![CDATA[Love Parade]]></keyword>
211 </keywords>
212 </video>
213 </list>},
214 },
215 'latest_audio' => {
216 'json' => q{{
217 "latest_audio": [
218 [
219 {
220 "id": "175384"
221 "type": "audio",
222 "title": "Paul Sneijder over Belgische formatie"
223 "description": "Ook in Belgie laat een nieuwe regering op zich wachten.n Toch is preformateur Di Rupo vanmiddag naar de koning geweest. Correspondent Paul Sneijder in Brussel."
224 "published": "2010-07-30 18:00:00"
225 "last_update": "2010-07-30 18:33:02"
226 "thumbnail_xs": ""
227 "thumbnail_s": ""
228 "thumbnail_m": ""
229 "link": http://nos.nl/audio/175384-paul-sneijder-over-belgische-formatie.html
230 "embedcode": "<object width="550" height="309"><param name="movie" value="http://s.nos.nl/swf/embed/nos_partner_audio.swf?tcmid=tcm-5-776295&amp;platform=open&amp;partner=user"></param><param name="wmode" value="transparent"></param><param name="allowScriptAccess" value="always"></param><param name="allowfullscreen" value="true"></param><embed src="http://s.nos.nl/swf/embed/nos_partner_video.swf?tcmid=tcm-5-776295&amp;platform=open&amp;partner=user" type="application/x-shockwave-flash" wmode="transparent" width="550" height="309" allowfullscreen="true" allowScriptAccess="always"></embed></object>"
231 "keywords": [
232 "belgië"
233 "brussel"
234 "formatie"
235 ]
236 },
237 {
238 "id": "175383"
239 "type": "audio",
240 "title": "Griekse chauffeurs blijven staken"
241 "description": "In Griekenland dreigt een onhoudbare situatie. De vrachtwagenchauffeurs gaan door met staken. Daardoor wordt het brandstoftekort steeds nijpender. Met alle gevolgen van dien. Correspondent Conny Keesen in Athene."
242 "published": "2010-07-30 18:00:00"
243 "last_update": "2010-07-30 18:33:02"
244 "thumbnail_xs": ""
245 "thumbnail_s": ""
246 "thumbnail_m": ""
247 "link": http://nos.nl/audio/175383-griekse-chauffeurs-blijven-staken.html
248 "embedcode": "<object width="550" height="309"><param name="movie" value="http://s.nos.nl/swf/embed/nos_partner_audio.swf?tcmid=tcm-5-776295&amp;platform=open&amp;partner=user"></param><param name="wmode" value="transparent"></param><param name="allowScriptAccess" value="always"></param><param name="allowfullscreen" value="true"></param><embed src="http://s.nos.nl/swf/embed/nos_partner_video.swf?tcmid=tcm-5-776295&amp;platform=open&amp;partner=user" type="application/x-shockwave-flash" wmode="transparent" width="550" height="309" allowfullscreen="true" allowScriptAccess="always"></embed></object>"
249 "keywords": [
250 "vrachtwagenchauffeurs"
251 "benzine"
252 "staking"
253 "Griekenland"
254 "Athene"
255 "brandstoftekort"
256 ]
257 }
258 ]
259 ]
260 }},
261 'xml' => q{<?xml version="1.0" encoding="UTF-8"?>
262 <list type="latest_audio" itemcount="2">
263 <audio>
264 <id>175384</id>
265 <type><![CDATA[audio]]></type>
266 <title><![CDATA[Paul Sneijder over Belgische formatie]]></title>
267 <description><![CDATA[Ook in Belgie laat een nieuwe regering op zich wachten.n Toch is preformateur Di Rupo vanmiddag naar de koning geweest. Correspondent Paul Sneijder in Brussel.]]></description>
268 <published><![CDATA[2010-07-30 18:00:00]]></published>
269 <last_update><![CDATA[2010-07-30 18:33:02]]></last_update>
270 <thumbnail_xs><![CDATA[]]></thumbnail_xs>
271 <thumbnail_s><![CDATA[]]></thumbnail_s>
272 <thumbnail_m><![CDATA[]]></thumbnail_m>
273 <link><![CDATA[http://nos.nl/audio/175384-paul-sneijder-over-belgische-formatie.html]]></link>
274 <embedcode><![CDATA[<object width="550" height="309"><param name="movie" value="http://s.nos.nl/swf/embed/nos_partner_audio.swf?tcmid=tcm-5-776295&amp;platform=open&amp;partner=user"></param><param name="wmode" value="transparent"></param><param name="allowScriptAccess" value="always"></param><param name="allowfullscreen" value="true"></param><embed src="http://s.nos.nl/swf/embed/nos_partner_video.swf?tcmid=tcm-5-776295&amp;platform=open&amp;partner=user" type="application/x-shockwave-flash" wmode="transparent" width="550" height="309" allowfullscreen="true" allowScriptAccess="always"></embed></object>]]></embedcode>
275 <keywords>
276 <keyword><![CDATA[belgië]]></keyword>
277 <keyword><![CDATA[brussel]]></keyword>
278 <keyword><![CDATA[formatie]]></keyword>
279 </keywords>
280 </audio>
281 <audio>
282 <id>175383</id>
283 <type><![CDATA[audio]]></type>
284 <title><![CDATA[Griekse chauffeurs blijven staken]]></title>
285 <description><![CDATA[In Griekenland dreigt een onhoudbare situatie. De vrachtwagenchauffeurs gaan door met staken. Daardoor wordt het brandstoftekort steeds nijpender. Met alle gevolgen van dien. Correspondent Conny Keesen in Athene.]]></description>
286 <published><![CDATA[2010-07-30 18:00:00]]></published>
287 <last_update><![CDATA[2010-07-30 18:33:02]]></last_update>
288 <thumbnail_xs><![CDATA[]]></thumbnail_xs>
289 <thumbnail_s><![CDATA[]]></thumbnail_s>
290 <thumbnail_m><![CDATA[]]></thumbnail_m>
291 <link><![CDATA[http://nos.nl/audio/175383-griekse-chauffeurs-blijven-staken.html]]></link>
292 <embedcode><![CDATA[<object width="550" height="309"><param name="movie" value="http://s.nos.nl/swf/embed/nos_partner_audio.swf?tcmid=tcm-5-776295&amp;platform=open&amp;partner=user"></param><param name="wmode" value="transparent"></param><param name="allowScriptAccess" value="always"></param><param name="allowfullscreen" value="true"></param><embed src="http://s.nos.nl/swf/embed/nos_partner_video.swf?tcmid=tcm-5-776295&amp;platform=open&amp;partner=user" type="application/x-shockwave-flash" wmode="transparent" width="550" height="309" allowfullscreen="true" allowScriptAccess="always"></embed></object>]]></embedcode>
293 <keywords>
294 <keyword><![CDATA[vrachtwagenchauffeurs]]></keyword>
295 <keyword><![CDATA[benzine]]></keyword>
296 <keyword><![CDATA[staking]]></keyword>
297 <keyword><![CDATA[Griekenland]]></keyword>
298 <keyword><![CDATA[Athene]]></keyword>
299 <keyword><![CDATA[brandstoftekort]]></keyword>
300 </keywords>
301 </audio>
302 </list>},
303 },
304 'search' => {
305 'json' => q{{
306 "search":[
307 {
308 "documents":[
309 {
310 "id":"video-36572",
311 "score":100,
312 "type":"video",
313 "title":"Cricket: finale twenty20 op Lord's","description":"Cricket, dan. De finale van het
314 twenty20-toernooi, in Londen. Het is de tweede editie in deze verkorte uitvoering en Pakistan
315 is voor de tweede keer finalist. Twee jaar geleden verloor Pakistan van India, en nu is het tijd
316 voor revanche. De tegenstander is Sri Lanka.",
317 "published":"2009-06-22 23:06:54",
318 "last_update":"2010-12-02 16:12:09",
319 "thumbnail":"http://content.nos.nl/data/video/s/2009/06/22/36572.jpg",
320 "category":"Sport",
321 "subcategory":"Algemeen",
322 "link":"http://nos.nl/video/36572-cricket-finale-twenty20-op-lords.html",
323 "keywords":[
324 "india",
325 "pakistan",
326 "Cricket"
327 ]
328 }
329 ],
330 "keywords":[
331 {
332 "tag":"Cricket",
333 "count":1
334 },
335 {
336 "tag":"india",
337 "count":1
338 },
339 {
340 "tag":"pakistan",
341 "count":1
342 }
343 ]
344 }
345 ]
346 }},
347 'xml' => q{<?xml version="1.0" encoding="UTF-8"?>
348 <list type="search" itemcount="1">
349 <documents>
350 <document>
351 <id>video-36572</id>
352 <score>100</score>
353 <type>video</type>
354 <title>Cricket: finale twenty20 op Lord's</title>
355 <description>
356 Cricket, dan. De finale van het twenty20-toernooi, in Londen. Het is de tweede editie in deze verkorte uitvoering en Pakistan is voor de tweede keer finalist. Twee jaar geleden verloor Pakistan van India, en nu is het tijd voor revanche. De tegenstander is Sri Lanka.
357 </description>
358 <published>2009-06-22 23:06:54</published>
359 <last_update>2010-12-02 16:12:09</last_update>
360 <thumbnail>
361 http://content.nos.nl/data/video/s/2009/06/22/36572.jpg
362 </thumbnail>
363 <category>Sport</category>
364 <subcategory>Algemeen</subcategory>
365 <link>
366 http://nos.nl/video/36572-cricket-finale-twenty20-op-lords.html
367 </link>
368 <keywords>
369 <keyword>india</keyword>
370 <keyword>pakistan</keyword>
371 <keyword>Cricket</keyword>
372 </keywords>
373 </document>
374 </documents>
375 <related>
376 <related>Cricket</related>
377 <related>india</related>
378 <related>pakistan</related>
379 </related>
380 </list>},
381 },
382 'guide_radio' => {
383 'json' => q{{
384 guide: [
385 [
386 {
387 "date": "2010-10-06",
388 "guide": [
389 {
390 "id": "171668744"
391 "type": "radio"
392 "channel_icon": http://open.nos.nl/img/icons/radio/ra1.png
393 "channel_code": "RA1"
394 "channel_name": "Radio 1"
395 "starttime": "2010-10-06 06:00:00"
396 "endtime": "2010-10-06 06:02:00"
397 "genre": "Nieuws/actualiteiten"
398 "title": "Nieuws"
399 "description": ""
400 },
401 {
402 "id": "171929021"
403 "type": "radio"
404 "channel_icon": http://open.nos.nl/img/icons/radio/ra2.png
405 "channel_code": "RA2"
406 "channel_name": "Radio 2"
407 "starttime": "2010-10-06 06:00:00"
408 "endtime": "2010-10-06 06:05:00"
409 "genre": "Overige"
410 "title": "Nieuws"
411 "description": ""
412 },
413 ]
414 },
415 {
416 "date": "2010-10-07"
417 "guide": [
418 {
419 "id": "171668782"
420 "type": "radio"
421 "channel_icon": http://open.nos.nl/img/icons/radio/ra1.png
422 "channel_code": "RA1"
423 "channel_name": "Radio 1"
424 "starttime": "2010-10-07 22:04:00"
425 "endtime": "2010-10-07 23:05:00"
426 "genre": "Sport"
427 "title": "NOS-Langs de lijn"
428 "description": ""
429 },
430 ]
431 }
432 ]
433 ]
434 }},
435 'xml' => q{<?xml version="1.0" encoding="UTF-8"?>
436 <list type="guide" daycount="2" itemcount="60">
437 <dayguide type="radio" date="2010-10-06">
438 <item>
439 <id>171668744</id>
440 <type>radio</type>
441 <channel_icon>http://open.nos.nl/img/icons/radio/ra1.png</channel_icon>
442 <channel_code>RA1</channel_code>
443 <channel_name>Radio 1</channel_name>
444 <starttime>2010-10-06 06:00:00</starttime>
445 <endtime>2010-10-06 06:02:00</endtime>
446 <genre>Nieuws/actualiteiten</genre>
447 <title>Nieuws</title>
448 <description></description>
449 </item>
450 <item>
451 <id>171929021</id>
452 <type>radio</type>
453 <channel_icon>http://open.nos.nl/img/icons/radio/ra2.png</channel_icon>
454 <channel_code>RA2</channel_code>
455 <channel_name>Radio 2</channel_name>
456 <starttime>2010-10-06 06:00:00</starttime>
457 <endtime>2010-10-06 06:05:00</endtime>
458 <genre>Overige</genre>
459 <title>Nieuws</title>
460 <description></description>
461 </item>
462 </dayguide>
463 <dayguide type="tv" date="2010-10-07">
464 <item>
465 <id>171929021</id>
466 <type>radio</type>
467 <channel_icon>http://open.nos.nl/img/icons/radio/ra2.png</channel_icon>
468 <channel_code>RA2</channel_code>
469 <channel_name>Radio 2</channel_name>
470 <starttime>2010-10-06 06:00:00</starttime>
471 <endtime>2010-10-06 06:05:00</endtime>
472 <genre>Overige</genre>
473 <title>Nieuws</title>
474 <description></description>
475 </item>
476 </dayguide>
477 </list>
478 },
479 },
480 'guide_tv' => {
481 'json' => q{{
482 "guide": [
483 [
484 {
485 "date": "2010-10-06",
486 "guide": [
487 {
488 "id": "171026258",
489 "type": "tv",
490 "channel_icon": "http://open.nos.nl/img/icons/tv/nl1.png",
491 "channel_code": "NL1",
492 "channel_name": "Nederland 1",
493 "starttime": "2010-10-06 07:00:00",
494 "endtime": "2010-10-06 07:10:00",
495 "genre": "Nieuws/actualiteiten",
496 "title": "NOS Journaal",
497 "description": "Journaal"
498 },
499 {
500 "id": "171026254",
501 "type": "tv",
502 "channel_icon": "http://open.nos.nl/img/icons/tv/nl1.png",
503 "channel_code": "NL1",
504 "channel_name": "Nederland 1",
505 "starttime": "2010-10-06 08:00:00",
506 "endtime": "2010-10-06 08:10:00",
507 "genre": "Nieuws/actualiteiten",
508 "title": "NOS Journaal",
509 "description": "Journaal"
510 },
511 ]
512 },
513 {
514 "date": "2010-10-07",
515 "guide": [
516 {
517 "id": "171026258",
518 "type": "tv",
519 "channel_icon": "http://open.nos.nl/img/icons/tv/nl1.png",
520 "channel_code": "NL1",
521 "channel_name": "Nederland 1",
522 "starttime": "2010-10-07 07:00:00",
523 "endtime": "2010-10-07 07:10:00",
524 "genre": "Nieuws/actualiteiten",
525 "title": "NOS Journaal",
526 "description": "Journaal"
527 },
528 {
529 "id": "171026254",
530 "type": "tv",
531 "channel_icon": "http://open.nos.nl/img/icons/tv/nl1.png",
532 "channel_code": "NL1",
533 "channel_name": "Nederland 1",
534 "starttime": "2010-10-07 08:00:00",
535 "endtime": "2010-10-07 08:10:00",
536 "genre": "Nieuws/actualiteiten",
537 "title": "NOS Journaal",
538 "description": "Journaal",
539 },
540 ]
541 }
542 ]
543 ]
544 }},
545 'xml' => q{<?xml version="1.0" encoding="UTF-8"?>
546 <list type="guide" daycount="2" itemcount="60">
547 <dayguide type="tv" date="2010-10-06">
548 <item>
549 <id>171026258</id>
550 <type><![CDATA[tv]]></type>
551 <channel_icon><![CDATA[http://open.nos.nl/img/icons/tv/nl1.png]]></channel_icon>
552 <channel_code><![CDATA[NL1]]></channel_code>
553 <channel_name><![CDATA[Nederland 1]]></channel_name>
554 <starttime><![CDATA[2010-10-06 07:00:00]]></starttime>
555 <endtime><![CDATA[2010-10-06 07:10:00]]></endtime>
556 <genre><![CDATA[Nieuws/actualiteiten]]></genre>
557 <title><![CDATA[NOS Journaal]]></title>
558 <description><![CDATA[Journaal]]></description>
559 </item>
560 <item>
561 <id>171246201</id>
562 <type><![CDATA[tv]]></type>
563 <channel_icon><![CDATA[http://open.nos.nl/img/icons/tv/nl2.png]]></channel_icon>
564 <channel_code><![CDATA[NL2]]></channel_code>
565 <channel_name><![CDATA[Nederland 2]]></channel_name>
566 <starttime><![CDATA[2010-10-06 07:00:00]]></starttime>
567 <endtime><![CDATA[2010-10-06 07:10:00]]></endtime>
568 <genre><![CDATA[Nieuws/actualiteiten]]></genre>
569 <title><![CDATA[NOS Journaal met gebarentolk]]></title>
570 <description><![CDATA[NOS Journaal met gebarentolk]]></description>
571 </item>
572 </dayguide>
573 <dayguide type="tv" date="2010-10-07">
574 <item>
575 <id>171026214</id>
576 <type><![CDATA[tv]]></type>
577 <channel_icon><![CDATA[http://open.nos.nl/img/icons/tv/nl1.png]]></channel_icon>
578 <channel_code><![CDATA[NL1]]></channel_code>
579 <channel_name><![CDATA[Nederland 1]]></channel_name>
580 <starttime><![CDATA[2010-10-07 00:00:00]]></starttime>
581 <endtime><![CDATA[2010-10-07 00:20:00]]></endtime>
582 <genre><![CDATA[Nieuws/actualiteiten]]></genre>
583 <title><![CDATA[NOS Journaal]]></title>
584 <description><![CDATA[NOS Journaal Laat]]></description>
585 </item>
586 <item>
587 <id>171026209</id>
588 <type><![CDATA[tv]]></type>
589 <channel_icon><![CDATA[http://open.nos.nl/img/icons/tv/nl1.png]]></channel_icon>
590 <channel_code><![CDATA[NL1]]></channel_code>
591 <channel_name><![CDATA[Nederland 1]]></channel_name>
592 <starttime><![CDATA[2010-10-07 02:20:00]]></starttime>
593 <endtime><![CDATA[2010-10-07 06:25:00]]></endtime>
594 <genre><![CDATA[Informatief]]></genre>
595 <title><![CDATA[NOS Tekst tv]]></title>
596 <description><![CDATA[Informatie uit Teletekst.]]></description>
597 </item>
598 </dayguide>
599 </list>
600 },
601 },
602 );
603 Readonly::Hash my %ERROR => (
604 'bad_request_missing' =>
605 q{{"badrequest":{"error":{"code":101,"message":"API-key not found"}}}},
606 'bad_request_invalid' =>
607 q{{"wrong param value":{"error":{"code":"111","message":"Param output must be of value (php,xml,json)"}}}},
608 'unauthorized' =>
609 q{{"unauthorized, invalid key":{"error":{"code":201,"message":"Invalid key"}}}},
610 'forbidden' =>
611 q{{"forbidden, rate limit":{"error":{"code":301,"message":"Rate limit, max requests per minute is set at 60"}}}},
612 );
613  
614 Getopt::Long::Configure(@GETOPT_CONFIG);
615 my %opts = %OPTS_DEFAULT;
616 Getopt::Long::GetOptions( \%opts, @GETOPTIONS ) or Pod::Usage::pod2usage(2);
617  
618 my $server = HTTP::Server::Brick->new( 'port' => $opts{'port'} );
619  
620 my $requests = 0;
621  
622 $server->mount(
623 $ROOT => {
624 'handler' => \&main,
625 'wildcard' => 1,
626 },
627 );
628  
629 sub main {
630 my ( $req, $res ) = @_;
631 my $uri = $req->uri;
632 $uri =~ s{$STRIP_QUERY}{}smx;
633 my $q = CGI->new($uri);
634 my %param = split $SLASH, $uri;
635 if ( !defined $OUTPUT{ lc $param{'output'} } ) {
636 $res->add_content_utf8( $ERROR{'bad_request_invalid'} );
637 $param{'output'} = $FALLBACK_OUTPUT;
638 $res->header( 'Content-Type',
639 $OUTPUT{ lc $param{'output'} } . $CHARSET );
640 $res->header(
641 'Status',
642 HTTP::Status::HTTP_BAD_REQUEST
643 . $SPACE
644 . status_message(HTTP::Status::HTTP_BAD_REQUEST),
645 );
646 $res->code(HTTP::Status::HTTP_BAD_REQUEST);
647 }
648 $res->header( 'Content-Type', $OUTPUT{ lc $param{'output'} } . $CHARSET );
649 if ( !defined $param{'key'} ) {
650 $res->add_content_utf8( $ERROR{'bad_request_missing'} );
651 $res->header(
652 'Status',
653 HTTP::Status::HTTP_BAD_REQUEST
654 . $SPACE
655 . status_message(HTTP::Status::HTTP_BAD_REQUEST),
656 );
657 $res->code(HTTP::Status::HTTP_BAD_REQUEST);
658 }
659 if ( $param{'key'} ne $API_KEY ) {
660 $res->header(
661 'Status',
662 HTTP::Status::HTTP_UNAUTHORIZED
663 . $SPACE
664 . status_message(HTTP::Status::HTTP_UNAUTHORIZED),
665 );
666  
667 ## no critic qw(ProhibitFlagComments)
668 # TODO: This also sets the content, which we don't want:
669 # (this is a TODO in HTTP::Server::Brick, so fixing it there is the way to go)
670 ## use critic
671 $res->code(HTTP::Status::HTTP_UNAUTHORIZED);
672 $res->add_content_utf8( $ERROR{'unauthorized'} );
673 }
674 $requests++;
675  
676 # dummy rate limit tester:
677 if ( $requests > $MAX_REQUESTS ) {
678 $res->add_content_utf8( $ERROR{'forbidden'} );
679 $res->header(
680 'Status',
681 HTTP::Status::HTTP_FORBIDDEN
682 . $SPACE
683 . status_message(HTTP::Status::HTTP_FORBIDDEN),
684 );
685 $requests = 0;
686 $res->code(HTTP::Status::HTTP_FORBIDDEN);
687 }
688 if ( defined $param{'index'} && $param{'index'} eq q{version} ) {
689 $res->add_content_utf8( $RESPONSE{'version'}->{ lc $param{'output'} } );
690 }
691 if ( defined $param{'latest'} ) {
692 $res->add_content_utf8(
693 $RESPONSE{ q{latest_} . $param{'latest'} }->{ lc $param{'output'} },
694 );
695 }
696 if ( defined $param{'search'} && $param{'search'} eq q{query} ) {
697 $res->add_content_utf8( $RESPONSE{'search'}->{ lc $param{'output'} } );
698 }
699 if ( defined $param{'guide'} ) {
700 $res->add_content_utf8(
701 $RESPONSE{ q{guide_} . $param{'guide'} }->{ lc $param{'output'} } );
702 }
703  
704 return 1;
705 }
706  
707 $server->start;
708  
709 __END__
710  
711 =encoding utf8
712  
713 =head1 NAME
714  
715 DummyServer.pl - a dummy NOS Open server to test the API against
716  
717 =head1 USAGE
718  
719 B<./DummyServer.pl> [B<--port=PORT>]
720  
721 =head1 DESCRIPTION
722  
723 For debugging against a server that isn't the NOS Open live server, this script
724 provides the same API against limited content.
725  
726 =head1 REQUIRED ARGUMENTS
727  
728 None.
729  
730 =head1 OPTIONS
731  
732 =over 4
733  
734 =item B< -?, -h, --help>
735  
736 Show help
737  
738 =item B< -m, --man>
739  
740 Show manpage
741  
742 =item B< -v, --verbose>
743  
744 Be more verbose
745  
746 =item B<--version>
747  
748 Show version and license
749  
750 =item B<--port>
751  
752 Port number to listen on, defaults to port 18081
753  
754 =back
755  
756 =head1 DIAGNOSTICS
757  
758 =head1 EXIT STATUS
759  
760 =head1 CONFIGURATION
761  
762 =head1 DEPENDENCIES
763  
764 Perl 5.14.0, CGI, Getopt::Long, HTTP::Server::Brick, Pod::Usage,
765 Pod::Usage::CommandLine, Readonly, WWW::NOS::Open
766  
767 =head1 INCOMPATIBILITIES
768  
769 Version 2 of the API is not provided.
770  
771 =head1 BUGS AND LIMITATIONS
772  
773 Only version 1 of the API is provided.
774  
775 Please report any bugs or feature requests at
776 L<RT for rt.cpan.org|https://rt.cpan.org/Dist/Display.html?Queue=WWW-NOS-Open>.
777  
778 =head1 CONFIGURATION AND ENVIRONMENT
779  
780 Using the defaults it starts the HTTP service on port 18081.
781  
782 =head1 AUTHOR
783  
784 Roland van Ipenburg, E<lt>ipenburg@xs4all.nlE<gt>
785  
786 =head1 LICENSE AND COPYRIGHT
787  
788 Copyright 2012 by Roland van Ipenburg
789  
790 This program is free software; you can redistribute it and/or modify
791 it under the same terms as Perl itself, either Perl version 5.14.0 or,
792 at your option, any later version of Perl 5 you may have available.
793  
794 =head1 DISCLAIMER OF WARRANTY
795  
796 BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
797 FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
798 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
799 PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
800 EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
801 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
802 ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
803 YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
804 NECESSARY SERVICING, REPAIR, OR CORRECTION.
805  
806 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
807 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
808 REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENSE, BE
809 LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
810 OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
811 THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
812 RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
813 FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
814 SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
815 SUCH DAMAGES.
816  
817 =cut