diff --git a/pagure/api/__init__.py b/pagure/api/__init__.py index 8e29c21..5ed6023 100644 --- a/pagure/api/__init__.py +++ b/pagure/api/__init__.py @@ -463,6 +463,8 @@ def api(): api_view_user_doc = load_doc(user.api_view_user) api_view_user_activity_stats_doc = load_doc( user.api_view_user_activity_stats) + api_view_user_activity_date_doc = load_doc( + user.api_view_user_activity_date) if pagure.APP.config.get('ENABLE_TICKETS', True): api_project_tags_doc = load_doc(api_project_tags) @@ -500,6 +502,7 @@ def api(): api_view_user_doc, api_groups_doc, api_view_user_activity_stats_doc, + api_view_user_activity_date_doc, ], ci=ci_doc, extras=extras, diff --git a/pagure/api/user.py b/pagure/api/user.py index 11fc383..811f4a4 100644 --- a/pagure/api/user.py +++ b/pagure/api/user.py @@ -10,6 +10,7 @@ import datetime +import arrow import flask import pagure @@ -219,3 +220,96 @@ def api_view_user_activity_stats(username): jsonout = flask.jsonify(stats) jsonout.status_code = httpcode return jsonout + + +@API.route('/user//activity/') +@api_method +def api_view_user_activity_date(username, date): + """ + User activity on a specific date + -------------------------------- + Use this endpoint to retrieve activity information about a specific user + on the specified date. + + :: + + GET /api/0/user//activity/ + + :: + + GET /api/0/user/ralph/activity/2016-01-02 + + Parameters + ^^^^^^^^^^ + + +---------------+----------+--------------+----------------------------+ + | Key | Type | Optionality | Description | + +===============+==========+==============+============================+ + | ``username`` | string | Mandatory | | The username of the user | + | | | | whose activity you are | + | | | | interested in. | + +---------------+----------+--------------+----------------------------+ + | ``date`` | string | Mandatory | | The date of interest | + +---------------+----------+--------------+----------------------------+ + + + Sample response + ^^^^^^^^^^^^^^^ + + :: + + { + "activities": [ + { + "date": "2016-02-24", + "date_created": "1456305852", + "description": "pingou created PR test#44", + "description_mk": "

pingou created PR test#44

", + "id": 4067, + "user": { + "fullname": "Pierre-YvesC", + "name": "pingou" + } + }, + { + "date": "2016-02-24", + "date_created": "1456305887", + "description": "pingou commented on PR test#44", + "description_mk": "

pingou commented on PR test#44

", + "id": 4112, + "user": { + "fullname": "Pierre-YvesC", + "name": "pingou" + } + } + ] + } + + """ + httpcode = 200 + + try: + date = arrow.get(date) + date = date.strftime('%Y-%m-%d') + except arrow.ParserError as err: + raise pagure.exceptions.APIError( + 400, error_code=APIERROR.ENOCODE, error=str(err)) + + user = pagure.lib.search_user(SESSION, username=username) + if not user: + raise pagure.exceptions.APIError(404, error_code=APIERROR.ENOUSER) + + activities = pagure.lib.get_user_activity_day(SESSION, user, date) + js_act = [] + for activity in activities: + activity = activity.to_json(public=True) + activity['description_mk'] = pagure.lib.text2markdown( + activity['description'] + ) + js_act.append(activity) + + jsonout = flask.jsonify( + dict(activities=js_act) + ) + jsonout.status_code = httpcode + return jsonout