35 |
35 |
|
36 |
36 |
category = _('Business Process Connectors')
|
37 |
37 |
|
|
38 |
_category_ordering = [_('General'), _('Journeys'), _('Subscriptions'), _('Topology')]
|
|
39 |
|
38 |
40 |
class Meta:
|
39 |
41 |
verbose_name = _('Okina')
|
40 |
42 |
|
... | ... | |
74 |
76 |
raise APIError('HTTP request failed, error %s' % response.status_code, data=data)
|
75 |
77 |
return data
|
76 |
78 |
|
77 |
|
@endpoint()
|
|
79 |
@endpoint(
|
|
80 |
display_category=_('General'),
|
|
81 |
display_order=1,
|
|
82 |
description=_('Cities'))
|
78 |
83 |
def cities(self, request):
|
79 |
84 |
okina_cities = self.request('cities')
|
80 |
85 |
cities = []
|
... | ... | |
90 |
95 |
cities.sort(key=lambda x: x['text'])
|
91 |
96 |
return {'data': cities}
|
92 |
97 |
|
93 |
|
@endpoint()
|
|
98 |
@endpoint(
|
|
99 |
display_category=_('General'),
|
|
100 |
display_order=2,
|
|
101 |
description=_('Classes'))
|
94 |
102 |
def classes(self, request):
|
95 |
103 |
return {'data': [{
|
96 |
104 |
'id': '%s' % item['id'],
|
... | ... | |
109 |
117 |
institutions.sort(key=lambda x: x['text'])
|
110 |
118 |
return institutions
|
111 |
119 |
|
112 |
|
@endpoint(parameters={
|
|
120 |
@endpoint(
|
|
121 |
display_category=_('General'),
|
|
122 |
display_order=3,
|
|
123 |
description=_('Institutions'))
|
|
124 |
def institutions(self, request):
|
|
125 |
return self.institutions(request)
|
|
126 |
|
|
127 |
@endpoint(
|
|
128 |
display_category=_('Journeys'),
|
|
129 |
display_order=2,
|
|
130 |
description=_('Institutions in a city (API 2020)'),
|
|
131 |
name='institutions',
|
|
132 |
parameters={
|
113 |
133 |
'insee': {'description': _('INSEE City code'), 'example_value': '36005'},
|
114 |
134 |
})
|
115 |
|
def institutions(self, request, insee=None):
|
|
135 |
def institutions_in_city(self, request, insee=None):
|
116 |
136 |
if insee:
|
117 |
137 |
query = '?' + urlencode({'inseeCode': insee})
|
118 |
138 |
else:
|
119 |
139 |
query = ''
|
120 |
140 |
return {'data': self.get_institutions(query)}
|
121 |
141 |
|
122 |
|
@endpoint(name='institutions', pattern='^from-city/(?P<city_insee_code>\d+)/*$')
|
|
142 |
@endpoint(
|
|
143 |
display_category=_('Journeys'),
|
|
144 |
display_order=3,
|
|
145 |
description=_('Institutions accessible from a city'),
|
|
146 |
name='institutions',
|
|
147 |
pattern=r'^from-city/(?P<city_insee_code>\d+)/*$',
|
|
148 |
parameters={
|
|
149 |
'city_insee_code': {'description': _('INSEE City code'), 'example_value': '36005'},
|
|
150 |
})
|
123 |
151 |
def institutions_from_city(self, request, city_insee_code):
|
124 |
152 |
return {'data': self.get_institutions('/subscriberCity/%s' % city_insee_code)}
|
125 |
153 |
|
126 |
154 |
@endpoint(
|
127 |
|
name='search', perm='can_access',
|
128 |
|
description=_('Get stop points based on a starting position and an arrival institution (API 2020)'),
|
129 |
|
parameters={
|
130 |
|
'lat': {'description': _('Latitude (departure)'), 'example_value': '46.828652'},
|
131 |
|
'lon': {'description': _('Longitude (departure)'), 'example_value': '1.701463'},
|
132 |
|
'address': {'description': _('Address (departure)')},
|
133 |
|
'institution': {'description': _('Institution ID (arrival)'), 'example_value': '277'},
|
134 |
|
'mode': {'description': _('Search mode: CLOSE_SCHOLAR (default) = 3km, FAR_ALL = 15km')},
|
135 |
|
})
|
|
155 |
display_category=_('Journeys'),
|
|
156 |
display_order=1,
|
|
157 |
name='search', perm='can_access',
|
|
158 |
description=_('Get stop points based on a starting position and an arrival institution (API 2020)'),
|
|
159 |
parameters={
|
|
160 |
'lat': {'description': _('Latitude (departure)'), 'example_value': '46.828652'},
|
|
161 |
'lon': {'description': _('Longitude (departure)'), 'example_value': '1.701463'},
|
|
162 |
'address': {'description': _('Address (departure)')},
|
|
163 |
'institution': {'description': _('Institution ID (arrival)'), 'example_value': '276'},
|
|
164 |
'mode': {'description': _('Search mode: CLOSE_SCHOLAR (default) = 3km, FAR_ALL = 15km')},
|
|
165 |
})
|
136 |
166 |
def search(self, request, lat, lon, institution, address='', mode='CLOSE_SCHOLAR'):
|
137 |
167 |
payload = {
|
138 |
168 |
'from-lat': lat,
|
... | ... | |
147 |
177 |
stop['text'] = stop['commercial_name']
|
148 |
178 |
return {'data': stops}
|
149 |
179 |
|
150 |
|
@endpoint(name='stop-areas',
|
151 |
|
pattern='^from-city/(?P<city_insee_code>\d+)/to-institution/(?P<institution_id>\d+)/*$')
|
|
180 |
@endpoint(
|
|
181 |
display_category=_('Journeys'),
|
|
182 |
display_order=4,
|
|
183 |
description=_('Stop areas from a city to an institution'),
|
|
184 |
name='stop-areas',
|
|
185 |
pattern=r'^from-city/(?P<city_insee_code>\d+)/to-institution/(?P<institution_id>\d+)/*$',
|
|
186 |
parameters={
|
|
187 |
'city_insee_code': {'description': _('INSEE City code'), 'example_value': '36005'},
|
|
188 |
'institution_id': {'description': _('Institution ID (arrival)'), 'example_value': '276'},
|
|
189 |
})
|
152 |
190 |
def stop_areas(self, request, city_insee_code, institution_id):
|
153 |
191 |
stops = self.request('stop-areas/subscriberCity/%s/institution/%s' % (city_insee_code,
|
154 |
192 |
institution_id))
|
... | ... | |
179 |
217 |
})
|
180 |
218 |
return {'data': ods}
|
181 |
219 |
|
182 |
|
@endpoint(name='origin-destinations')
|
|
220 |
@endpoint(
|
|
221 |
display_category=_('Journeys'),
|
|
222 |
display_order=5,
|
|
223 |
description=_('Origin/Destinations'),
|
|
224 |
name='origin-destinations')
|
183 |
225 |
def origin_destinations(self, request):
|
184 |
226 |
return self.get_ods()
|
185 |
227 |
|
186 |
|
@endpoint(name='origin-destinations',
|
187 |
|
pattern='^to-institution/(?P<institution_id>\d+)/*$')
|
|
228 |
@endpoint(
|
|
229 |
display_category=_('Journeys'),
|
|
230 |
display_order=6,
|
|
231 |
description=_('Origin/Destinations to an institution'),
|
|
232 |
name='origin-destinations',
|
|
233 |
pattern=r'^to-institution/(?P<institution_id>\d+)/*$',
|
|
234 |
parameters={
|
|
235 |
'institution_id': {'description': _('Institution ID (arrival)'), 'example_value': '276'},
|
|
236 |
})
|
188 |
237 |
def origin_destinations_to_institution(self, request, institution_id):
|
189 |
238 |
return self.get_ods('/institution/%s' % institution_id)
|
190 |
239 |
|
191 |
|
@endpoint(name='origin-destinations',
|
192 |
|
pattern='^from-stop-area/(?P<stop_area_id>\d+)/to-institution/(?P<institution_id>\d+)/*$')
|
|
240 |
@endpoint(
|
|
241 |
display_category=_('Journeys'),
|
|
242 |
display_order=7,
|
|
243 |
description=_('Origin/Destinations from a stop area to an institution'),
|
|
244 |
name='origin-destinations',
|
|
245 |
pattern=r'^from-stop-area/(?P<stop_area_id>\d+)/to-institution/(?P<institution_id>\d+)/*$',
|
|
246 |
parameters={
|
|
247 |
'stop_area_id': {'description': _('Stop area ID'), 'example_value': '3282'},
|
|
248 |
'institution_id': {'description': _('Institution ID (arrival)'), 'example_value': '276'},
|
|
249 |
})
|
193 |
250 |
def origin_destinations_from_stop_to_institution(self, request, stop_area_id, institution_id):
|
194 |
251 |
endpoint = 'ods/institution/%s/stop-area/%s' % (institution_id, stop_area_id)
|
195 |
252 |
okina_journeys = self.request(endpoint)
|
... | ... | |
206 |
263 |
journeys.append(journey)
|
207 |
264 |
return {'data': journeys}
|
208 |
265 |
|
209 |
|
@endpoint(name='origin-destinations',
|
210 |
|
pattern='^from-city/(?P<city_insee_code>\d+)/to-institution/(?P<institution_id>\d+)/*$')
|
|
266 |
@endpoint(
|
|
267 |
display_category=_('Journeys'),
|
|
268 |
display_order=8,
|
|
269 |
description=_('Origin/Destinations from a city to an institution'),
|
|
270 |
name='origin-destinations',
|
|
271 |
pattern=r'^from-city/(?P<city_insee_code>\d+)/to-institution/(?P<institution_id>\d+)/*$',
|
|
272 |
parameters={
|
|
273 |
'city_insee_code': {'description': _('INSEE City code'), 'example_value': '36005'},
|
|
274 |
'institution_id': {'description': _('Institution ID (arrival)'), 'example_value': '276'},
|
|
275 |
})
|
211 |
276 |
def origin_destinations_from_city_to_institution(self, request, city_insee_code, institution_id):
|
212 |
277 |
return self.get_ods('/institution/%s/subscriberCity/%s' % (institution_id, city_insee_code))
|
213 |
278 |
|
214 |
|
@endpoint(name='origin-destinations',
|
215 |
|
pattern='^from-city/(?P<city_insee_code>\d+)/*$')
|
|
279 |
@endpoint(
|
|
280 |
display_category=_('Journeys'),
|
|
281 |
display_order=9,
|
|
282 |
description=_('Origin/Destinations from a city'),
|
|
283 |
name='origin-destinations',
|
|
284 |
pattern=r'^from-city/(?P<city_insee_code>\d+)/*$',
|
|
285 |
parameters={
|
|
286 |
'city_insee_code': {'description': _('INSEE City code'), 'example_value': '36005'},
|
|
287 |
})
|
216 |
288 |
def origin_destinations_from_city(self, request, city_insee_code):
|
217 |
289 |
return self.get_ods('/subscriberCity/%s' % city_insee_code)
|
218 |
290 |
|
219 |
|
@endpoint(name='topology', pattern='^(?P<kind>(lines|networks|vehicle-journeys))/*$')
|
|
291 |
@endpoint(
|
|
292 |
display_category=_('Topology'),
|
|
293 |
show=False,
|
|
294 |
name='topology', pattern='^(?P<kind>(lines|networks|vehicle-journeys))/*$')
|
220 |
295 |
def topology(self, request, kind):
|
221 |
296 |
return {'data': [{
|
222 |
297 |
'id': '%s' % item['id'],
|
223 |
298 |
'text': item['name']
|
224 |
299 |
} for item in self.request('topology/%s' % kind)]}
|
225 |
300 |
|
226 |
|
@endpoint(name='subscriber', methods=['post'], perm='can_access')
|
|
301 |
@endpoint(
|
|
302 |
display_category=_('Topology'),
|
|
303 |
display_order=1,
|
|
304 |
description=_('Lines'),
|
|
305 |
name='topology', pattern='^lines/*$', example_pattern='lines/')
|
|
306 |
def topology_lines(self, request):
|
|
307 |
return self.topology(request, kind='lines')
|
|
308 |
|
|
309 |
@endpoint(
|
|
310 |
display_category=_('Topology'),
|
|
311 |
display_order=2,
|
|
312 |
description=_('Networks'),
|
|
313 |
name='topology', pattern='^networks/*$', example_pattern='networks/')
|
|
314 |
def topology_networks(self, request):
|
|
315 |
return self.topology(request, kind='networks')
|
|
316 |
|
|
317 |
@endpoint(
|
|
318 |
display_category=_('Topology'),
|
|
319 |
display_order=3,
|
|
320 |
description=_('Vehicle journeys'),
|
|
321 |
name='topology', pattern='^vehicle-journeys/*$', example_pattern='vehicle-journeys/')
|
|
322 |
def topology_vehicle_journeys(self, request):
|
|
323 |
return self.topology(request, kind='vehicle-journeys')
|
|
324 |
|
|
325 |
@endpoint(
|
|
326 |
display_category=_('Subscriptions'),
|
|
327 |
display_order=1,
|
|
328 |
description=_('Create a subscriber'),
|
|
329 |
long_description=_('Same payload as for the Okina POST /b2b/subscribers endpoint'),
|
|
330 |
name='subscriber', methods=['post'], perm='can_access')
|
227 |
331 |
def create_subscriber(self, request):
|
228 |
332 |
try:
|
229 |
333 |
payload = json_loads(request.body)
|
... | ... | |
233 |
337 |
raise APIError('payload must be a dict', http_status=400)
|
234 |
338 |
return {'data': self.request('subscribers', payload, result_is_list=False)}
|
235 |
339 |
|
236 |
|
@endpoint(name='subscriber', pattern='^(?P<subscriber_id>\d+)/*$',
|
237 |
|
methods=['get'], perm='can_access')
|
|
340 |
@endpoint(
|
|
341 |
display_category=_('Subscriptions'),
|
|
342 |
display_order=2,
|
|
343 |
description=_('Informations about a subscriber'),
|
|
344 |
name='subscriber', pattern=r'^(?P<subscriber_id>\d+)/*$',
|
|
345 |
methods=['get'], perm='can_access',
|
|
346 |
parameters={
|
|
347 |
'subscriber_id': {'description': _('Subscriber ID'), 'example_value': '284'},
|
|
348 |
})
|
238 |
349 |
def get_subscriber(self, request, subscriber_id):
|
239 |
350 |
return {'data': self.request('subscribers/%s' % subscriber_id, result_is_list=False)}
|
240 |
351 |
|
241 |
|
@endpoint(name='subscriber', pattern='^(?P<subscriber_id>\d+)/qrcode/*$',
|
242 |
|
perm='can_access')
|
|
352 |
@endpoint(
|
|
353 |
display_category=_('Subscriptions'),
|
|
354 |
display_order=3,
|
|
355 |
description=_("Get subscriber's QR Code"),
|
|
356 |
name='subscriber', pattern=r'^(?P<subscriber_id>\d+)/qrcode/*$',
|
|
357 |
perm='can_access',
|
|
358 |
parameters={
|
|
359 |
'subscriber_id': {'description': _('Subscriber ID'), 'example_value': '284'},
|
|
360 |
})
|
243 |
361 |
def get_subscriber_qrcode(self, request, subscriber_id):
|
244 |
362 |
qrcode = self.request('subscribers/%s/qrcode' % subscriber_id, result_is_json=False)
|
245 |
363 |
content_type = qrcode.headers.get('Content-Type')
|
... | ... | |
250 |
368 |
err=response['code'])
|
251 |
369 |
return HttpResponse(qrcode.content, content_type=content_type)
|
252 |
370 |
|
253 |
|
@endpoint(name='subscription', methods=['post'], perm='can_access')
|
|
371 |
@endpoint(
|
|
372 |
display_category=_('Subscriptions'),
|
|
373 |
display_order=4,
|
|
374 |
description=_("Create a subscription"),
|
|
375 |
long_description=_('Same payload as for the Okina POST /b2b/subscriptions endpoint'),
|
|
376 |
name='subscription', methods=['post'], perm='can_access')
|
254 |
377 |
def create_subscription(self, request):
|
255 |
378 |
try:
|
256 |
379 |
payload = json_loads(request.body)
|
... | ... | |
260 |
383 |
raise APIError('payload must be a dict', http_status=400)
|
261 |
384 |
return {'data': self.request('subscriptions', payload, result_is_list=False)}
|
262 |
385 |
|
263 |
|
@endpoint(name='subscription', pattern='^(?P<subscription_id>\d+)/*$',
|
264 |
|
methods=['get'], perm='can_access')
|
|
386 |
@endpoint(
|
|
387 |
display_category=_('Subscriptions'),
|
|
388 |
display_order=5,
|
|
389 |
description=_("Informations about a subscription"),
|
|
390 |
name='subscription', pattern=r'^(?P<subscription_id>\d+)/*$',
|
|
391 |
methods=['get'], perm='can_access',
|
|
392 |
parameters={
|
|
393 |
'subscription_id': {'description': _('Subscription ID'), 'example_value': '284'},
|
|
394 |
})
|
265 |
395 |
def get_subscription(self, request, subscription_id):
|
266 |
396 |
return {'data': self.request('subscriptions/%s' % subscription_id, result_is_list=False)}
|