ginger.py 805 Bytes
Newer Older
Antoine Lima's avatar
Antoine Lima committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@author: Antoine Lima, Leo Reynaert, Domitille Jehenne
"""

import logging
import request
from http import HTTPStatus

class Ginger(object):
	URL = 'https://assos.utc.fr/ginger/v1/'
	_instance = None

	def __init__(self):
		if Ginger._instance!=None:
			self.api_key = Settings['ginger.key']
Antoine Lima's avatar
Antoine Lima committed
18
			self.url = Ginger.URL
Antoine Lima's avatar
Antoine Lima committed
19 20 21 22 23 24 25 26 27

	@property
	@staticmethod
	def instance():
		if Ginger._instance==None:
			Ginger._instance = Ginger()
		return Ginger._instance

	@staticmethod
Antoine Lima's avatar
Antoine Lima committed
28
	def get(endpoint, params={}):
Antoine Lima's avatar
Antoine Lima committed
29 30 31 32 33 34 35 36
		# Add the API key to the parameter list
		params['key'] = Ginger.instance.api_key

		response = request.get(Ginger.instance.url + endpoint, params)
		if response.status_code!=200:
			return HTTPStatus(response.status_code)
		else:
			return response.content