Skip to content

Commit a646afe

Browse files
committed
Node API updated.
1 parent fbf330b commit a646afe

File tree

6 files changed

+548
-158
lines changed

6 files changed

+548
-158
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "moeralib"
7-
version = "0.16.8"
7+
version = "0.17.0"
88
authors = [
99
{name = "Shmuel Leib Melamud", email = "[email protected]"},
1010
]

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = moeralib
3-
version = 0.16.8
3+
version = 0.17.0
44

55
[options]
66
install_requires =

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='moeralib',
5-
version='0.16.8',
5+
version='0.17.0',
66
install_requires=[
77
"requests>=2.32.0",
88
'camel-converter',

src/moeralib/node/node.py

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,51 @@ def search_activity_reactions(self, filter: types.ActivityReactionFilter) -> Lis
2828
)
2929
return structure_list(data, types.ActivityReactionInfo)
3030

31+
def get_search_history(
32+
self, prefix: str | None = None, limit: int | None = None
33+
) -> List[types.SearchHistoryInfo]:
34+
"""
35+
Get a list of previously executed search queries, optionally filtered by the given ``prefix`` and limited by
36+
the given ``limit``. The node may decide to return fewer queries than the given ``limit``. The queries are
37+
always sorted by creation timestamp, descending.
38+
39+
:param prefix: find queries with the specified prefix (case-insensitive)
40+
:param limit: maximum number of queries returned
41+
"""
42+
location = "/activity/search".format()
43+
params = {"prefix": prefix, "limit": limit}
44+
data = self.call(
45+
"get_search_history", location, method="GET", params=params,
46+
schema=schemas.SEARCH_HISTORY_INFO_ARRAY_SCHEMA
47+
)
48+
return structure_list(data, types.SearchHistoryInfo)
49+
50+
def save_to_search_history(self, history_text: types.SearchHistoryText) -> types.SearchHistoryInfo:
51+
"""
52+
Save a search query in the registry.
53+
54+
:param history_text:
55+
"""
56+
location = "/activity/search"
57+
data = self.call(
58+
"save_to_search_history", location, method="POST", body=history_text,
59+
schema=schemas.SEARCH_HISTORY_INFO_SCHEMA
60+
)
61+
return types.SearchHistoryInfo.from_json(data)
62+
63+
def delete_from_search_history(self, query: str) -> types.Result:
64+
"""
65+
Delete a search query from the registry.
66+
67+
:param query: the query to be deleted
68+
"""
69+
location = "/activity/search".format()
70+
params = {"query": query}
71+
data = self.call(
72+
"delete_from_search_history", location, method="DELETE", params=params, schema=schemas.RESULT_SCHEMA
73+
)
74+
return types.Result.from_json(data)
75+
3176
def get_remote_sheriff_orders_slice(
3277
self, after: int | None = None, before: int | None = None, limit: int | None = None
3378
) -> types.SheriffOrdersSliceInfo:
@@ -924,6 +969,23 @@ def get_feed_slice(
924969
)
925970
return types.FeedSliceInfo.from_json(data)
926971

