-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi_client.py
More file actions
31 lines (26 loc) · 854 Bytes
/
api_client.py
File metadata and controls
31 lines (26 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- coding: utf-8 -*-
import json
import requests
from urllib.parse import urlencode
from app_config import API_URL, ENDPOINT_ESCOLAS, ENDPOINT_ESCOLA, ENDPOINT_CARDAPIOS
def api_call(endpoint, kwargs=dict()):
url = '{}{}?{}'.format(API_URL, endpoint, urlencode(kwargs))
response = requests.get(url)
content = response.content.decode('utf8')
return json.loads(content)
def find_escolas(query):
query_args = {
'nome': query,
'limit': 4
}
endpoint = ENDPOINT_ESCOLAS
return api_call(endpoint, query_args)
def get_escola(id_escola):
endpoint = ENDPOINT_ESCOLA.format(id_escola)
return api_call(endpoint)
def get_cardapio(id_escola, idade, data):
query_args = {
'idade': idade
}
endpoint = ENDPOINT_CARDAPIOS.format(id_escola, data)
return api_call(endpoint, query_args)