Skip to content

Commit

Permalink
Fix for #1. Also some cleaning up of docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
wragge committed Feb 15, 2022
1 parent d2caadd commit faa4209
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 475 deletions.
253 changes: 27 additions & 226 deletions api.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@
" if class_id:\n",
" payload['o:resource_class'] = self.format_resource_id(class_id, 'resource_classes')\n",
" if item_set_id:\n",
" payload['o:item_set'] = self.format_resource_id(template_id, 'item_sets')\n",
" payload['o:item_set'] = self.format_resource_id(item_set_id, 'item_sets')\n",
" if media_files:\n",
" files = self.add_media_to_payload(payload, media_files)\n",
" response = self.s.post(f'{self.api_url}/items', files=files, params=self.params)\n",
Expand Down Expand Up @@ -1306,229 +1306,6 @@
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"template_payload = omeka.prepare_template_payload('templates/Person.json')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'@context': 'https://timsherratt.org/collections/api-context',\n",
" '@id': 'https://timsherratt.org/collections/api/resource_templates/9',\n",
" '@type': 'o:ResourceTemplate',\n",
" 'o:id': 9,\n",
" 'o:label': 'Person',\n",
" 'o:owner': {'@id': 'https://timsherratt.org/collections/api/users/1',\n",
" 'o:id': 1},\n",
" 'o:resource_class': {'@id': 'https://timsherratt.org/collections/api/resource_classes/492',\n",
" 'o:id': 492},\n",
" 'o:title_property': {'@id': 'https://timsherratt.org/collections/api/properties/1116',\n",
" 'o:id': 1116},\n",
" 'o:description_property': {'@id': 'https://timsherratt.org/collections/api/properties/528',\n",
" 'o:id': 528},\n",
" 'o:resource_template_property': [{'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1116',\n",
" 'o:id': 1116},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': None,\n",
" 'o:data_type': ['literal'],\n",
" 'o:is_required': True,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1199',\n",
" 'o:id': 1199},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': None,\n",
" 'o:data_type': ['uri'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/528',\n",
" 'o:id': 528},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': None,\n",
" 'o:data_type': ['literal'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/417',\n",
" 'o:id': 417},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': None,\n",
" 'o:data_type': [],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1144',\n",
" 'o:id': 1144},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': None,\n",
" 'o:data_type': [],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/282',\n",
" 'o:id': 282},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': None,\n",
" 'o:data_type': ['literal'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1357',\n",
" 'o:id': 1357},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': None,\n",
" 'o:data_type': ['numeric:timestamp', 'literal'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1464',\n",
" 'o:id': 1464},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': None,\n",
" 'o:data_type': ['customvocab:1'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1042',\n",
" 'o:id': 1042},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': 'Place|Heritage place|State|Country',\n",
" 'o:data_type': ['resource:item', 'uri', 'literal'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/708',\n",
" 'o:id': 708},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': None,\n",
" 'o:data_type': ['numeric:timestamp', 'literal'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1468',\n",
" 'o:id': 1468},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': None,\n",
" 'o:data_type': ['customvocab:1'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/766',\n",
" 'o:id': 766},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': 'Place|Heritage place|State|Country',\n",
" 'o:data_type': ['resource:item', 'uri', 'literal'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/922',\n",
" 'o:id': 922},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': 'Person',\n",
" 'o:data_type': ['resource:item', 'uri'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/265',\n",
" 'o:id': 265},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': 'Person',\n",
" 'o:data_type': ['resource:item', 'uri'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1209',\n",
" 'o:id': 1209},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': None,\n",
" 'o:data_type': [],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1384',\n",
" 'o:id': 1384},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': 'Person',\n",
" 'o:data_type': ['resource:item', 'uri'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1358',\n",
" 'o:id': 1358},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': 'Person',\n",
" 'o:data_type': ['resource:item', 'uri'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/870',\n",
" 'o:id': 870},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': 'Person',\n",
" 'o:data_type': ['resource:item', 'uri'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/981',\n",
" 'o:id': 981},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': 'Organisation',\n",
" 'o:data_type': ['resource:item', 'uri', 'literal'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1253',\n",
" 'o:id': 1253},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': 'Organisation',\n",
" 'o:data_type': ['resource:item', 'uri', 'literal'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/804',\n",
" 'o:id': 804},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': 'Event',\n",
" 'o:data_type': ['resource:item'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/588',\n",
" 'o:id': 588},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': 'Vehicle',\n",
" 'o:data_type': ['resource:item'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/1391',\n",
" 'o:id': 1391},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': 'Book|Book chapter|Article|Newspaper article|Archival document|Archival file|Photograph|Art work',\n",
" 'o:data_type': ['resource:item'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/742',\n",
" 'o:id': 742},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': None,\n",
" 'o:data_type': ['uri'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/393',\n",
" 'o:id': 393},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': None,\n",
" 'o:data_type': ['uri'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False},\n",
" {'o:property': {'@id': 'https://timsherratt.org/collections/api/properties/246',\n",
" 'o:id': 246},\n",
" 'o:alternate_label': None,\n",
" 'o:alternate_comment': None,\n",
" 'o:data_type': ['uri'],\n",
" 'o:is_required': False,\n",
" 'o:is_private': False}]}"
]
},
"execution_count": null,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"omeka_auth.upload_template('templates/Person.json')"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -1891,6 +1668,30 @@
"assert test_item['dcterms:title'][0]['value'] == new_item['dcterms:title'][0]['@value']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also add an item to an existing item set by supplying the `item_set_id` parameter."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Get a random item set id\n",
"random_item_set = random.choice(omeka_auth.get_resources('item_sets')['results'])\n",
"item_set_id = random_item_set['o:id']\n",
"\n",
"# Create a new item using the item set id\n",
"new_item_in_item_set = new_item = omeka_auth.add_item(payload, item_set_id=item_set_id)\n",
"\n",
"# Check that the ids match\n",
"assert new_item_in_item_set['o:item_set'][0]['o:id'] == item_set_id"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -2690,9 +2491,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"In the example below I'm going to manually step through the process of adding a new item to Omeka using the API in order to demonstrate the methods available. But of course the point of using the API is to automate such processes -- joining together the individual steps so they can be embedded into your own systems or workflows.\n",
"In the example below I'm going to manually step through the process of adding a new item to Omeka using the API in order to demonstrate the methods available. But of course the point of using the API is to automate such processes -- joining together the individual steps so they can be embedded into your own systems or workflows. For a more detailed example that uploads Trove newspaper articles from a variety of sources, including Trove searches, Trove lists, and Zotero libraries, see the [GLAM Workbench](https://glam-workbench.net/trove-newspapers/#upload-trove-newspaper-articles-to-omeka-s).\n",
"\n",
"Let's suppose we want to add this newspaper article in Trove to our Omeka instance. To take best advantage of Omeka's linked data infrastructure, we'll actually create two resources -- one for the article, and one for the newspaper it was published in.\n",
"Let's suppose we want to add [this newspaper article](http://nla.gov.au/nla.news-article226799674) in Trove to our Omeka instance. To take best advantage of Omeka's linked data infrastructure, we'll actually create two resources -- one for the article, and one for the newspaper it was published in.\n",
"\n",
"I've already created templates labelled 'Newspaper' and 'Newspaper article'.\n",
"\n",
Expand Down
Loading

0 comments on commit faa4209

Please sign in to comment.