Merge: nitc: check pkg-config packages availability later
[nit.git] / src / doc / commands / commands_http.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 # Initialize commands from HTTP requests
16 #
17 # FIXME: this module is pretty tied up to the nitwed routes.
18 # To be more generic, param names should be extracted as variables.
19 module commands_http
20
21 import commands
22 import commands::commands_catalog
23 import nitcorn::vararg_routes
24
25 redef class DocCommand
26 # Init the command from an HTTPRequest
27 fun http_init(req: HttpRequest): CmdMessage do return init_command
28 end
29
30 redef class CmdEntity
31 redef fun http_init(req) do
32 var name = req.param("id")
33 if name != null then name = name.from_percent_encoding
34 self.mentity_name = name
35
36 return super
37 end
38 end
39
40 redef class CmdList
41 redef fun http_init(req) do
42 limit = req.int_arg("l")
43 page = req.int_arg("p")
44 return super
45 end
46 end
47
48 # Error Handling
49
50 # Message handling
51
52 redef class CmdMessage
53 # HTTP code to return for this message
54 var http_status_code = 200
55 end
56
57 redef class CmdError
58 redef var http_status_code = 400
59 end
60
61 redef class CmdWarning
62 redef var http_status_code = 404
63 end
64
65 redef class ErrorMEntityNoName
66 redef var http_status_code = 400
67 end
68
69 redef class ErrorMEntityNotFound
70 redef var http_status_code = 404
71 end
72
73 redef class ErrorMEntityConflict
74 redef var http_status_code = 300
75 end
76
77 # CmdModel
78
79 redef class CmdComment
80 redef fun http_init(req) do
81 full_doc = req.bool_arg("full_doc") or else true
82 fallback = req.bool_arg("fallback") or else true
83 format = req.string_arg("format") or else "raw"
84 return super
85 end
86 end
87
88 redef class CmdAncestors
89 redef fun http_init(req) do
90 parents = req.bool_arg("parents") or else true
91 return super
92 end
93 end
94
95 redef class CmdDescendants
96 redef fun http_init(req) do
97 children = req.bool_arg("children") or else true
98 return super
99 end
100 end
101
102 redef class CmdEntityList
103 # FIXME avoid linearization conflict
104 redef fun http_init(req) do return super
105 end
106
107 redef class CmdSearch
108 redef fun http_init(req) do
109 query = req.string_arg("q")
110 return super
111 end
112 end
113
114 redef class CmdModelEntities
115 redef fun http_init(req) do
116 kind = req.string_arg("kind") or else "all"
117 return super
118 end
119 end
120
121 redef class CmdCode
122 redef fun http_init(req) do
123 format = req.string_arg("format") or else "raw"
124 return super
125 end
126 end
127
128 redef class CmdEntityCode
129 # FIXME avoid linearization conflict
130 redef fun http_init(req) do
131 var name = req.param("id")
132 if name != null then name = name.from_percent_encoding
133 mentity_name = name
134
135 format = req.string_arg("format") or else "raw"
136 return init_command
137 end
138 end
139
140 # CmdGraph
141
142 redef class CmdGraph
143 redef fun http_init(req) do
144 format = req.string_arg("format") or else "dot"
145 return super
146 end
147 end
148
149 redef class CmdInheritanceGraph
150 redef fun http_init(req) do
151 pdepth = req.int_arg("pdepth")
152 cdepth = req.int_arg("cdepth")
153 return super
154 end
155 end
156
157 # CmdCatalog
158
159 redef class CmdCatalogTag
160 redef fun http_init(req) do
161 var tag = req.param("tid")
162 if tag != null then tag = tag.from_percent_encoding
163 self.tag = tag
164 return super
165 end
166 end
167
168 redef class CmdCatalogPerson
169 redef fun http_init(req) do
170 var name = req.param("pid")
171 if name != null then name = name.from_percent_encoding
172 self.person_name = name
173 return super
174 end
175 end