972+
def delete_feed_stories(
973+
self, feed_name: str, type: types.StoryType | None = None, receiver: str | None = None,
974+
recommended: bool | None = None
975+
) -> types.Result:
976+
"""
977+
Delete all stories from the feed with optional filtering.
978+
979+
:param feed_name: name of the feed
980+
:param type: delete only the stories of the given type
981+
:param receiver: delete only the stories about postings located at the given node
982+
:param recommended: delete only the stories about recommended postings
983+
"""
984+
location = "/feeds/{feedName}/stories".format(feedName=quote_plus(feed_name))
985+
params = {"type": type, "receiver": receiver, "recommended": recommended}
986+
data = self.call("delete_feed_stories", location, method="DELETE", params=params, schema=schemas.RESULT_SCHEMA)
987+
return types.Result.from_json(data)
988+
927989
def get_friend_groups(self) -> List[types.FriendGroupInfo]:
928990
"""
929991
Get the list of all groups of friends that exist on the node.
@@ -1652,6 +1714,112 @@ def register_at_push_relay(self, attributes: types.PushRelayClientAttributes) ->
16521714
)
16531715
return types.Result.from_json(data)
16541716

1717+
def get_recommended_postings(
1718+
self, sheriff: str | None = None, limit: int | None = None
1719+
) -> List[types.RecommendedPostingInfo]:
1720+
"""
1721+
Find postings known to the recommendation service and may be of interest to the client. If the client is
1722+
authenticated, the service may tune the recommendations for them.
1723+
1724+
The service may decide to return fewer recommendations than the given ``limit``.
1725+
1726+
:param sheriff: filter out entries prohibited by the given sheriff
1727+
:param limit: maximum number of recommendations returned
1728+
"""
1729+
location = "/recommendations/postings".format()
1730+
params = {"sheriff": sheriff, "limit": limit}
1731+
data = self.call(
1732+
"get_recommended_postings", location, method="GET", params=params,
1733+
schema=schemas.RECOMMENDED_POSTING_INFO_ARRAY_SCHEMA
1734+
)
1735+
return structure_list(data, types.RecommendedPostingInfo)
1736+
1737+
def get_recommended_postings_for_reading(
1738+
self, sheriff: str | None = None, limit: int | None = None
1739+
) -> List[types.RecommendedPostingInfo]:
1740+
"""
1741+
Find postings known to the recommendation service and may be of interest to the client to read them. If the
1742+
client is authenticated, the service may tune the recommendations for them.
1743+
1744+
The service may decide to return fewer recommendations than the given ``limit``.
1745+
1746+
:param sheriff: filter out entries prohibited by the given sheriff
1747+
:param limit: maximum number of recommendations returned
1748+
"""
1749+
location = "/recommendations/postings/reading".format()
1750+
params = {"sheriff": sheriff, "limit": limit}
1751+
data = self.call(
1752+
"get_recommended_postings_for_reading", location, method="GET", params=params,
1753+
schema=schemas.RECOMMENDED_POSTING_INFO_ARRAY_SCHEMA
1754+
)
1755+
return structure_list(data, types.RecommendedPostingInfo)
1756+
1757+
def get_recommended_postings_for_commenting(
1758+
self, sheriff: str | None = None, limit: int | None = None
1759+
) -> List[types.RecommendedPostingInfo]:
1760+
"""
1761+
Find postings known to the recommendation service and may be of interest to the client to take part in the
1762+
discussion. If the client is authenticated, the service may tune the recommendations for them.
1763+
1764+
The service may decide to return fewer recommendations than the given ``limit``.
1765+
1766+
:param sheriff: filter out entries prohibited by the given sheriff
1767+
:param limit: maximum number of recommendations returned
1768+
"""
1769+
location = "/recommendations/postings/commenting".format()
1770+
params = {"sheriff": sheriff, "limit": limit}
1771+
data = self.call(
1772+
"get_recommended_postings_for_commenting", location, method="GET", params=params,
1773+
schema=schemas.RECOMMENDED_POSTING_INFO_ARRAY_SCHEMA
1774+
)
1775+
return structure_list(data, types.RecommendedPostingInfo)
1776+
1777+
def accept_recommended_posting(self, node_name: str, posting_id: str) -> types.Result:
1778+
"""
1779+
Inform the recommendation service that the recommended posting was accepted by the client.
1780+
1781+
:param node_name: name of the remote node
1782+
:param posting_id: ID of the posting on the remote node
1783+
"""
1784+
location = "/recommendations/postings/accepted/{nodeName}/{postingId}".format(
1785+
nodeName=quote_plus(node_name), postingId=quote_plus(posting_id)
1786+
)
1787+
data = self.call("accept_recommended_posting", location, method="POST", schema=schemas.RESULT_SCHEMA)
1788+
return types.Result.from_json(data)
1789+
1790+
def reject_recommended_posting(self, node_name: str, posting_id: str) -> types.Result:
1791+
"""
1792+
Inform the recommendation service that the recommended posting was rejected by the client.
1793+
1794+
:param node_name: name of the remote node
1795+
:param posting_id: ID of the posting on the remote node
1796+
"""
1797+
location = "/recommendations/postings/rejected/{nodeName}/{postingId}".format(
1798+
nodeName=quote_plus(node_name), postingId=quote_plus(posting_id)
1799+
)
1800+
data = self.call("reject_recommended_posting", location, method="POST", schema=schemas.RESULT_SCHEMA)
1801+
return types.Result.from_json(data)
1802+
1803+
def exclude_node_from_recommendations(self, node_name: str) -> types.Result:
1804+
"""
1805+
Ask the recommendation service to exclude all content from the given node from future recommendations.
1806+
1807+
:param node_name: name of the remote node
1808+
"""
1809+
location = "/recommendations/nodes/excluded/{nodeName}".format(nodeName=quote_plus(node_name))
1810+
data = self.call("exclude_node_from_recommendations", location, method="POST", schema=schemas.RESULT_SCHEMA)
1811+
return types.Result.from_json(data)
1812+
1813+
def allow_node_in_recommendations(self, node_name: str) -> types.Result:
1814+
"""
1815+
Allow the recommendation service to include the content from the given node to future recommendations.
1816+
1817+
:param node_name: name of the remote node
1818+
"""
1819+
location = "/recommendations/nodes/excluded/{nodeName}".format(nodeName=quote_plus(node_name))
1820+
data = self.call("allow_node_in_recommendations", location, method="DELETE", schema=schemas.RESULT_SCHEMA)
1821+
return types.Result.from_json(data)
1822+
16551823
def ask_remote_node(self, node_name: str, details: types.AskDescription) -> types.Result:
16561824
"""
16571825
Send a request to the remote node.

0 commit comments

Comments
 (0)