# Path: blindr/common/authenticate.py
# def authenticate(func):
#     @wraps(func)
#     def wrapper(*args, **kwargs):
#         user = token_authentication(request.headers.get('X-User-Token'))
#         if user:
#             func.__self__.user = user
#             return func(*args, **kwargs)
#         abort(401)
#     return wrapper
# 
# Path: blindr/models/event.py
# class Event(object):
# 
#     @staticmethod
#     def create(data):
#         data['sent_at'] = time.time()
#         data['event_id'] = str(uuid.uuid4())
#         return events.put_item(data=data)
# 
#     @staticmethod
#     def fetch(user=None, city=None, since=60):
#         adjusted_since = since - 60
#         dst = ''
# 
#         if user:
#             dst = 'user:{}'.format(user)
#         if city:
#             dst = 'city:{}'.format(city)
# 
#         resultset = events.query_2(
#             dst__eq=dst,
#             sent_at__gte=adjusted_since)
# 
#         items = [dict(item) for item in resultset]
#         for item in items:
#             item['sent_at'] = float(item['sent_at'])
# 
#         return items
# 
#     @staticmethod
#     def fetch_history(user, other,since=0):
#         resultset = events.query_2(
#             participants__eq= '{}:{}'.format(*sorted([user,other])),
#             index= 'participants-index',
#             sent_at__gte=since)
# 
#         items = [dict(item) for item in resultset]
#         for item in items:
#             item['sent_at'] = float(item['sent_at'])
# 
#         return list(items)


from flask.ext import restful
from blindr.common.authenticate import authenticate
from flask import request, abort
from blindr.models.event import Event


class History(restful.Resource):
    method_decorators=[authenticate]

    def get(self, other_id):
        sinceParam = int(request.args.get('since'))

# Path: blindr/common/authenticate.py
# def authenticate(func):
#     @wraps(func)
#     def wrapper(*args, **kwargs):
#         user = token_authentication(request.headers.get('X-User-Token'))
#         if user:
#             func.__self__.user = user
#             return func(*args, **kwargs)
#         abort(401)
#     return wrapper
# 
# Path: blindr/models/event.py
# class Event(object):
# 
#     @staticmethod
#     def create(data):
#         data['sent_at'] = time.time()
#         data['event_id'] = str(uuid.uuid4())
#         return events.put_item(data=data)
# 
#     @staticmethod
#     def fetch(user=None, city=None, since=60):
#         adjusted_since = since - 60
#         dst = ''
# 
#         if user:
#             dst = 'user:{}'.format(user)
#         if city:
#             dst = 'city:{}'.format(city)
# 
#         resultset = events.query_2(
#             dst__eq=dst,
#             sent_at__gte=adjusted_since)
# 
#         items = [dict(item) for item in resultset]
#         for item in items:
#             item['sent_at'] = float(item['sent_at'])
# 
#         return items
# 
#     @staticmethod
#     def fetch_history(user, other,since=0):
#         resultset = events.query_2(
#             participants__eq= '{}:{}'.format(*sorted([user,other])),
#             index= 'participants-index',
#             sent_at__gte=since)
# 
#         items = [dict(item) for item in resultset]
#         for item in items:
#             item['sent_at'] = float(item['sent_at'])
# 
#         return list(items)


# Path: blindr/api/history.py
from flask.ext import restful
from blindr.common.authenticate import authenticate
from flask import request, abort
from blindr.models.event import Event



class History(restful.Resource):
    method_decorators=[authenticate]

    def get(self, other_id):
        sinceParam = int(request.args.get('since'))

        return Event.fetch_history(user= self.user.id,