Skip to content

Commit be7d4db

Browse files
Update validate.py: using helper to build path with encoded params on the fly.
1 parent 0014102 commit be7d4db

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

jigsawstack/validate.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from ._config import ClientConfig
66
from typing import Any, Dict, List, cast
77
from typing_extensions import NotRequired, TypedDict
8+
from .helpers import build_path
89

910

1011
class Spam(TypedDict):
@@ -86,8 +87,11 @@ def __init__(
8687
)
8788

8889
def email(self, params: EmailValidationParams) -> EmailValidationResponse:
89-
email = params.get("email")
90-
path = f"/validate/email?email={email}"
90+
path = build_path(
91+
base_path="/validate/email",
92+
params=params,
93+
)
94+
9195
resp = Request(
9296
config=self.config,
9397
path=path,
@@ -110,23 +114,25 @@ def nsfw(self, params: NSFWParams) -> NSFWResponse:
110114
return resp
111115

112116
def profanity(self, params: ProfanityParams) -> ProfanityResponse:
113-
text = params.get("text")
114-
censor_replacement = params.get("censor_replacement", "*")
115-
path = f"/validate/profanity"
117+
path = build_path(
118+
base_path="/validate/profanity",
119+
params=params,
120+
)
116121
resp = Request(
117122
config=self.config,
118123
path=path,
119124
params=cast(
120-
Dict[Any, Any], {"text": text, "censor_replacement": censor_replacement}
125+
Dict[Any, Any], params
121126
),
122127
verb="post",
123128
).perform_with_content()
124129
return resp
125130

126131
def spellcheck(self, params: SpellCheckParams) -> SpellCheckResponse:
127-
text = params.get("text")
128-
language_code = params.get("language_code", "en")
129-
path = f"/validate/spell_check?text={text}&language_code={language_code}"
132+
path = build_path(
133+
base_path="/validate/spell_check",
134+
params=params,
135+
)
130136
resp = Request(
131137
config=self.config,
132138
path=path,
@@ -164,8 +170,7 @@ def __init__(
164170
)
165171

166172
async def email(self, params: EmailValidationParams) -> EmailValidationResponse:
167-
email = params.get("email")
168-
path = f"/validate/email?email={email}"
173+
path = bui
169174
resp = await AsyncRequest(
170175
config=self.config,
171176
path=path,
@@ -188,23 +193,25 @@ async def nsfw(self, params: NSFWParams) -> NSFWResponse:
188193
return resp
189194

190195
async def profanity(self, params: ProfanityParams) -> ProfanityResponse:
191-
text = params.get("text")
192-
censor_replacement = params.get("censor_replacement", "*")
193-
path = f"/validate/profanity"
196+
path = build_path(
197+
base_path="/validate/profanity",
198+
params=params,
199+
)
194200
resp = await AsyncRequest(
195201
config=self.config,
196202
path=path,
197203
params=cast(
198-
Dict[Any, Any], {"text": text, "censor_replacement": censor_replacement}
204+
Dict[Any, Any], params
199205
),
200206
verb="post",
201207
).perform_with_content()
202208
return resp
203209

204210
async def spellcheck(self, params: SpellCheckParams) -> SpellCheckResponse:
205-
text = params.get("text")
206-
language_code = params.get("language_code", "en")
207-
path = f"/validate/spell_check?text={text}&language_code={language_code}"
211+
path = build_path(
212+
base_path="/validate/spell_check",
213+
params=params,
214+
)
208215
resp = await AsyncRequest(
209216
config=self.config,
210217
path=path,

0 commit comments

Comments
 (0)