|
3 | 3 | # and described in the LICENSE.txt file in the root of this project |
4 | 4 |
|
5 | 5 | """ |
6 | | -DSpace REST API client library. Intended to make interacting with DSpace in Python 3 easier, particularly |
7 | | -when creating, updating, retrieving and deleting DSpace Objects. |
8 | | -This client library is a work in progress and currently only implements the most basic functionality. |
9 | | -It was originally created to assist with a migration of container structure, items and bistreams from a non-DSpace |
10 | | -system to a new DSpace 7 repository. |
| 6 | +DSpace REST API client library. Intended to make interacting with DSpace in Python 3 easier, |
| 7 | +particularly when creating, updating, retrieving and deleting DSpace Objects. |
| 8 | +This client library is a work in progress and currently only implements the most basic |
| 9 | +functionality. |
| 10 | +It was originally created to assist with a migration of container structure, items and bistreams |
| 11 | +from a non-DSpace system to a new DSpace 7 repository. |
11 | 12 |
|
12 | | -It needs a lot of expansion: resource policies and permissions, validation of prepared objects and responses, |
13 | | -better abstracting and handling of HAL-like API responses, plus just all the other endpoints and operations implemented. |
| 13 | +It needs a lot of expansion: resource policies and permissions, validation of prepared objects |
| 14 | +and responses, better abstracting and handling of HAL-like API responses, plus just all the other |
| 15 | +endpoints and operations implemented. |
14 | 16 |
|
15 | 17 | @author Kim Shepherd <[email protected]> |
16 | 18 | """ |
@@ -48,11 +50,12 @@ def parse_json(response): |
48 | 50 |
|
49 | 51 | class DSpaceClient: |
50 | 52 | """ |
51 | | - Main class of the API client itself. This client uses request sessions to connect and authenticate to |
52 | | - the REST API, maintain XSRF tokens, and all GET, POST, PUT, PATCH operations. |
53 | | - Low-level api_get, api_post, api_put, api_delete, api_patch functions are defined to handle the requests and do |
54 | | - retries / XSRF refreshes where necessary. |
55 | | - Higher level get, create, update, partial_update (patch) functions are implemented for each DSO type |
| 53 | + Main class of the API client itself. This client uses request sessions to connect and |
| 54 | + authenticate to the REST API, maintain XSRF tokens, and all GET, POST, PUT, PATCH operations. |
| 55 | + Low-level api_get, api_post, api_put, api_delete, api_patch functions are defined to |
| 56 | + handle the requests and do retries / XSRF refreshes where necessary. |
| 57 | + Higher level get, create, update, partial_update (patch) functions are implemented |
| 58 | + for each DSO type |
56 | 59 | """ |
57 | 60 | # Set up basic environment, variables |
58 | 61 | session = None |
@@ -87,11 +90,13 @@ class PatchOperation: |
87 | 90 |
|
88 | 91 | def paginated(embed_name, item_constructor, embedding=lambda x: x): |
89 | 92 | """ |
90 | | - @param embed_name: The key under '_embedded' in the JSON response that contains the resources to be paginated. |
91 | | - (e.g. 'collections', 'objects', 'items', etc.) |
| 93 | + @param embed_name: The key under '_embedded' in the JSON response that contains the |
| 94 | + resources to be paginated. (e.g. 'collections', 'objects', 'items', etc.) |
92 | 95 | @param item_constructor: A callable that takes a resource dictionary and returns an item. |
93 | | - @param embedding: Optional post-fetch processing lambda (default: identity function) for each resource |
94 | | - @return: A decorator that, when applied to a method, follows pagination and yields each resource |
| 96 | + @param embedding: Optional post-fetch processing lambda (default: identity function) |
| 97 | + for each resource |
| 98 | + @return: A decorator that, when applied to a method, follows pagination and yields |
| 99 | + each resource |
95 | 100 | """ |
96 | 101 | def decorator(fun): |
97 | 102 | @functools.wraps(fun) |
@@ -120,9 +125,11 @@ def do_paginate(url, params): |
120 | 125 | def __init__(self, api_endpoint=API_ENDPOINT, username=USERNAME, password=PASSWORD, solr_endpoint=SOLR_ENDPOINT, |
121 | 126 | solr_auth=SOLR_AUTH, fake_user_agent=False): |
122 | 127 | """ |
123 | | - Accept optional API endpoint, username, password arguments using the OS environment variables as defaults |
| 128 | + Accept optional API endpoint, username, password arguments using the OS environment |
| 129 | + variables as defaults |
124 | 130 | :param api_endpoint: base path to DSpace REST API, eg. http://localhost:8080/server/api |
125 | | - :param username: username with appropriate privileges to perform operations on REST API |
| 131 | + :param username: username with appropriate privileges to perform operations on |
| 132 | + REST API |
126 | 133 | :param password: password for the above username |
127 | 134 | """ |
128 | 135 | self.session = requests.Session() |
|
0 commit comments