Skip to content

Commit 9df862a

Browse files
refactor: move some utils to core like validation or rate limit
1 parent 902661a commit 9df862a

30 files changed

Lines changed: 89 additions & 86 deletions

hrflow/auth/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import typing as t
22

3-
from ..utils import validate_key, validate_response
3+
from ..core.validation import validate_key, validate_response
44

55
API_SECRET_REGEX = r"^ask[rw]?_[0-9a-f]{32}$"
66

hrflow/board/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from ..utils import (
1+
from ..core.validation import (
22
ORDER_BY_VALUES,
33
validate_key,
44
validate_limit,

hrflow/core/__init__.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import os
2+
3+
from .validation import (
4+
is_valid_extension,
5+
is_valid_filename,
6+
validate_key,
7+
validate_reference,
8+
)
9+
10+
11+
def format_item_payload(item, provider_key, key, reference=None, email=None):
12+
provider = "source_key" if item == "profile" else "board_key"
13+
14+
payload = {provider: validate_key("provider", provider_key)}
15+
if key:
16+
payload["key"] = validate_key("item", key)
17+
if reference:
18+
payload["reference"] = validate_reference(reference)
19+
if email:
20+
payload["profile_email"] = email
21+
22+
return payload
23+
24+
25+
def get_files_from_dir(dir_path, is_recurcive):
26+
file_res = []
27+
files_path = os.listdir(dir_path)
28+
29+
for file_path in files_path:
30+
true_path = os.path.join(dir_path, file_path)
31+
if os.path.isdir(true_path) and is_recurcive:
32+
if is_valid_filename(true_path):
33+
file_res += get_files_from_dir(true_path, is_recurcive)
34+
continue
35+
if is_valid_extension(true_path):
36+
file_res.append(true_path)
37+
return file_res
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
]
3333
INVALID_FILENAME = [".", ".."]
3434

35-
ITEM_TYPE = ["profile", "job"]
36-
3735

3836
def validate_boolean(name, value):
3937
"""

hrflow/job/asking.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import typing as t
22

3-
from ..utils import KEY_REGEX, validate_key, validate_reference, validate_response
3+
from ..core.validation import (
4+
KEY_REGEX,
5+
validate_key,
6+
validate_reference,
7+
validate_response,
8+
)
49

510

611
class JobAsking:

hrflow/job/embedding.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from ..utils import format_item_payload, validate_response
1+
from ..core.validation import validate_response
2+
from ..core import format_item_payload
23

34

45
class JobEmbedding:

hrflow/job/scoring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22

3-
from ..utils import (
3+
from ..core.validation import (
44
ORDER_BY_VALUES,
55
SORT_BY_VALUES,
66
STAGE_VALUES,

hrflow/job/searching.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22

3-
from ..utils import (
3+
from ..core.validation import (
44
ORDER_BY_VALUES,
55
SORT_BY_VALUES,
66
STAGE_VALUES,

hrflow/job/storing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import json
22

3-
from ..utils import (
3+
from ..core.validation import (
44
ORDER_BY_VALUES,
55
SORT_BY_VALUES,
6-
format_item_payload,
76
validate_boolean,
87
validate_key,
98
validate_limit,
@@ -13,6 +12,7 @@
1312
validate_response,
1413
validate_value,
1514
)
15+
from ..core import format_item_payload
1616

1717

1818
class JobStoring:

0 commit comments

Comments
 (0)