Skip to content

Commit

Permalink
Merge pull request #10 from mailerlite/fix/f-strings
Browse files Browse the repository at this point in the history
added f-strings
  • Loading branch information
nklmilojevic authored Mar 31, 2023
2 parents e5b140d + c120387 commit 8c1703d
Show file tree
Hide file tree
Showing 14 changed files with 896 additions and 368 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
---
name: Release
on:
push:
branches:
- main
name: Test
on: push

jobs:
test:
name: Python ${{ matrix.python-version }} tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
Expand All @@ -25,7 +22,7 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.1.13
version: 1.3.1
virtualenvs-create: true
virtualenvs-in-project: true
- name: Load cached venv
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.1
0.1.2
4 changes: 2 additions & 2 deletions mailerlite/sdk/automations.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get(self, automation_id):
"""

return self.api_client.request(
"GET", "{}/{}".format(self.base_api_url, automation_id)
"GET", f"{self.base_api_url}/{automation_id}"
).json()

def activity(self, automation_id, **kwargs):
Expand Down Expand Up @@ -65,6 +65,6 @@ def activity(self, automation_id, **kwargs):

return self.api_client.request(
"GET",
"{}/{}/activity".format(self.base_api_url, automation_id),
f"{self.base_api_url}/{automation_id}/activity",
query_params,
).json()
4 changes: 1 addition & 3 deletions mailerlite/sdk/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def request(self, requests=[]):

if type(requests) is not list:
raise TypeError(
"`requests` type is not valid. Expected `dict`, got {}.".format(
type(requests)
)
f"`requests` type is not valid. Expected `dict`, got {type(requests)}."
)

body_params = {"requests": requests}
Expand Down
41 changes: 13 additions & 28 deletions mailerlite/sdk/campaigns.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ def update(self, campaign_id, campaign):

if not isinstance(campaign_id, int):
raise TypeError(
"`campaign_id` type is not valid. Expected `int`, got {}.".format(
type(campaign_id)
)
f"`campaign_id` type is not valid. Expected `int`, got {type(campaign_id)}."
)

return self.api_client.request(
"PUT", "{}/{}".format(self.base_api_url, campaign_id), body=campaign
"PUT", f"{self.base_api_url}/{campaign_id}", body=campaign
).json()

def get(self, campaign_id):
Expand All @@ -58,13 +56,11 @@ def get(self, campaign_id):

if not isinstance(campaign_id, int):
raise TypeError(
"`campaign_id` type is not valid. Expected `int`, got {}.".format(
type(campaign_id)
)
f"`campaign_id` type is not valid. Expected `int`, got {type(campaign_id)}."
)

return self.api_client.request(
"GET", "{}/{}".format(self.base_api_url, campaign_id)
"GET", f"{self.base_api_url}/{campaign_id}"
).json()

def list(self, **kwargs):
Expand Down Expand Up @@ -110,14 +106,12 @@ def schedule(self, campaign_id, schedule):

if not isinstance(campaign_id, int):
raise TypeError(
"`campaign_id` type is not valid. Expected `int`, got {}.".format(
type(campaign_id)
)
f"`campaign_id` type is not valid. Expected `int`, got {type(campaign_id)}."
)

return self.api_client.request(
"POST",
"{}/{}/schedule".format(self.base_api_url, campaign_id),
f"{self.base_api_url}/{campaign_id}/schedule",
body=schedule,
).json()

Expand All @@ -135,13 +129,11 @@ def cancel(self, campaign_id):

if not isinstance(campaign_id, int):
raise TypeError(
"`campaign_id` type is not valid. Expected `int`, got {}.".format(
type(campaign_id)
)
f"`campaign_id` type is not valid. Expected `int`, got {type(campaign_id)}."
)

return self.api_client.request(
"POST", "{}/{}/cancel".format(self.base_api_url, campaign_id)
"POST", f"{self.base_api_url}/{campaign_id}/cancel"
).json()

def delete(self, campaign_id):
Expand All @@ -158,13 +150,11 @@ def delete(self, campaign_id):

if not isinstance(campaign_id, int):
raise TypeError(
"`campaign_id` type is not valid. Expected `int`, got {}.".format(
type(campaign_id)
)
f"`campaign_id` type is not valid. Expected `int`, got {type(campaign_id)}."
)

response = self.api_client.request(
"DELETE", "{}/{}".format(self.base_api_url, campaign_id)
"DELETE", f"{self.base_api_url}/{campaign_id}"
)

return True if response.status_code == 204 else False
Expand All @@ -183,14 +173,11 @@ def activity(self, campaign_id):

if not isinstance(campaign_id, int):
raise TypeError(
"`campaign_id` type is not valid. Expected `int`, got {}.".format(
type(campaign_id)
)
f"`campaign_id` type is not valid. Expected `int`, got {type(campaign_id)}."
)

return self.api_client.request(
"POST",
"{}/{}/reports/subscriber-activity".format(self.base_api_url, campaign_id),
"POST", f"{self.base_api_url}/{campaign_id}/reports/subscriber-activity"
).json()

def languages(self):
Expand All @@ -204,6 +191,4 @@ def languages(self):
:rtype: dict
"""

