canonicalwebteam.store-api 7.3.6__tar.gz → 7.3.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (15) hide show
  1. {canonicalwebteam_store_api-7.3.6 → canonicalwebteam_store_api-7.3.8}/PKG-INFO +1 -1
  2. canonicalwebteam_store_api-7.3.8/canonicalwebteam/snap_recommendations.py +74 -0
  3. {canonicalwebteam_store_api-7.3.6 → canonicalwebteam_store_api-7.3.8}/canonicalwebteam/store_api/devicegw.py +4 -1
  4. {canonicalwebteam_store_api-7.3.6 → canonicalwebteam_store_api-7.3.8}/pyproject.toml +1 -1
  5. {canonicalwebteam_store_api-7.3.6 → canonicalwebteam_store_api-7.3.8}/LICENSE +0 -0
  6. {canonicalwebteam_store_api-7.3.6 → canonicalwebteam_store_api-7.3.8}/README.md +0 -0
  7. {canonicalwebteam_store_api-7.3.6 → canonicalwebteam_store_api-7.3.8}/canonicalwebteam/__init__.py +0 -0
  8. {canonicalwebteam_store_api-7.3.6 → canonicalwebteam_store_api-7.3.8}/canonicalwebteam/exceptions.py +0 -0
  9. {canonicalwebteam_store_api-7.3.6 → canonicalwebteam_store_api-7.3.8}/canonicalwebteam/retry_utils.py +0 -0
  10. {canonicalwebteam_store_api-7.3.6 → canonicalwebteam_store_api-7.3.8}/canonicalwebteam/store_api/__init__.py +0 -0
  11. {canonicalwebteam_store_api-7.3.6 → canonicalwebteam_store_api-7.3.8}/canonicalwebteam/store_api/base.py +0 -0
  12. {canonicalwebteam_store_api-7.3.6 → canonicalwebteam_store_api-7.3.8}/canonicalwebteam/store_api/dashboard.py +0 -0
  13. {canonicalwebteam_store_api-7.3.6 → canonicalwebteam_store_api-7.3.8}/canonicalwebteam/store_api/publishergw.py +0 -0
  14. {canonicalwebteam_store_api-7.3.6 → canonicalwebteam_store_api-7.3.8}/canonicalwebteam/stores_web_redis/__init__.py +0 -0
  15. {canonicalwebteam_store_api-7.3.6 → canonicalwebteam_store_api-7.3.8}/canonicalwebteam/stores_web_redis/utility.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: canonicalwebteam.store-api
3
- Version: 7.3.6
3
+ Version: 7.3.8
4
4
  Summary:
5
5
  License: LGPL-3.0
6
6
  License-File: LICENSE
@@ -0,0 +1,74 @@
1
+ from os import getenv
2
+
3
+ from requests import Session
4
+
5
+
6
+ RECOMMENDATIONS_API_URL = getenv(
7
+ "SNAP_RECOMMENDATIONS_API_URL",
8
+ "https://recommendations.snapcraft.io/api/",
9
+ )
10
+
11
+
12
+ class SnapRecommendations:
13
+ """Helpers for Snap Recommendation Service."""
14
+
15
+ def __init__(self, session=Session()):
16
+ self.session = session
17
+ self.base_url = RECOMMENDATIONS_API_URL
18
+
19
+ def get_endpoint_url(self, endpoint: str) -> str:
20
+ return f"{self.base_url}{endpoint}"
21
+
22
+ def _process_response(self, response):
23
+ """
24
+ Process the response from the recommendation service.
25
+ Raises an HTTPError if the request was not successful.
26
+ """
27
+ response.raise_for_status()
28
+ return response.json()
29
+
30
+ def get_categories(self) -> list:
31
+ """
32
+ Return the list of recommendation categories.
33
+
34
+ Endpoint: [GET] /categories
35
+ """
36
+ url = self.get_endpoint_url("categories")
37
+ response = self.session.get(url)
38
+ return self._process_response(response)
39
+
40
+ def get_category(self, category_id: str) -> list:
41
+ """
42
+ Return ranked snaps for a given category.
43
+
44
+ Endpoint: [GET] /category/{id}
45
+ """
46
+ url = self.get_endpoint_url(f"category/{category_id}")
47
+ response = self.session.get(url)
48
+ return self._process_response(response)
49
+
50
+ def get_popular(self) -> list:
51
+ return self.get_category("popular")
52
+
53
+ def get_recent(self) -> list:
54
+ return self.get_category("recent")
55
+
56
+ def get_trending(self) -> list:
57
+ return self.get_category("trending")
58
+
59
+ def get_top_rated(self) -> list:
60
+ return self.get_category("top_rated")
61
+
62
+ def get_recently_updated(
63
+ self, page: int = 1, size: int = 10, timeout: int = 10
64
+ ) -> dict:
65
+ """
66
+ Return recently updated snaps with pagination.
67
+
68
+ Endpoint: [GET] /recently-updated?page=<page>&size=<size>
69
+ Returns: { "page": n, "size": n, "snaps": [ ... ] }
70
+ """
71
+ params = {"page": page, "size": size}
72
+ url = self.get_endpoint_url("recently-updated")
73
+ response = self.session.get(url, params=params, timeout=timeout)
74
+ return self._process_response(response)
@@ -245,7 +245,10 @@ class DeviceGW(Base):
245
245
  params = {}
246
246
  if fields:
247
247
  params = {"fields": ",".join(fields)}
248
- if channel:
248
+ # Having an empty channel string tells details endpoint to
249
+ # not filter by channel. Having None and not including the channel
250
+ # parameter makes the endpoint default to latest/stable channel
251
+ if channel is not None:
249
252
  params["channel"] = channel
250
253
  headers = self.config[api_version].get("headers")
251
254
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = 'canonicalwebteam.store-api'
3
- version = '7.3.6'
3
+ version = '7.3.8'
4
4
  description = ''
5
5
  authors = ['Canonical Web Team <webteam@canonical.com>']
6
6
  license = 'LGPL-3.0'