canonicalwebteam.store-api 6.1.0__tar.gz → 6.3.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: canonicalwebteam.store-api
3
- Version: 6.1.0
3
+ Version: 6.3.0
4
4
  Summary:
5
5
  License: LGPL-3.0
6
6
  Author: Canonical Web Team
@@ -80,6 +80,15 @@ class Dashboard(Base):
80
80
  )
81
81
  return self.process_response(response)
82
82
 
83
+ def get_account_keys(self, session: dict) -> list:
84
+ """
85
+ Returns the keys associated with a user account
86
+ Documentation:
87
+ https://dashboard.snapcraft.io/docs/reference/v1/account.html#get--dev-api-account
88
+ Endpoint: [GET] https://dashboard.snapcraft.io/dev/api/account
89
+ """
90
+ return self.get_account(session).get("account-keys", [])
91
+
83
92
  def get_account_snaps(self, session: dict) -> dict:
84
93
  """
85
94
  Returns the snaps associated with a user account
@@ -259,7 +268,7 @@ class Dashboard(Base):
259
268
  self,
260
269
  session,
261
270
  snap_id,
262
- data: Optional[str] = None,
271
+ data: Optional[dict] = None,
263
272
  files: Optional[list] = None,
264
273
  ) -> dict:
265
274
  """
@@ -1,26 +1,42 @@
1
1
  from os import getenv
2
2
  from typing import Optional
3
-
4
3
  from requests import Session
5
4
  from canonicalwebteam.store_api.base import Base
6
5
 
7
6
 
8
7
  DEVICEGW_URL = getenv("DEVICEGW_URL", "https://api.snapcraft.io/")
8
+ DEVICEGW_URL_STAGING = getenv(
9
+ "DEVICEGW_URL_STAGING", "https://api.staging.snapcraft.io/"
10
+ )
9
11
 
10
12
 
11
13
  class DeviceGW(Base):
12
- def __init__(self, namespace, session=Session(), store=None):
14
+ def __init__(
15
+ self, namespace, session=Session(), store=None, staging=False
16
+ ):
13
17
  super().__init__(session)
14
- self.config = {
15
- 1: {
16
- "base_url": f"{DEVICEGW_URL}api/v1/{namespace}s/",
17
- "headers": {"X-Ubuntu-Series": "16"},
18
- },
19
- 2: {
20
- "base_url": f"{DEVICEGW_URL}v2/{namespace}s/",
21
- "headers": {"Snap-Device-Series": "16"},
22
- },
23
- }
18
+ if staging:
19
+ self.config = {
20
+ 1: {
21
+ "base_url": f"{DEVICEGW_URL_STAGING}api/v1/{namespace}s/",
22
+ "headers": {"X-Ubuntu-Series": "16"},
23
+ },
24
+ 2: {
25
+ "base_url": f"{DEVICEGW_URL_STAGING}v2/{namespace}s/",
26
+ "headers": {"Snap-Device-Series": "16"},
27
+ },
28
+ }
29
+ else:
30
+ self.config = {
31
+ 1: {
32
+ "base_url": f"{DEVICEGW_URL}api/v1/{namespace}s/",
33
+ "headers": {"X-Ubuntu-Series": "16"},
34
+ },
35
+ 2: {
36
+ "base_url": f"{DEVICEGW_URL}v2/{namespace}s/",
37
+ "headers": {"Snap-Device-Series": "16"},
38
+ },
39
+ }
24
40
 
25
41
  if store:
26
42
  self.config[1]["headers"].update({"X-Ubuntu-Store": store})
@@ -95,25 +111,28 @@ class DeviceGW(Base):
95
111
  category: str = "",
96
112
  architecture: str = "",
97
113
  publisher: str = "",
98
- featured: str = "false",
114
+ featured: str = "",
99
115
  fields: list = [],
100
116
  ) -> dict:
101
117
  """
102
118
  Documentation: https://api.snapcraft.io/docs/search.html#snaps_find
103
- Endpoint: [GET] https://api.snapcraft.io/v2/snaps/find
119
+ Endpoint: [GET] https://api.snapcraft.io/v2/{namespace}/find
104
120
  """
105
121
  url = self.get_endpoint_url("find", 2)
106
122
  headers = self.config[2].get("headers")
107
- params = {
108
- "q": query,
109
- "category": category,
110
- "architecture": architecture,
111
- "publisher": publisher,
112
- "featured": featured,
113
- }
123
+ params = {"q": query}
114
124
  if fields:
115
125
  params["fields"] = ",".join(fields)
126
+ if architecture:
127
+ params["architecture"] = architecture
128
+ if category:
129
+ params["category"] = category
130
+ if publisher:
131
+ params["publisher"] = publisher
132
+ if featured:
133
+ params["featured"] = featured
116
134
  response = self.session.get(url, params=params, headers=headers)
135
+ # pprint(response.json())
117
136
  return self.process_response(response)
118
137
 
119
138
  def get_all_items(self, size: int, api_version: int = 1) -> dict:
@@ -193,7 +212,7 @@ class DeviceGW(Base):
193
212
  """
194
213
  Documentation: https://api.snapcraft.io/docs/info.html
195
214
  Endpoint: [GET]
196
- https://api.snapcraft.io/api/v2/{name_space}/info/{package_name}
215
+ https://api.snapcraft.io/v2/{name_space}/info/{package_name}
197
216
  """
198
217
  url = self.get_endpoint_url("info/" + name, api_version)
199
218
  params = {}
@@ -229,7 +248,7 @@ class DeviceGW(Base):
229
248
  ) -> dict:
230
249
  """
231
250
  Documentation: https://api.snapcraft.io/docs/categories.html
232
- Endpoint: https://api.snapcraft.io/api/v2/{name_space}/categories
251
+ Endpoint: https://api.snapcraft.io/v2/{name_space}/categories
233
252
  """
234
253
  url = self.get_endpoint_url("categories", api_version)
235
254
  return self.process_response(
@@ -247,7 +266,7 @@ class DeviceGW(Base):
247
266
  Documentation:
248
267
  https://api.snapcraft.io/docs/charms.html#list_resource_revisions
249
268
  Endpoint:
250
- https://api.snapcraft.io/api/v2/charms/resources/{package_name}/{resource_name}/revisions
269
+ https://api.snapcraft.io/v2/charms/resources/{package_name}/{resource_name}/revisions
251
270
  """
252
271
  url = self.get_endpoint_url(
253
272
  f"resources/{name}/{resource_name}/revisions", api_version
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = 'canonicalwebteam.store-api'
3
- version = '6.1.0'
3
+ version = '6.3.0'
4
4
  description = ''
5
5
  authors = ['Canonical Web Team <webteam@canonical.com>']
6
6
  license = 'LGPL-3.0'