-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmatching.py
More file actions
113 lines (104 loc) · 4.54 KB
/
matching.py
File metadata and controls
113 lines (104 loc) · 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import json
from ..core.rate_limit import rate_limiter
from ..core.validation import (
KEY_REGEX,
ORDER_BY_VALUES,
SORT_BY_VALUES,
validate_key,
validate_limit,
validate_page,
validate_provider_keys,
validate_reference,
validate_response,
validate_value,
)
class ProfileMatching:
def __init__(self, api):
"""Initialize the ProfileMatching class with the provided API client."""
self.client = api
@rate_limiter
def list(
self,
source_key,
profile_key=None,
profile_reference=None,
source_keys=None,
page=1,
limit=30,
sort_by="created_at",
order_by=None,
created_at_min=None,
created_at_max=None,
**kwargs,
):
"""
💾 Match Profils indexed in Sources to a Profile
(https://api.hrflow.ai/v1/profils/matching).
Args:
source_key: <string>
The key of the Source in which the profile is indexed.
profile_key: <string> (Optional)
The key of a specific profile to macth with.
profile_reference: <string> (Optional)
The reference of a specific profile to macth with.
source_keys: <list> (Optional)
A list of keys for multiple Sources of profiles to be matched with the profile.
page: <int> (default to 1)
The page number for pagination.
limit: <int> (default to 30)
Number of profiles to fetch per page.
sort_by: <string> (default to "created_at")
The field to sort by.
order_by: <string> (Optional)
The order of sorting, either 'asc' or 'desc'.
created_at_min: <string> (Optional)
The minimum creation date of the profiles in format "YYYY-MM-DD".
created_at_max: <string> (Optional)
The maximum creation date of the profiles in format "YYYY-MM-DD".
Returns:
Match the profile identified by profile_key or profile_reference
and source_key with all profiles in the sources identified by keys in source_keys list.
Response examples:
- Success response:
{
"code": 200, # response code
"message": "Profile Matching results", # response message
"meta": {
'page': 1, # current page
'maxPage': 5, # max page in the paginated response
'count': 2, # number of profiles in the current page
'total': 10 # total number of profiles retrieved
},
"data": { # list of profile objects
"predictions": [[]],
"profiles": [
{
"key": "xxx",
"reference": "xxx",
...
},
...
]
}
}
- Error response: (if the source_key is not valid)
{
"code": 400,
"message": "Invalid parameters. Unable to find object: source"
}
"""
query_params = {
"source_key": validate_key("Source", source_key, regex=KEY_REGEX),
"profile_key": validate_key("Key", profile_key, regex=KEY_REGEX),
"profile_reference": validate_reference(profile_reference),
"source_keys": json.dumps(validate_provider_keys(source_keys)),
"limit": validate_limit(limit),
"page": validate_page(page),
"sort_by": validate_value(sort_by, SORT_BY_VALUES, "sort by"),
"order_by": validate_value(order_by, ORDER_BY_VALUES, "order by"),
"created_at_min": created_at_min, # TODO validate dates format
"created_at_max": created_at_max, # TODO validate dates format
}
params = {**query_params, **kwargs}
response = self.client.get("profiles/matching", params)
return validate_response(response)