aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2019-10-12 21:02:39 +0200
committerLorenz Diener <[email protected]>2019-10-12 21:02:39 +0200
commit3194b1295e8f4a6d151d18ad4f23174c63408c05 (patch)
tree15e126c70b7241bf7c8295cc74ee18bd7a700d22
parent2e5095f301c62c73f6b839bbbffeda14ab8cd797 (diff)
downloadmastodon.py-3194b1295e8f4a6d151d18ad4f23174c63408c05.tar.gz
Re-add and test trends API
-rw-r--r--docs/index.rst5
-rw-r--r--mastodon/Mastodon.py22
-rw-r--r--tests/cassettes/test_trends.yaml29
-rw-r--r--tests/test_instance.py5
4 files changed, 61 insertions, 0 deletions
diff --git a/docs/index.rst b/docs/index.rst
index 0ec0f75..c0aebb7 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -949,6 +949,11 @@ Reading data: Searching
949.. automethod:: Mastodon.search 949.. automethod:: Mastodon.search
950.. automethod:: Mastodon.search_v2 950.. automethod:: Mastodon.search_v2
951 951
952Reading data: Trends
953--------------------
954
955.. automethod:: Mastodon.trends
956
952Reading data: Mutes and blocks 957Reading data: Mutes and blocks
953------------------------------ 958------------------------------
954These functions allow you to get information about accounts that are 959These functions allow you to get information about accounts that are
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 1561fa1..899aae4 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -1313,6 +1313,28 @@ class Mastodon:
1313 return self.__api_request('GET', '/api/v2/search', params) 1313 return self.__api_request('GET', '/api/v2/search', params)
1314 1314
1315 ### 1315 ###
1316 # Reading data: Trends
1317 ###
1318 @api_version("2.4.3", "3.0.0", __DICT_VERSION_HASHTAG)
1319 def trends(self, limit = None):
1320 """
1321 Fetch trending-hashtag information, if the instance provides such information.
1322
1323 Specify `limit` to limit how many results are returned (the maximum number
1324 of results is 10, the endpoint is not paginated).
1325
1326 Does not require authentication unless locked down by the administrator.
1327
1328 Important versioning note: This endpoint does not exist for Mastodon versions
1329 between 2.8.0 (inclusive) and 3.0.0 (exclusive).
1330
1331 Returns a list of `hashtag dicts`_, sorted by the instances trending algorithm,
1332 descending.
1333 """
1334 params = self.__generate_params(locals())
1335 return self.__api_request('GET', '/api/v1/trends', params)
1336
1337 ###
1316 # Reading data: Lists 1338 # Reading data: Lists
1317 ### 1339 ###
1318 @api_version("2.1.0", "2.1.0", __DICT_VERSION_LIST) 1340 @api_version("2.1.0", "2.1.0", __DICT_VERSION_LIST)
diff --git a/tests/cassettes/test_trends.yaml b/tests/cassettes/test_trends.yaml
new file mode 100644
index 0000000..15cfd9b
--- /dev/null
+++ b/tests/cassettes/test_trends.yaml
@@ -0,0 +1,29 @@
1interactions:
2- request:
3 body: null
4 headers:
5 Accept: ['*/*']
6 Accept-Encoding: ['gzip, deflate']
7 Authorization: [Bearer __MASTODON_PY_TEST_ACCESS_TOKEN]
8 Connection: [keep-alive]
9 User-Agent: [python-requests/2.18.4]
10 method: GET
11 uri: http://localhost:3000/api/v1/trends
12 response:
13 body: {string: '[]'}
14 headers:
15 Cache-Control: ['no-cache, no-store']
16 Content-Type: [application/json; charset=utf-8]
17 Referrer-Policy: [strict-origin-when-cross-origin]
18 Transfer-Encoding: [chunked]
19 Vary: ['Accept-Encoding, Origin']
20 X-Content-Type-Options: [nosniff]
21 X-Download-Options: [noopen]
22 X-Frame-Options: [SAMEORIGIN]
23 X-Permitted-Cross-Domain-Policies: [none]
24 X-Request-Id: [cd891bac-8b4d-476e-b767-2346ff6f498e]
25 X-Runtime: ['0.074803']
26 X-XSS-Protection: [1; mode=block]
27 content-length: ['2']
28 status: {code: 200, message: OK}
29version: 1
diff --git a/tests/test_instance.py b/tests/test_instance.py
index 343af18..e7dee1f 100644
--- a/tests/test_instance.py
+++ b/tests/test_instance.py
@@ -43,3 +43,8 @@ def test_nodeinfo(api):
43 assert nodeinfo 43 assert nodeinfo
44 assert nodeinfo.version == '2.0' 44 assert nodeinfo.version == '2.0'
45 45
46
47@pytest.mark.vcr()
48def test_trends(api):
49 assert isinstance(api.trends(), list)
50
Powered by cgit v1.2.3 (git 2.41.0)