Skip to content

Commit 6cb6eec

Browse files
committed
Add response_format parameter to get_item_info function
1 parent 0ca8835 commit 6cb6eec

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## 3.5.2
2+
### Changed
3+
- Add `response_format` parameter to `get_item_info` function
4+
5+
## 3.5.1
6+
### Changed
7+
- Add timeout argument for the async client
8+
19
## 3.5
210
### Added
311
- Asynchronous API support using `httpx`

metabase_api/_helper_methods.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
def get_item_info(self, item_type
33
, item_id=None, item_name=None
44
, collection_id=None, collection_name=None
5-
, params=None):
5+
, params=None, response_mode=None):
66
'''
77
Return the info for the given item.
88
Use 'params' for providing arguments. E.g. to include tables in the result for databases, use: params={'include':'tables'}
@@ -18,11 +18,15 @@ def get_item_info(self, item_type
1818
raise ValueError('Either the name or id of the {} must be provided.'.format(item_type))
1919
item_id = self.get_item_id(item_type, item_name, collection_id=collection_id, collection_name=collection_name)
2020

21-
res = self.get("/api/{}/{}".format(item_type, item_id), params=params)
22-
if res:
21+
if response_mode == 'raw':
22+
res = self.get("/api/{}/{}".format(item_type, item_id), 'raw', params=params)
2323
return res
2424
else:
25-
raise ValueError('There is no {} with the id "{}"'.format(item_type, item_id))
25+
res = self.get("/api/{}/{}".format(item_type, item_id), params=params)
26+
if res:
27+
return res
28+
else:
29+
raise ValueError('There is no {} with the id "{}"'.format(item_type, item_id))
2630

2731

2832

metabase_api/_helper_methods_async.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
async def get_item_info(self, item_type, item_id=None, item_name=None,
33
collection_id=None, collection_name=None,
4-
params=None):
4+
params=None, response_mode=None):
55
"""Async version of get_item_info"""
66
assert item_type in ['database', 'table', 'card', 'collection', 'dashboard', 'pulse', 'segment']
77

@@ -13,11 +13,15 @@ async def get_item_info(self, item_type, item_id=None, item_name=None,
1313
raise ValueError(f'Either the name or id of the {item_type} must be provided.')
1414
item_id = await self.get_item_id(item_type, item_name, collection_id=collection_id, collection_name=collection_name)
1515

16-
res = await self.get(f"/api/{item_type}/{item_id}", params=params)
17-
if res:
16+
if response_mode == 'raw':
17+
res = await self.get(f"/api/{item_type}/{item_id}", 'raw', params=params)
1818
return res
1919
else:
20-
raise ValueError(f'There is no {item_type} with the id "{item_id}"')
20+
res = await self.get(f"/api/{item_type}/{item_id}", params=params)
21+
if res:
22+
return res
23+
else:
24+
raise ValueError(f'There is no {item_type} with the id "{item_id}"')
2125

2226

2327

setup.py

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

66
setuptools.setup(
77
name="metabase-api",
8-
version="3.5.1",
8+
version="3.5.2",
99
author="Vahid Vaezian",
1010
author_email="vahid.vaezian@gmail.com",
1111
description="A Python Wrapper for Metabase API",

0 commit comments

Comments
 (0)