1
0
mirror of https://github.com/ilri/dspace-statistics-api.git synced 2025-05-10 15:16:02 +02:00

Compare commits

...

8 Commits

Author SHA1 Message Date
702724e8a4 CHANGELOG.md: Move unreleased changes to version 0.3.0 2018-09-25 11:38:36 +03:00
36818d03ef CHANGELOG.md: Update unreleased changes 2018-09-25 11:37:56 +03:00
4cf8656b35 Change / route to /items
I think it's more obvious if the "all items" route is plural. Also,
this will allow me to eventually put documentation at the root.
2018-09-25 11:34:07 +03:00
f30a464cd1 README.md: Add notes about API endpoints 2018-09-25 11:28:12 +03:00
93ae12e313 README.md: Update introduction 2018-09-25 11:15:12 +03:00
dc978e9333 CHANGELOG.md: Add note about requirements.txt and Travis CI 2018-09-25 11:09:02 +03:00
295436fea0 Add .travis.yml 2018-09-25 11:08:01 +03:00
46a1476ab0 Add requirements.txt
Generated with `pip freeze`. This is so I can pin the versions of
packages that I've tested with as well as to allow Travis to test
whether the project runs on various Pythons and to let GitHub in-
form me of vulnerabilities in some libraries.
2018-09-25 11:02:50 +03:00
5 changed files with 41 additions and 3 deletions

8
.travis.yml Normal file
View File

@ -0,0 +1,8 @@
language: python
python:
- "3.5"
- "3.6"
install:
- pip install -r requirements.txt
# vim: ts=2 sw=2 et

View File

@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [0.3.0] - 2018-09-25
### Added
- requirements.txt for pip
- Travis CI build configuration for Python 3.6 and 3.7
- Documentation on using the API
### Changed
- The "all items" route from / to /items
## [0.2.1] - 2018-09-24 ## [0.2.1] - 2018-09-24
### Changed ### Changed
- Environment settings in example systemd unit files - Environment settings in example systemd unit files

View File

@ -1,22 +1,31 @@
# DSpace Statistics API # DSpace Statistics API
A quick and dirty REST API to expose Solr view and download statistics for items in a DSpace repository. A quick and dirty REST API to expose Solr view and download statistics for items in a DSpace repository.
Written and tested in Python 3.6. SolrClient (0.2.1) does not currently run in Python 3.7.0. Requires PostgreSQL version 9.5 or greater for [`UPSERT` support](https://wiki.postgresql.org/wiki/UPSERT). Written and tested in Python 3.5 and 3.6. SolrClient (0.2.1) does [not currently run in Python 3.7.0](https://github.com/moonlitesolutions/SolrClient/issues/79). Requires PostgreSQL version 9.5 or greater for [`UPSERT` support](https://wiki.postgresql.org/wiki/UPSERT).
## Installation ## Installation
Create a virtual environment and run it: Create a virtual environment and run it:
$ virtualenv -p /usr/bin/python3.6 venv $ virtualenv -p /usr/bin/python3.6 venv
$ . venv/bin/activate $ . venv/bin/activate
$ pip install falcon gunicorn SolrClient psycopg2-binary $ pip install -r requirements.txt
$ gunicorn app:api $ gunicorn app:api
## Using the API
The API exposes the following endpoints:
- GET `/items`return views and downloads for all items that Solr knows about¹. Accepts `limit` and `page` query parameters for pagination of results.
- GET `/item/id`return views and downloads for a single item (*id* must be a positive integer).
¹ We are querying the Solr statistics core, which technically only knows about all items that have either views or downloads.
## Todo ## Todo
- Add API documentation - Add API documentation
- Close up DB connection when gunicorn shuts down gracefully - Close up DB connection when gunicorn shuts down gracefully
- Better logging - Better logging
- Return HTTP 404 when item_id is nonexistent - Return HTTP 404 when item_id is nonexistent
- Tests
## License ## License
This work is licensed under the [GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html). This work is licensed under the [GPLv3](https://www.gnu.org/licenses/gpl-3.0.en.html).

2
app.py
View File

@ -59,7 +59,7 @@ class ItemResource:
resp.media = statistics resp.media = statistics
api = falcon.API() api = falcon.API()
api.add_route('/', AllItemsResource()) api.add_route('/items', AllItemsResource())
api.add_route('/item/{item_id:int}', ItemResource()) api.add_route('/item/{item_id:int}', ItemResource())
# vim: set sw=4 ts=4 expandtab: # vim: set sw=4 ts=4 expandtab:

12
requirements.txt Normal file
View File

@ -0,0 +1,12 @@
certifi==2018.8.24
chardet==3.0.4
falcon==1.4.1
gunicorn==19.9.0
idna==2.7
kazoo==2.2.1
psycopg2-binary==2.7.5
python-mimeparse==1.6.0
requests==2.19.1
six==1.11.0
SolrClient==0.2.1
urllib3==1.23