# Path: coffeestats/caffeine_api_v1/views.py
# @csrf_exempt
# @require_POST
# @api_token_required
# @json_response
# def add_drink(request, userinfo, messages, *args, **kwargs):
#     """
#     Submit a caffeinated beverage.
# 
#     :param HttpRequest request: POST request
#     :param User userinfo: :py:class:`caffeine.models.User`
#     :param dict messages: message dictionary
#     :return: messages array or :py:class:`django.http.HttpResponseBadRequest`
# 
#     """
# 
#     ctype = request.POST.get('beverage')
#     drinktime = request.POST.get('time')
#     time = None
#     if not ctype:
#         messages.setdefault('error', []).append(
#             API_ERROR_MISSING_PARAM_BEVERAGE)
#     elif not hasattr(DRINK_TYPES, ctype):
#         messages.setdefault('error', []).append(
#             API_ERROR_INVALID_BEVERAGE)
#     if not drinktime:
#         messages.setdefault('error', []).append(
#             API_ERROR_MISSING_PARAM_TIME)
#     else:
#         time = _parse_drinktime(drinktime, messages)
#         if time is not None and time > datetime.now() + timedelta(minutes=1):
#             messages.setdefault('error', []).append(API_ERROR_FUTURE_DATETIME)
#     if 'error' in messages:
#         return HttpResponseBadRequest(json.dumps(messages), 'text/json')
#     data = {'date': time.date(), 'time': time.time()}
#     form = SubmitCaffeineForm(userinfo, getattr(DRINK_TYPES, ctype), data)
#     form.date = time.date()
#     form.time = time.time()
#     if not form.is_valid():
#         for key in form.errors:
#             messages.setdefault('error', []).extend(form.errors[key])
#         return HttpResponseBadRequest(json.dumps(messages), 'text/json')
#     drink = form.save()
#     messages['success'] = _('Your %(drink)s has been registered!') % {
#         'drink': drink
#     }
#     return messages
# 
# @csrf_exempt
# @require_POST
# @api_token_required
# @json_response
# def random_users(request, **_):
#     """
#     Return a list of random user data.
# 
#     :param HttpRequest request: POST request
#     :return: list of users
# 
#     """
#     data = []
#     for user in User.objects.random_users(int(request.POST.get('count', 5))):
#         data.append({
#             'username': user.username,
#             'name': user.get_full_name(),
#             'location': user.location,
#             'profile': request.build_absolute_uri(
#                 reverse('public', kwargs={'username': user.username})),
#             'coffees': user.coffees,
#             'mate': user.mate})
#     return data


from django.conf.urls import url
from .views import (
    add_drink,
    random_users,
)


urlpatterns = [
    url(r'random-users$', random_users, name='random_users'),
    url(r'add-drink$', add_drink, name='add_drink'),

# Path: coffeestats/caffeine_api_v1/views.py
# @csrf_exempt
# @require_POST
# @api_token_required
# @json_response
# def add_drink(request, userinfo, messages, *args, **kwargs):
#     """
#     Submit a caffeinated beverage.
# 
#     :param HttpRequest request: POST request
#     :param User userinfo: :py:class:`caffeine.models.User`
#     :param dict messages: message dictionary
#     :return: messages array or :py:class:`django.http.HttpResponseBadRequest`
# 
#     """
# 
#     ctype = request.POST.get('beverage')
#     drinktime = request.POST.get('time')
#     time = None
#     if not ctype:
#         messages.setdefault('error', []).append(
#             API_ERROR_MISSING_PARAM_BEVERAGE)
#     elif not hasattr(DRINK_TYPES, ctype):
#         messages.setdefault('error', []).append(
#             API_ERROR_INVALID_BEVERAGE)
#     if not drinktime:
#         messages.setdefault('error', []).append(
#             API_ERROR_MISSING_PARAM_TIME)
#     else:
#         time = _parse_drinktime(drinktime, messages)
#         if time is not None and time > datetime.now() + timedelta(minutes=1):
#             messages.setdefault('error', []).append(API_ERROR_FUTURE_DATETIME)
#     if 'error' in messages:
#         return HttpResponseBadRequest(json.dumps(messages), 'text/json')
#     data = {'date': time.date(), 'time': time.time()}
#     form = SubmitCaffeineForm(userinfo, getattr(DRINK_TYPES, ctype), data)
#     form.date = time.date()
#     form.time = time.time()
#     if not form.is_valid():
#         for key in form.errors:
#             messages.setdefault('error', []).extend(form.errors[key])
#         return HttpResponseBadRequest(json.dumps(messages), 'text/json')
#     drink = form.save()
#     messages['success'] = _('Your %(drink)s has been registered!') % {
#         'drink': drink
#     }
#     return messages
# 
# @csrf_exempt
# @require_POST
# @api_token_required
# @json_response
# def random_users(request, **_):
#     """
#     Return a list of random user data.
# 
#     :param HttpRequest request: POST request
#     :return: list of users
# 
#     """
#     data = []
#     for user in User.objects.random_users(int(request.POST.get('count', 5))):
#         data.append({
#             'username': user.username,
#             'name': user.get_full_name(),
#             'location': user.location,
#             'profile': request.build_absolute_uri(
#                 reverse('public', kwargs={'username': user.username})),
#             'coffees': user.coffees,
#             'mate': user.mate})
#     return data


# Path: coffeestats/caffeine_api_v1/urls.py
from django.conf.urls import url
from .views import (
    add_drink,
    random_users,
)



urlpatterns = [
    url(r'random-users$', random_users, name='random_users'),
    url(r'add-drink$', add_drink, name='add_drink'),

]