Coverage for portality/view/api_v1.py: 89%
104 statements
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-19 18:38 +0100
« prev ^ index » next coverage.py v6.4.2, created at 2022-07-19 18:38 +0100
1from flask import Blueprint, url_for, redirect
3from portality.api.current import Api400Error
4from portality.core import app
5from portality.decorators import api_key_required, api_key_optional, write_required
6from portality.lib import plausible
7from portality.view import api_v3
9blueprint = Blueprint('api_v1', __name__)
11API_VERSION_NUMBER = '1.0.0'
13# Google Analytics category for API events
14GA_CATEGORY = app.config.get('GA_CATEGORY_API', 'API Hit')
15GA_ACTIONS = app.config.get('GA_ACTIONS_API', {})
17API_UNSUPPORTED_ERROR = "Version 1 is no longer supported."
19# the API v1 is not supported anymore, this file handles api v2 requests:
20# requests to articles are redirected to v2
21# other requests raise the 400 Error
23#######################################
24# ARTICLES
27@blueprint.route('/')
28def api_v1_root():
29 return redirect(url_for('api_v3.api_spec'))
32@blueprint.route('/docs')
33def docs():
34 return redirect(url_for('doaj.docs'))
37@blueprint.route('/search/articles/<path:search_query>')
38def search_articles(search_query):
39 # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664
40 # return redirect(url_for('api_v3.search_articles', search_query=search_query))
41 return api_v3.search_articles(search_query)
44@blueprint.route("/articles", methods=["POST"])
45@api_key_required
46@write_required(api=True)
47@plausible.pa_event(GA_CATEGORY, action=GA_ACTIONS.get('create_article', 'Create article'))
48def create_article():
49 # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664
50 # return redirect(url_for('api_v3.create_article', **request.args), code=301)
51 return api_v3.create_article()
54@blueprint.route("/articles/<article_id>", methods=["GET"])
55@api_key_optional
56@plausible.pa_event(GA_CATEGORY, action=GA_ACTIONS.get('retrieve_article', 'Retrieve article'),
57 record_value_of_which_arg='article_id')
58def retrieve_article(article_id):
59 # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664
60 # return redirect(url_for('api_v3.retrieve_article', article_id=article_id, **request.args), code=301)
61 return api_v3.retrieve_article(article_id)
64@blueprint.route("/articles/<article_id>", methods=["PUT"])
65@api_key_required
66@write_required(api=True)
67@plausible.pa_event(GA_CATEGORY, action=GA_ACTIONS.get('update_article', 'Update article'),
68 record_value_of_which_arg='article_id')
69def update_article(article_id):
70 # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664
71 # return redirect(url_for('api_v3.update_article', article_id=article_id, **request.args), code=301)
72 return api_v3.update_article(article_id)
75@blueprint.route("/articles/<article_id>", methods=["DELETE"])
76@api_key_required
77@write_required(api=True)
78@plausible.pa_event(GA_CATEGORY, action=GA_ACTIONS.get('delete_article', 'Delete article'),
79 record_value_of_which_arg='article_id')
80def delete_article(article_id):
81 # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664
82 # return redirect(url_for('api_v3.delete_article', article_id=article_id, **request.args), code=301)
83 return api_v3.delete_article(article_id)
86@blueprint.route("/bulk/articles", methods=["POST"])
87@api_key_required
88@write_required(api=True)
89@plausible.pa_event(GA_CATEGORY, action=GA_ACTIONS.get('bulk_article_create', 'Bulk article create'))
90def bulk_article_create():
91 # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664
92 # return redirect(url_for('api_v3.bulk_article_create', **request.args), code=301)
93 return api_v3.bulk_article_create()
96@blueprint.route("/bulk/articles", methods=["DELETE"])
97@api_key_required
98@write_required(api=True)
99@plausible.pa_event(GA_CATEGORY, action=GA_ACTIONS.get('bulk_article_delete', 'Bulk article delete'))
100def bulk_article_delete():
101 # Redirects are disabled https://github.com/DOAJ/doajPM/issues/2664
102 # return redirect(url_for('api_v3.bulk_article_delete', **request.args), code=301)
103 return api_v3.bulk_article_delete()
106#######################################
107# OTHER
109@blueprint.route('/journals/<journal_id>', methods=['GET'])
110@api_key_optional
111@plausible.pa_event(GA_CATEGORY, action=GA_ACTIONS.get('retrieve_journal', 'Retrieve journal'),
112 record_value_of_which_arg='journal_id')
113def retrieve_journal(journal_id):
114 raise Api400Error(API_UNSUPPORTED_ERROR)
117@blueprint.route("/bulk/applications", methods=["POST"])
118@api_key_required
119@write_required(api=True)
120@plausible.pa_event(GA_CATEGORY, action=GA_ACTIONS.get('bulk_application_create', 'Bulk application create'))
121def bulk_application_create():
122 raise Api400Error(API_UNSUPPORTED_ERROR)
125@blueprint.route("/bulk/applications", methods=["DELETE"])
126@api_key_required
127@write_required(api=True)
128@plausible.pa_event(GA_CATEGORY, action=GA_ACTIONS.get('bulk_application_delete', 'Bulk application delete'))
129def bulk_application_delete():
130 raise Api400Error(API_UNSUPPORTED_ERROR)
133@blueprint.route("/applications", methods=["POST"])
134@api_key_required
135@write_required(api=True)
136@plausible.pa_event(GA_CATEGORY, action=GA_ACTIONS.get('create_application', 'Create application'))
137def create_application():
138 raise Api400Error(API_UNSUPPORTED_ERROR)
141@blueprint.route("/applications/<application_id>", methods=["GET"])
142@api_key_required
143@plausible.pa_event(GA_CATEGORY, action=GA_ACTIONS.get('retrieve_application', 'Retrieve application'),
144 record_value_of_which_arg='application_id')
145def retrieve_application(application_id):
146 raise Api400Error(API_UNSUPPORTED_ERROR)
149@blueprint.route("/applications/<application_id>", methods=["PUT"])
150@api_key_required
151@write_required(api=True)
152@plausible.pa_event(GA_CATEGORY, action=GA_ACTIONS.get('update_application', 'Update application'),
153 record_value_of_which_arg='application_id')
154def update_application(application_id):
155 raise Api400Error(API_UNSUPPORTED_ERROR)
158@blueprint.route("/applications/<application_id>", methods=["DELETE"])
159@api_key_required
160@write_required(api=True)
161@plausible.pa_event(GA_CATEGORY, action=GA_ACTIONS.get('delete_application', 'Delete application'),
162 record_value_of_which_arg='application_id')
163def delete_application(application_id):
164 raise Api400Error(API_UNSUPPORTED_ERROR)
167@blueprint.route("/search/applications/<path:search_query>")
168@api_key_required
169@plausible.pa_event(GA_CATEGORY, action=GA_ACTIONS.get('search_applications', 'Search applications'),
170 record_value_of_which_arg='search_query')
171def search_applications(search_query):
172 raise Api400Error(API_UNSUPPORTED_ERROR)
175@blueprint.route('/search/journals/<path:search_query>')
176@plausible.pa_event(GA_CATEGORY, action=GA_ACTIONS.get('search_journals', 'Search journals'),
177 record_value_of_which_arg='search_query')
178def search_journals(search_query):
179 raise Api400Error(API_UNSUPPORTED_ERROR)