pprint(update_response['portal_state_transitions']) ## Setup our login credentials. auth = dict(username='******', password='******') folder = BibFolder(decode_output=True, **auth) exampleitemid = auth['username'] + '-pubexample' ## Create the item (it will be private by default) pdf = BibItem.encode_pdf('my.pdf', 'Testdata') create_response = folder.create_item(exampleitemid, 'ArticleReference', attributes={'title': 'Example', 'publication_year': '2012', 'authors': [{'firstnames': 'Hans Petter', 'lastname': 'Langtangen', 'username': '******'}, {'username': '******', 'firstnames': 'Carsten', 'lastname': 'Griwodz'}], 'simula_pdf_file': pdf}) print 'Created {title}'.format(**create_response['attributes']) print ' View it here: {url}'.format(**create_response) print 'The current portal_state is "{portal_state}", and the next possible states are: '.format(**create_response) pprint(create_response['portal_state_transitions']) ## Get an API for the created item itemid = create_response['attributes']['id'] exampleitem = BibItem(itemid, decode_output=True, **auth) portal_type = create_response['portal_type']
from pprint import pprint from simula_bibrestclient.client import BibFolder, BibItem from simula_bibrestclient.diff import create_diff # Setup our login credentials. auth = dict(username='******', password='******') exampleitemid = auth['username'] + '-example' portal_type = 'ArticleReference' # Create a bibitem folder = BibFolder(decode_output=True, **auth) create_response = folder.create_item(exampleitemid, portal_type, attributes={'title': 'Example', 'publication_year': '2012'}) print 'Created {title}'.format(**create_response['attributes']) print ' View it here: {url}'.format(**create_response) #pprint(create_response) # Pretty-print the entire response # Get the created bibitem itemid = create_response['attributes']['id'] exampleitem = BibItem(itemid, decode_output=True, **auth) # Pretend to update (no changes are stored in the database, but the response is just like it would be on a regular update) update_attributes = {'title': 'Updated example item using the Python REST client library'} pretend_update_response = exampleitem.update(portal_type, attributes=update_attributes,
folder = BibFolder(decode_output=True, **auth) # We can use search() to get bibliography items. If we do not use any # parameters, ALL simula publications are returned search_reponse = folder.search(simula_author_usernames=['griff', 'hpl']) print 'Search for {!r}:'.format(search_reponse['parameters']) print ' returned {0} items'.format(len(search_reponse['items'])) print ' parameters as they appear to the server:' print ' ', repr(search_reponse['parameters']) #pprint(search_reponse) # Pretty-print the entire response # We can use create_item() to create a new item in the folder create_response = folder.create_item(exampleitemid, 'ArticleReference', attributes={'title': 'Example', 'publication_year': '2012', 'simula_pdf_file': create_pdf()}) print 'Created {title}'.format(**create_response['attributes']) print ' View it here: {url}'.format(**create_response) #pprint(create_response) # Pretty-print the entire response ############################################### # Work with the item API # - Get all attributes of a single item, including the PDF data # - Update attributes of an item # - Delete single item via the web-browser ############################################### itemid = create_response['attributes']['id']