Skip to content

Commit ae90099

Browse files
authored
Add playlist and team support (#10)
* Update the documentation
1 parent 4fb675a commit ae90099

File tree

18 files changed

+1820
-28
lines changed

18 files changed

+1820
-28
lines changed

.github/workflows/integrationtest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ jobs:
2525
GRAFANA_DASHBOARD_PATH: ${{ secrets.GRAFANA_DASHBOARD_PATH }}
2626
GRAFANA_DASHBOARD_NAME: ${{ secrets.GRAFANA_DASHBOARD_NAME }}
2727
GRAFANA_USERNAME: ${{ secrets.GRAFANA_USERNAME }}
28-
GRAFANA_PASSWORD: ${{ secrets.GRAFANA_PASSWORD }}
28+
GRAFANA_PASSWORD: ${{ secrets.GRAFANA_PASSWORD }}

README.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ In general my focus inside this project is to implement and deliver old and new
125125
- Create a short url
126126

127127
### User
128-
- Search Users
128+
- Search users
129129
- Get user by id
130130
- Get user by username or email
131131
- Update the user
@@ -150,6 +150,27 @@ In general my focus inside this project is to implement and deliver old and new
150150
- Delete snapshot by key
151151
- Delete snapshot by delete key
152152

153+
### Team
154+
- Search team
155+
- Get team by id
156+
- Add team
157+
- Update team
158+
- Delete team by id
159+
- Get team members
160+
- Add team member
161+
- Delete team member
162+
- Get team preferences
163+
- Update team preferences
164+
165+
### Playlist
166+
- Search playlist
167+
- Get playlist
168+
- Get playlist items
169+
- Get playlist dashboards
170+
- Create playlist
171+
- Update playlist
172+
- Delete playlist
173+
153174
## Feature timeline
154175

155176
The following table describes the plan to implement the rest of the Grafana API functionality. Please, open an issue and vote them up, if you prefer a faster implementation of an API functionality.
@@ -163,11 +184,10 @@ The following table describes the plan to implement the rest of the Grafana API
163184
| [Fine-grained access control HTTP API](https://grafana.com/docs/grafana/latest/http_api/access_control/) | | | | |
164185
| [HTTP Preferences API](https://grafana.com/docs/grafana/latest/http_api/preferences/) | | | | |
165186
| [Library Element HTTP API](https://grafana.com/docs/grafana/latest/http_api/library_element/) | | | | |
166-
| [Licensing HTTP API](https://grafana.com/docs/grafana/latest/http_api/licensing/) | | | | |
167-
| [Other HTTP API](https://grafana.com/docs/grafana/latest/http_api/other/) | | | | |
168-
| [Playlist HTTP API](https://grafana.com/docs/grafana/latest/http_api/playlist/) | 20 | [ZPascal](https://github.com/ZPascal) | | |
169-
| [Reporting API](https://grafana.com/docs/grafana/latest/http_api/reporting/) | | | | |
170-
| [Team HTTP API](https://grafana.com/docs/grafana/latest/http_api/team/) | 20 | [ZPascal](https://github.com/ZPascal) | | |
187+
| [Licensing HTTP API](https://grafana.com/docs/grafana/latest/http_api/licensing/) | 22 | [ZPascal](https://github.com/ZPascal) | | |
188+
| [Other HTTP API](https://grafana.com/docs/grafana/latest/http_api/other/) | 22 | [ZPascal](https://github.com/ZPascal) | | |
189+
| [Query History API](https://grafana.com/docs/grafana/latest/http_api/query_history/) | 22 | [ZPascal](https://github.com/ZPascal) | | |
190+
| [Reporting API](https://grafana.com/docs/grafana/latest/http_api/reporting/) | 22 | [ZPascal](https://github.com/ZPascal) | | |
171191

172192
## Installation
173193

docs/content/grafana_api/model.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
* [AlertmanagerReceivers](#grafana_api.model.AlertmanagerReceivers)
1313
* [RulerRule](#grafana_api.model.RulerRule)
1414
* [UserObject](#grafana_api.model.UserObject)
15+
* [PlaylistObject](#grafana_api.model.PlaylistObject)
16+
* [PlaylistItemObject](#grafana_api.model.PlaylistItemObject)
17+
* [TeamObject](#grafana_api.model.TeamObject)
1518

1619
<a id="grafana_api.model"></a>
1720

@@ -207,3 +210,52 @@ The class includes all necessary variables to generate a User object that is nec
207210
- `login` _str_ - Specify the expression of the rule
208211
- `theme` _str_ - Specify the Grafana alert of the rule
209212

213+
<a id="grafana_api.model.PlaylistObject"></a>
214+
215+
## PlaylistObject Objects
216+
217+
```python
218+
class PlaylistObject(NamedTuple)
219+
```
220+
221+
The class includes all necessary variables to generate a playlist object
222+
223+
**Arguments**:
224+
225+
- `name` _str_ - Specify the name of the playlist
226+
- `interval` _str_ - Specify the interval of the playlist
227+
- `items` _list_ - Specify a list of PlaylistItemObjects
228+
229+
<a id="grafana_api.model.PlaylistItemObject"></a>
230+
231+
## PlaylistItemObject Objects
232+
233+
```python
234+
class PlaylistItemObject(NamedTuple)
235+
```
236+
237+
The class includes all necessary variables to generate a playlist item object that is necessary to update a playlist
238+
239+
**Arguments**:
240+
241+
- `type` _str_ - Specify the type of the playlist item
242+
- `value` _str_ - Specify the value of the playlist item
243+
- `order` _int_ - Specify the order of the playlist item
244+
- `title` _str_ - Specify the title of the playlist item
245+
246+
<a id="grafana_api.model.TeamObject"></a>
247+
248+
## TeamObject Objects
249+
250+
```python
251+
class TeamObject(NamedTuple)
252+
```
253+
254+
The class includes all necessary variables to generate a team object that is necessary to create a team
255+
256+
**Arguments**:
257+
258+
- `name` _str_ - Specify the name of the team
259+
- `email` _str_ - Specify the email of the team
260+
- `org_id` _int_ - Specify the org_id of the team
261+

docs/content/index.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ The following list describes the currently supported features of the Grafana API
1919
- [ ] [External Group Sync HTTP API](https://grafana.com/docs/grafana/latest/http_api/external_group_sync/)
2020
- [ ] [Fine-grained access control HTTP API](https://grafana.com/docs/grafana/latest/http_api/access_control/)
2121
- [ ] [HTTP Preferences API](https://grafana.com/docs/grafana/latest/http_api/preferences/)
22-
- [ ] [HTTP Snapshot API](https://grafana.com/docs/grafana/latest/http_api/snapshot/)
22+
- [x] [HTTP Snapshot API](https://grafana.com/docs/grafana/latest/http_api/snapshot/)
2323
- [ ] [Library Element HTTP API](https://grafana.com/docs/grafana/latest/http_api/library_element/)
2424
- [ ] [Licensing HTTP API](https://grafana.com/docs/grafana/latest/http_api/licensing/)
25-
- [ ] [Organization HTTP API](https://grafana.com/docs/grafana/latest/http_api/org/)
25+
- [x] [Organization HTTP API](https://grafana.com/docs/grafana/latest/http_api/org/)
2626
- [ ] [Other HTTP API](https://grafana.com/docs/grafana/latest/http_api/other/)
27-
- [ ] [Playlist HTTP API](https://grafana.com/docs/grafana/latest/http_api/playlist/)
27+
- [x] [Playlist HTTP API](https://grafana.com/docs/grafana/latest/http_api/playlist/)
2828
- [ ] [Reporting API](https://grafana.com/docs/grafana/latest/http_api/reporting/)
29-
- [ ] [Short URL HTTP API](https://grafana.com/docs/grafana/latest/http_api/short_url/)
30-
- [ ] [Team HTTP API](https://grafana.com/docs/grafana/latest/http_api/team/)
31-
- [ ] [User HTTP API](https://grafana.com/docs/grafana/latest/http_api/user/)
29+
- [x] [Short URL HTTP API](https://grafana.com/docs/grafana/latest/http_api/short_url/)
30+
- [x] [Team HTTP API](https://grafana.com/docs/grafana/latest/http_api/team/)
31+
- [x] [User HTTP API](https://grafana.com/docs/grafana/latest/http_api/user/)
3232

3333
## Installation
3434

docs/grafana_api_sdk.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ The following list describes the currently supported features of the Grafana API
1919
- [ ] [External Group Sync HTTP API](https://grafana.com/docs/grafana/latest/http_api/external_group_sync/)
2020
- [ ] [Fine-grained access control HTTP API](https://grafana.com/docs/grafana/latest/http_api/access_control/)
2121
- [ ] [HTTP Preferences API](https://grafana.com/docs/grafana/latest/http_api/preferences/)
22-
- [ ] [HTTP Snapshot API](https://grafana.com/docs/grafana/latest/http_api/snapshot/)
22+
- [x] [HTTP Snapshot API](https://grafana.com/docs/grafana/latest/http_api/snapshot/)
2323
- [ ] [Library Element HTTP API](https://grafana.com/docs/grafana/latest/http_api/library_element/)
2424
- [ ] [Licensing HTTP API](https://grafana.com/docs/grafana/latest/http_api/licensing/)
25-
- [ ] [Organization HTTP API](https://grafana.com/docs/grafana/latest/http_api/org/)
25+
- [x] [Organization HTTP API](https://grafana.com/docs/grafana/latest/http_api/org/)
2626
- [ ] [Other HTTP API](https://grafana.com/docs/grafana/latest/http_api/other/)
27-
- [ ] [Playlist HTTP API](https://grafana.com/docs/grafana/latest/http_api/playlist/)
27+
- [x] [Playlist HTTP API](https://grafana.com/docs/grafana/latest/http_api/playlist/)
2828
- [ ] [Reporting API](https://grafana.com/docs/grafana/latest/http_api/reporting/)
29-
- [ ] [Short URL HTTP API](https://grafana.com/docs/grafana/latest/http_api/short_url/)
30-
- [ ] [Team HTTP API](https://grafana.com/docs/grafana/latest/http_api/team/)
31-
- [ ] [User HTTP API](https://grafana.com/docs/grafana/latest/http_api/user/)
29+
- [x] [Short URL HTTP API](https://grafana.com/docs/grafana/latest/http_api/short_url/)
30+
- [x] [Team HTTP API](https://grafana.com/docs/grafana/latest/http_api/team/)
31+
- [x] [User HTTP API](https://grafana.com/docs/grafana/latest/http_api/user/)
3232

3333
## Installation
3434

setup.py

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

99
setuptools.setup(
1010
name="grafana-api-sdk",
11-
version="0.0.4",
11+
version="0.0.5",
1212
author="Pascal Zimmermann",
1313
author_email="[email protected]",
1414
description="A Grafana API SDK",

src/grafana_api/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
23
import requests
34

45
from .model import RequestsMethods, ERROR_MESSAGES, APIModel
@@ -107,7 +108,7 @@ def __check_the_api_call_response(response: any = None) -> any:
107108
api_call (any): Returns the value of the api call
108109
"""
109110

110-
if type(response.json()) == dict:
111+
if len(response.text) != 0 and type(response.json()) == dict:
111112
if (
112113
"message" in response.json().keys()
113114
and response.json()["message"] in ERROR_MESSAGES

src/grafana_api/model.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class APIEndpoints(Enum):
2929
USERS = f"{api_prefix}/users"
3030
SNAPSHOTS = f"{api_prefix}/snapshots"
3131
DASHBOARD_SNAPSHOTS = f"{api_prefix}/dashboard/snapshots"
32+
PLAYLISTS = f"{api_prefix}/playlists"
33+
TEAMS = f"{api_prefix}/teams"
3234

3335

3436
class RequestsMethods(Enum):
@@ -218,3 +220,47 @@ class UserObject(NamedTuple):
218220
name: str
219221
login: str
220222
theme: str
223+
224+
225+
class PlaylistObject(NamedTuple):
226+
"""The class includes all necessary variables to generate a playlist object
227+
228+
Args:
229+
name (str): Specify the name of the playlist
230+
interval (str): Specify the interval of the playlist
231+
items (list): Specify a list of PlaylistItemObjects
232+
"""
233+
234+
name: str
235+
interval: str
236+
items: list
237+
238+
239+
class PlaylistItemObject(NamedTuple):
240+
"""The class includes all necessary variables to generate a playlist item object that is necessary to update a playlist
241+
242+
Args:
243+
type (str): Specify the type of the playlist item
244+
value (str): Specify the value of the playlist item
245+
order (int): Specify the order of the playlist item
246+
title (str): Specify the title of the playlist item
247+
"""
248+
249+
type: str
250+
value: str
251+
order: int
252+
title: str
253+
254+
255+
class TeamObject(NamedTuple):
256+
"""The class includes all necessary variables to generate a team object that is necessary to create a team
257+
258+
Args:
259+
name (str): Specify the name of the team
260+
email (str): Specify the email of the team
261+
org_id (int): Specify the org_id of the team
262+
"""
263+
264+
name: str
265+
email: str
266+
org_id: int

0 commit comments

Comments
 (0)