|
13 | 13 | import mimetypes |
14 | 14 |
|
15 | 15 | class Elink: |
| 16 | + """ |
| 17 | + Defines a set of access points for E-Link API endpoints. |
| 18 | +
|
| 19 | + Construct an api access object, defining the desired API target and supplying the user-specific API key token. |
| 20 | +
|
| 21 | + Use this to access functions, including: |
| 22 | +
|
| 23 | + get_single_record -- obtain a particular Record by its OSTI ID |
| 24 | + query_records -- query E-Link records according to given parameters |
| 25 | + post_new_record -- create a new Record; returned with unique OSTI ID value |
| 26 | + update_record -- update the indicated record content by OSTI ID |
| 27 | + patch_record -- submit a partial JSON update to a given record by its OSTI ID |
| 28 | + patch_json -- submit a JSON-patch set of commands to update a given record by its OSTI ID |
| 29 | + get_media -- obtain all media sets associated with an OSTI ID |
| 30 | + post_media -- add a new media set to the OSTI ID |
| 31 | + put_media -- replace an existing media set with new content |
| 32 | +
|
| 33 | + """ |
16 | 34 | def __init__(self, token=None, target=None): |
17 | 35 | """ |
18 | 36 | Set up the E-Link 2 OSTI API connector. |
@@ -105,7 +123,8 @@ def query_records(self, **kwargs): |
105 | 123 | the list of allowed query parameters. |
106 | 124 |
|
107 | 125 | Returns: |
108 | | - List[Record] - A list of one or more matching metadata records, if found. |
| 126 | + a iterative Query object containing total_rows count matching the search, and data containing |
| 127 | + a page at a time of returned Record values as a List. |
109 | 128 | """ |
110 | 129 | query_params = "" |
111 | 130 |
|
@@ -162,6 +181,55 @@ def post_new_record(self, record, state="save"): |
162 | 181 |
|
163 | 182 | # returns array, so grab the first element |
164 | 183 | return self._convert_response_to_records(response)[0] |
| 184 | + |
| 185 | + def patch_record(self, osti_id, patch, state="save"): |
| 186 | + """ |
| 187 | + Update record via partial-patch-json method endpoint |
| 188 | +
|
| 189 | + Arguments: |
| 190 | + osti_id -- the OSTI ID of the record to patch |
| 191 | + patch -- JSON/dict containing the partial JSON to apply |
| 192 | +
|
| 193 | + Keyword arguments: |
| 194 | + state -- the desired workflow submission state ("save" or "submit") default: "save" |
| 195 | +
|
| 196 | + Returns: |
| 197 | + Record -- the metadata of the new record revision if successful |
| 198 | + """ |
| 199 | + response = requests.patch(f"{self.target}/records/{osti_id}/{state}", |
| 200 | + headers = { |
| 201 | + "Authorization" : f"Bearer {self.token}", |
| 202 | + "Content-Type": "application/json" |
| 203 | + }, |
| 204 | + data=str(patch)) |
| 205 | + |
| 206 | + Validation.handle_response(response) |
| 207 | + |
| 208 | + return self._convert_response_to_records(response)[0] |
| 209 | + |
| 210 | + def patch_json(self, osti_id, jsonpatch, state="save"): |
| 211 | + """ |
| 212 | + Update record via a JSON-patch set of command operations. |
| 213 | + |
| 214 | + :param osti_id: The OSTI ID of the record to patch |
| 215 | + :type osti_id: int |
| 216 | +
|
| 217 | + :param jsonpatch: The JSON or dict containing array of patch operations to perform |
| 218 | + :param state: The desired workflow state of the new revision ("save" or "submit") default: "save" |
| 219 | +
|
| 220 | + :return: a Record of the new revision if successful |
| 221 | +
|
| 222 | + """ |
| 223 | + response = requests.patch(f"{self.target}/records/{osti_id}/{state}", |
| 224 | + headers = { |
| 225 | + "Authorization" : f"Bearer {self.token}", |
| 226 | + "Content-Type": "application/json-patch+json" |
| 227 | + }, |
| 228 | + data=str(jsonpatch)) |
| 229 | + |
| 230 | + Validation.handle_response(response) |
| 231 | + |
| 232 | + return self._convert_response_to_records(response)[0] |
165 | 233 |
|
166 | 234 | def update_record(self, osti_id, record, state="save"): |
167 | 235 | """Update existing records at OSTI by unique OSTI ID |
|
0 commit comments