Skip to content

Commit

Permalink
Merge pull request #25 from thoth-pub/feature/relation_updated_at
Browse files Browse the repository at this point in the history
Support filtering on multiple work statuses/updated timestamp, for use by dissemination service
  • Loading branch information
rhigman authored Mar 27, 2023
2 parents 459f588 + 1392e60 commit 135bb7e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 252 deletions.
60 changes: 43 additions & 17 deletions thothlibrary/thoth-0_9_0/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,16 +747,19 @@ def subject_count(self, subject_types: str = "", search: str = "",

def works(self, limit: int = 100, offset: int = 0, search: str = "",
order: str = None, publishers: str = None, work_types: str = None,
work_status: str = None, raw: bool = False):
work_status: str = None, work_statuses: str = None,
updated_at_with_relations: str = None, raw: bool = False):
"""
Returns works
@param limit: the maximum number of results to return
@param order: a GraphQL order query statement
@param offset: the offset from which to retrieve results
@param publishers: a list of publishers to limit by
@param search: a filter string to search
@param work_types: the work type (e.g. MONOGRAPH)
@param work_status: the work status (e.g. ACTIVE)
@param work_types: the work types (e.g. [MONOGRAPH, TEXTBOOK])
@param work_status: (deprecated) the work status (e.g. ACTIVE)
@param work_statuses: the work statuses (e.g. [ACTIVE])
@param updated_at_with_relations: timestamp and choice of greater/less than, for limiting results by last update time
@param raw: whether to return a python object or the raw server result
@return: either an object (default) or raw server response
"""
Expand All @@ -775,6 +778,9 @@ def works(self, limit: int = 100, offset: int = 0, search: str = "",
self._dictionary_append(parameters, 'publishers', publishers)
self._dictionary_append(parameters, 'workTypes', work_types)
self._dictionary_append(parameters, 'workStatus', work_status)
self._dictionary_append(parameters, 'workStatuses', work_statuses)
self._dictionary_append(
parameters, 'updatedAtWithRelations', updated_at_with_relations)

return self._api_request("works", parameters, return_raw=raw)

Expand Down Expand Up @@ -804,15 +810,17 @@ def work_by_id(self, work_id: str, raw: bool = False):

return self._api_request("work", parameters, return_raw=raw)

def work_count(self, search: str = "", publishers: str = None,
work_types: str = None, work_status: str = None,
raw: bool = False):
def work_count(self, search: str = "", publishers: str = None, work_types: str = None,
work_status: str = None, work_statuses: str = None,
updated_at_with_relations: str = None, raw: bool = False):
"""
A count of works
@param search: a search string
@param publishers: a list of publishers by which to limit results
@param work_types: the work type (e.g. MONOGRAPH)
@param work_status: the work status (e.g. ACTIVE)
@param work_types: the work types (e.g. [MONOGRAPH, TEXTBOOK])
@param work_status: (deprecated) the work status (e.g. ACTIVE)
@param work_statuses: the work statuses (e.g. [ACTIVE])
@param updated_at_with_relations: timestamp and choice of greater/less than, for limiting results by last update time
@param raw: whether to return a raw result
@return: a count of works
"""
Expand All @@ -825,20 +833,25 @@ def work_count(self, search: str = "", publishers: str = None,
self._dictionary_append(parameters, 'publishers', publishers)
self._dictionary_append(parameters, 'workTypes', work_types)
self._dictionary_append(parameters, 'workStatus', work_status)
self._dictionary_append(parameters, 'workStatuses', work_statuses)
self._dictionary_append(
parameters, 'updatedAtWithRelations', updated_at_with_relations)

return self._api_request("workCount", parameters, return_raw=raw)

def books(self, limit: int = 100, offset: int = 0, search: str = "",
order: str = None, publishers: str = None,
work_status: str = None, raw: bool = False):
order: str = None, publishers: str = None, work_status: str = None,
work_statuses: str = None, updated_at_with_relations: str = None, raw: bool = False):
"""
Returns books
@param limit: the maximum number of results to return
@param order: a GraphQL order query statement
@param offset: the offset from which to retrieve results
@param publishers: a list of publishers to limit by
@param search: a filter string to search
@param work_status: the work status (e.g. ACTIVE)
@param work_status: (deprecated) the work status (e.g. ACTIVE)
@param work_statuses: the work statuses (e.g. [ACTIVE])
@param updated_at_with_relations: timestamp and choice of greater/less than, for limiting results by last update time
@param raw: whether to return a python object or the raw server result
@return: either an object (default) or raw server response
"""
Expand All @@ -856,20 +869,25 @@ def books(self, limit: int = 100, offset: int = 0, search: str = "",
self._dictionary_append(parameters, 'order', order)
self._dictionary_append(parameters, 'publishers', publishers)
self._dictionary_append(parameters, 'workStatus', work_status)
self._dictionary_append(parameters, 'workStatuses', work_statuses)
self._dictionary_append(
parameters, 'updatedAtWithRelations', updated_at_with_relations)

return self._api_request("books", parameters, return_raw=raw)

def bookIds(self, limit: int = 100, offset: int = 0, search: str = "",
order: str = None, publishers: str = None,
work_status: str = None, raw: bool = False):
order: str = None, publishers: str = None, work_status: str = None,
work_statuses: str = None, updated_at_with_relations: str = None, raw: bool = False):
"""
Returns books, in a minimal representation containing only workId
@param limit: the maximum number of results to return
@param order: a GraphQL order query statement
@param offset: the offset from which to retrieve results
@param publishers: a list of publishers to limit by
@param search: a filter string to search
@param work_status: the work status (e.g. ACTIVE)
@param work_status: (deprecated) the work status (e.g. ACTIVE)
@param work_statuses: the work statuses (e.g. [ACTIVE])
@param updated_at_with_relations: timestamp and choice of greater/less than, for limiting results by last update time
@param raw: whether to return a python object or the raw server result
@return: either an object (default) or raw server response
"""
Expand All @@ -887,16 +905,21 @@ def bookIds(self, limit: int = 100, offset: int = 0, search: str = "",
self._dictionary_append(parameters, 'order', order)
self._dictionary_append(parameters, 'publishers', publishers)
self._dictionary_append(parameters, 'workStatus', work_status)
self._dictionary_append(parameters, 'workStatuses', work_statuses)
self._dictionary_append(
parameters, 'updatedAtWithRelations', updated_at_with_relations)

return self._api_request("bookIds", parameters, return_raw=raw)

def book_count(self, search: str = "", publishers: str = None,
work_status: str = None, raw: bool = False):
def book_count(self, search: str = "", publishers: str = None, work_status: str = None,
work_statuses: str = None, updated_at_with_relations: str = None, raw: bool = False):
"""
A count of books
@param search: a search string
@param publishers: a list of publishers by which to limit results
@param work_status: the work status (e.g. ACTIVE)
@param work_status: (deprecated) the work status (e.g. ACTIVE)
@param work_statuses: the work statuses (e.g. [ACTIVE])
@param updated_at_with_relations: timestamp and choice of greater/less than, for limiting results by last update time
@param raw: whether to return a raw result
@return: a count of works
"""
Expand All @@ -908,5 +931,8 @@ def book_count(self, search: str = "", publishers: str = None,
self._dictionary_append(parameters, 'filter', search)
self._dictionary_append(parameters, 'publishers', publishers)
self._dictionary_append(parameters, 'workStatus', work_status)
self._dictionary_append(parameters, 'workStatuses', work_statuses)
self._dictionary_append(
parameters, 'updatedAtWithRelations', updated_at_with_relations)

return self._api_request("bookCount", parameters, return_raw=raw)
Loading

0 comments on commit 135bb7e

Please sign in to comment.