simula_bibrestclient.client — REST client¶
-
class
simula_bibrestclient.client.BibFolder(username, password, folderurl='http://plonerest.simula.no/publications/', **kwargs)[source]¶ Bases:
simula_bibrestclient.client.BibResourceBibliography folder REST API.
-
bulk_update(items, pretend=False)[source]¶ Perform HTTP PUT to update many items.
Note
This is a very thin wrapper around
put(). See the source for this method (link on the right hand side) to see what it does.Parameters: items – List of items to update. Pretend: Just pretend to make the changes? If True, no changes are made to the database, however the response will still be just as if we usedpretend=False.
-
create_item(id, portal_type, attributes, pretend=False)[source]¶ Perform HTTP POST to create a bibliography item within this folder.
Note
This is a very thin wrapper around
post(). See the source for this method (link on the right hand side) to see what it does.Parameters: - id – ID (short name) of the new item.
- portal_type – The portal_type of the bibliography item.
- attributes – Attributes for the new item. These are the same as the
attributesdocumented in the REST API docs. Note thatattributes['id']is ignored if included (Theidparameter is used instead).
Pretend: Just pretend to make the changes? If
True, no changes are made to the database, however the response will still be just as if we usedpretend=False.
-
get_restapi_url()[source]¶ Returns the REST API URL of this bibfolder. When this URL is opened in a browser, the user sees the docs for the REST API.
-
get_website_url()[source]¶ Returns the URL for this bibfolder on the website (not the REST API url).
-
search(simula_author_usernames=[], author_names=[], search='', itemids=[])[source]¶ Perform HTTP GET to search the publication catalog. The default is to return all publications, however the results can be limited using the parameters below. Only the first search limiting parameter that is not
bool(False)is used, and they are checked in the order they are listed.Parameters: - simula_author_usernames – List of author Plone usernames.
Matches exact usernames (no fuzzy searching).
E.g.:
['hpl', 'griff'] - author_names – List of author names. E.g.:
['Griwodz C', 'Langtangen H'] - search – Free text search. Searches the SearchableText index.
E.g:
"addresses the problem of managing an evolving" - itemids – Search for one or more item IDs.
Matches the given itemids exactly (no fuzzy searching).
E.g.:
['Simula.010', 'Simula.002']
- simula_author_usernames – List of author Plone usernames.
Matches exact usernames (no fuzzy searching).
E.g.:
-
-
class
simula_bibrestclient.client.BibItem(itemid, username, password, folderurl='http://plonerest.simula.no/publications/', **kwargs)[source]¶ Bases:
simula_bibrestclient.client.BibResourceBibliography item (e.g.: ArticleReferece, PhdThesis, Book, ...) REST API.
Note
Why is portal_type a method argument instead of a constructor argument?
Because
getdoes not requireportal_type, and we need to be able to perform aget-request to find theportal_type. We do not store any state in the class, soportal_stateis not automatically maintained internally (since this would require an extra get-request for each update).Parameters: itemid – The id of the bibliography item. -
browser_confirm_delete()[source]¶ Open a webbrowser tab on the
get_browser_deleteurl(). This view asks the user to confirm if they want to delete the item or not.
-
classmethod
decode_pdf(simula_pdf_file_dict)[source]¶ The reverse of
encode_pdf().
-
classmethod
encode_pdf(filename, data, content_type='application/pdf')[source]¶ Create a
simula_pdf_file-compatible dict.Parameters: - filename – The name of the file (E.g.:
"myfile.pdf"). This file is not read from disk, the string is the filename that users get when they download the PDF from the website. - data – A string containing the data of the PDF.
- content_type – The content-type of the file. Defaults to “application/pdf”.
Returns: A
simula_pdf_file-compatible dict wheredatais base64 encoded.- filename – The name of the file (E.g.:
-
classmethod
encode_pdffile(filepath, content_type='application/pdf')[source]¶ Create a
simula_pdf_file-compatible dict from the file at the givenfilepath. Reads the file from disk and usesencode_pdf().Parameters: - filepath – Path to a file on the local filesystem.
- content_type – The content-type of the file. Defaults to “application/pdf”.
-
get_browser_deleteurl()[source]¶ Returns the URL for the confirm-delete view for this bibliography item on the website.
-
get_restapi_url()[source]¶ Returns the REST API URL of this bibliography item. When this URL is opened in a browser, the user sees the docs for the REST API.
-
get_website_url()[source]¶ Returns the URL for this bibliography item on the website (not the REST API url).
Shortcut for
update(portal_state='submit').
-
update(portal_type, portal_state=None, attributes={}, pretend=False)[source]¶ Perform HTTP PUT to update the item bibliography item.
Note
This is a very thin wrapper around
put(). See the source for this method (link on the right hand side) to see what it does.Parameters: - portal_state – Change the state of the bibitem. When an item is
created, its state is
private. Any request changing or getting the item includesportal_state_transitions, which describes the next possible states. - portal_type – The portal_type for the bibliography item.
- attributes – Attributes to update. These are the same as the
attributesdocumented in the REST API docs.
Pretend: Just pretend to make the changes? If
True, no changes are made to the database, however the response will still be just as if we usedpretend=False.- portal_state – Change the state of the bibitem. When an item is
created, its state is
-
-
class
simula_bibrestclient.client.BibResource(url, username, password, mimetype='application/json', decode_output=False)[source]¶ Bases:
restkit.resource.ResourceBase class for the REST APIs.
Parameters: - url – URL to the REST API (including @@rest).
- username – Simula website username.
- password – Simula website password.
- mimetype – See
mimetype. - decode_output – See
decode_output.
-
decode(data)[source]¶ If
decode_outputis True, decode decode the response and return a Python datastructure. Ifdecode_outputis False, returndata.
-
post(requestdata)[source]¶ Perform HTTP POST request with
requestdatain the request body andmimetypein theAcceptheader.Parameters: requestdata – Bytestring encoded with as mimetype.
-
put(requestdata)[source]¶ Perform HTTP PUT request with
requestdatain the request body andmimetypein theAcceptheader.Parameters: requestdata – Bytestring encoded with as mimetype.
-
decode_output= None¶ Decode the response from the server? If not
mimetype=='application/json', this will raise an exception ifTrue.
-
mimetype= None¶ The mimetype to use for input/output