idonethis: Pass API query parameters as `params` dict in requests methods.
MODIFY
zulip_bots/zulip_bots/bots/idonethis/fixtures/api_noop.json
zulip_bots/zulip_bots/bots/idonethis/fixtures/api_noop.json
"api_url": "https://beta.idonethis.com/api/v2/noop",
"headers": {
"Authorization": "Token 12345678"
- }
+ },
+ "params": null
},
"response": {"doesnt": "matter"},
"response-headers": {

MODIFY
zulip_bots/zulip_bots/bots/idonethis/fixtures/team_list.json
zulip_bots/zulip_bots/bots/idonethis/fixtures/team_list.json
"api_url": "https://beta.idonethis.com/api/v2/teams",
"headers": {
"Authorization": "Token 12345678"
- }
+ },
+ "params": null
},
"response": [
{

MODIFY
zulip_bots/zulip_bots/bots/idonethis/fixtures/test_401.json
zulip_bots/zulip_bots/bots/idonethis/fixtures/test_401.json
"api_url": "https://beta.idonethis.com/api/v2/teams",
"headers": {
"Authorization": "Token 87654321"
- }
+ },
+ "params": null
},
"response": {
"error": "Invalid API Authentication"

MODIFY
zulip_bots/zulip_bots/bots/idonethis/fixtures/test_create_entry.json
zulip_bots/zulip_bots/bots/idonethis/fixtures/test_create_entry.json
},
"headers": {
"Authorization": "Token 12345678"
- }
+ },
+ "params": null
},
"response": {
"body": "something and something else",

MODIFY
zulip_bots/zulip_bots/bots/idonethis/fixtures/test_create_entry_team_2.json
zulip_bots/zulip_bots/bots/idonethis/fixtures/test_create_entry_team_2.json
},
"headers": {
"Authorization": "Token 12345678"
- }
+ },
+ "params": null
},
"response": {
"body": "something and something else",

MODIFY
zulip_bots/zulip_bots/bots/idonethis/fixtures/test_entries_list.json
zulip_bots/zulip_bots/bots/idonethis/fixtures/test_entries_list.json
{
"request": {
- "api_url": "https://beta.idonethis.com/api/v2/entries?team_id=31415926535",
+ "api_url": "https://beta.idonethis.com/api/v2/entries",
"headers": {
"Authorization": "Token 12345678"
+ },
+ "params": {
+ "team_id": "31415926535"
}
},
"response": [

MODIFY
zulip_bots/zulip_bots/bots/idonethis/fixtures/test_show_team.json
zulip_bots/zulip_bots/bots/idonethis/fixtures/test_show_team.json
"api_url": "https://beta.idonethis.com/api/v2/teams/31415926535",
"headers": {
"Authorization": "Token 12345678"
- }
+ },
+ "params": null
},
"response": {
"hash_id": "31415926535",

MODIFY
zulip_bots/zulip_bots/bots/idonethis/idonethis.py
zulip_bots/zulip_bots/bots/idonethis/idonethis.py
@@ -25,12 +25,15 @@ class UnknownCommandSyntax(Exception):
class UnspecifiedProblemException(Exception):
pass
-def make_API_request(endpoint: str, method: str="GET", body: Optional[Dict[str, str]]=None) -> Any:
+def make_API_request(endpoint: str,
+ method: str="GET",
+ body: Optional[Dict[str, str]]=None,
+ params: Optional[Dict[str, str]]=None) -> Any:
headers = {'Authorization': 'Token ' + api_key}
if method == "GET":
- r = requests.get(API_BASE_URL + endpoint, headers=headers)
+ r = requests.get(API_BASE_URL + endpoint, headers=headers, params=params)
elif method == "POST":
- r = requests.post(API_BASE_URL + endpoint, headers=headers, json=body)
+ r = requests.post(API_BASE_URL + endpoint, headers=headers, params=params, json=body)
if r.status_code == 200:
return r.json()
elif r.status_code == 401 and 'error' in r.json() and r.json()['error'] == "Invalid API Authentication":
@@ -54,9 +57,9 @@ def api_show_users(hash_id: str) -> Any:
def api_list_entries(team_id: Optional[str]=None) -> Any:
if team_id:
- return make_API_request("/entries?team_id={}".format(team_id))
+ return make_API_request("/entries", params=dict(team_id=team_id))
else:
- return make_API_request("/entries".format(team_id))
+ return make_API_request("/entries")
def api_create_entry(body: str, team_id: str) -> Any:
return make_API_request("/entries", "POST", {"body": body, "team_id": team_id})

idonethis: Pass API query parameters as `params` dict in requests methods.