return self.api_client.request(
"GET", "{}/languages".format(self.base_api_url)
).json()
return self.api_client.request("GET", f"{self.base_api_url}/languages").json()
10 changes: 3 additions & 7 deletions mailerlite/sdk/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ def update(self, field_id, name):

if not isinstance(field_id, int):
raise TypeError(
"`field_id` type is not valid. Expected `int`, got {}.".format(
type(field_id)
)
f"`field_id` type is not valid. Expected `int`, got {type(field_id)}."
)

if len(name) > 255:
Expand All @@ -93,7 +91,7 @@ def update(self, field_id, name):
body_params = {"name": name}

return self.api_client.request(
"PUT", "{}/{}".format(self.base_api_url, field_id), body=body_params
"PUT", f"{self.base_api_url}/{field_id}", body=body_params
).json()

def delete(self, field_id):
Expand All @@ -108,8 +106,6 @@ def delete(self, field_id):
:rtype: bool
"""

response = self.api_client.request(
"DELETE", "{}/{}".format(self.base_api_url, field_id)
)
response = self.api_client.request("DELETE", f"{self.base_api_url}/{field_id}")

return True if response.status_code == 204 else False
30 changes: 9 additions & 21 deletions mailerlite/sdk/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def list(self, type, **kwargs):
query_params[key] = val

return self.api_client.request(
"GET", "{}/{}".format(self.base_api_url, type), query_params
"GET", f"{self.base_api_url}/{type}", query_params
).json()

def get(self, form_id):
Expand All @@ -51,14 +51,10 @@ def get(self, form_id):

if not isinstance(form_id, int):
raise TypeError(
"`form_id` type is not valid. Expected `int`, got {}.".format(
type(form_id)
)
f"`form_id` type is not valid. Expected `int`, got {type(form_id)}."
)

return self.api_client.request(
"GET", "{}/{}".format(self.base_api_url, form_id)
).json()
return self.api_client.request("GET", f"{self.base_api_url}/{form_id}").json()

def update(self, form_id, name):
"""
Expand All @@ -75,15 +71,13 @@ def update(self, form_id, name):

if not isinstance(form_id, int):
raise TypeError(
"`form_id` type is not valid. Expected `int`, got {}.".format(
type(form_id)
)
f"`form_id` type is not valid. Expected `int`, got {type(form_id)}."
)

body_params = {"name": name}

return self.api_client.request(
"PUT", "{}/{}".format(self.base_api_url, form_id), body=body_params
"PUT", f"{self.base_api_url}/{form_id}", body=body_params
).json()

def get_subscribers(self, form_id, **kwargs):
Expand All @@ -102,9 +96,7 @@ def get_subscribers(self, form_id, **kwargs):

if not isinstance(form_id, int):
raise TypeError(
"`form_id` type is not valid. Expected `int`, got {}.".format(
type(form_id)
)
f"`form_id` type is not valid. Expected `int`, got {type(form_id)}."
)

available_params = ["limit", "page", "filter"]
Expand All @@ -122,7 +114,7 @@ def get_subscribers(self, form_id, **kwargs):
query_params[key] = val

return self.api_client.request(
"GET", "{}/{}/subscribers".format(self.base_api_url, form_id), query_params
"GET", f"{self.base_api_url}/{form_id}/subscribers", query_params
).json()

def delete(self, form_id):
Expand All @@ -139,13 +131,9 @@ def delete(self, form_id):

if not isinstance(form_id, int):
raise TypeError(
"`form_id` type is not valid. Expected `int`, got {}.".format(
type(form_id)
)
f"`form_id` type is not valid. Expected `int`, got {type(form_id)}."
)

response = self.api_client.request(
"DELETE", "{}/{}".format(self.base_api_url, form_id)
)
response = self.api_client.request("DELETE", f"{self.base_api_url}/{form_id}")

return True if response.status_code == 204 else False
20 changes: 6 additions & 14 deletions mailerlite/sdk/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ def update(self, group_id, name):

if not isinstance(group_id, int):
raise TypeError(
"`group_id` type is not valid. Expected `int`, got {}.".format(
type(group_id)
)
f"`group_id` type is not valid. Expected `int`, got {type(group_id)}."
)

if len(name) > 255:
Expand All @@ -88,7 +86,7 @@ def update(self, group_id, name):
body_params = {"name": name}

return self.api_client.request(
"PUT", "{}/{}".format(self.base_api_url, group_id), body=body_params
"PUT", f"{self.base_api_url}/{group_id}", body=body_params
).json()

def delete(self, group_id):
Expand All @@ -106,14 +104,10 @@ def delete(self, group_id):

if not isinstance(group_id, int):
raise TypeError(
"`group_id` type is not valid. Expected `int`, got {}.".format(
type(group_id)
)
f"`group_id` type is not valid. Expected `int`, got {type(group_id)}."
)

response = self.api_client.request(
"DELETE", "{}/{}".format(self.base_api_url, group_id)
)
response = self.api_client.request("DELETE", f"{self.base_api_url}/{group_id}")

return True if response.status_code == 204 else False

Expand All @@ -134,9 +128,7 @@ def get_group_subscribers(self, group_id, **kwargs):

if not isinstance(group_id, int):
raise TypeError(
"`group_id` type is not valid. Expected `int`, got {}.".format(
type(group_id)
)
f"`group_id` type is not valid. Expected `int`, got {type(group_id)}."
)

available_params = ["filter", "limit", "page"]
Expand All @@ -154,6 +146,6 @@ def get_group_subscribers(self, group_id, **kwargs):

return self.api_client.request(
"GET",
"{}/{}/{}".format(self.base_api_url, group_id, "subscribers"),
f"{self.base_api_url}/{group_id}/subscribers",
query_params,
).json()
18 changes: 6 additions & 12 deletions mailerlite/sdk/segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ def get_subscribers(self, segment_id, **kwargs):

if not isinstance(segment_id, int):
raise TypeError(
"`segment_id` type is not valid. Expected `int`, got {}.".format(
type(segment_id)
)
f"`segment_id` type is not valid. Expected `int`, got {type(segment_id)}."
)

if not isinstance(segment_id, int):
Expand All @@ -67,7 +65,7 @@ def get_subscribers(self, segment_id, **kwargs):
query_params[key] = val

return self.api_client.request(
"GET", "{}/{}".format(self.base_api_url, segment_id), query_params
"GET", f"{self.base_api_url}/{segment_id}", query_params
).json()

def update(self, segment_id, name):
Expand All @@ -87,9 +85,7 @@ def update(self, segment_id, name):

if not isinstance(segment_id, int):
raise TypeError(
"`segment_id` type is not valid. Expected `int`, got {}.".format(
type(segment_id)
)
f"`segment_id` type is not valid. Expected `int`, got {type(segment_id)}."
)

if len(name) > 255:
Expand All @@ -99,7 +95,7 @@ def update(self, segment_id, name):
body_params = {"name": name}

response = self.api_client.request(
"PUT", "{}/{}".format(self.base_api_url, segment_id), body=body_params
"PUT", f"{self.base_api_url}/{segment_id}", body=body_params
)

return True if response.status_code == 200 else False
Expand All @@ -119,13 +115,11 @@ def delete(self, segment_id):

if not isinstance(segment_id, int):
raise TypeError(
"`segment_id` type is not valid. Expected `int`, got {}.".format(
type(segment_id)
)
f"`segment_id` type is not valid. Expected `int`, got {type(segment_id)}."
)

response = self.api_client.request(
"DELETE", "{}/{}".format(self.base_api_url, segment_id)
"DELETE", f"{self.base_api_url}/{segment_id}"
)

return True if response.status_code == 204 else False
Loading

0 comments on commit 8c1703d

Please sign in to comment.