Skip to content

Commit 1581ce1

Browse files
riquelme222Moustapha Ebnou
andauthored
Minor/edit objects with reference or key (#9)
* doc: update notebooks example to match latest release 3.1.0 * Minor: Edit stored objects either by reference/key provided in the object json --------- Co-authored-by: Moustapha Ebnou <moustapha.ebnou@hrflow.ai>
1 parent 84f3b7c commit 1581ce1

5 files changed

Lines changed: 183 additions & 43 deletions

File tree

examples/job/job_endpoints_examples.ipynb

Lines changed: 86 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
},
1111
{
1212
"cell_type": "code",
13-
"execution_count": 2,
13+
"execution_count": 1,
1414
"metadata": {},
1515
"outputs": [],
1616
"source": [
@@ -35,7 +35,7 @@
3535
},
3636
{
3737
"cell_type": "code",
38-
"execution_count": 3,
38+
"execution_count": 4,
3939
"metadata": {},
4040
"outputs": [],
4141
"source": [
@@ -293,30 +293,108 @@
293293
},
294294
{
295295
"cell_type": "code",
296-
"execution_count": null,
296+
"execution_count": 7,
297297
"metadata": {},
298-
"outputs": [],
298+
"outputs": [
299+
{
300+
"data": {
301+
"text/plain": [
302+
"{'code': 200,\n",
303+
" 'message': 'Job edited',\n",
304+
" 'data': {'id': 1264450,\n",
305+
" 'key': '8cee3ead87a38cc1f7f3cf9298b7e58e16406e05',\n",
306+
" 'reference': 'my_custom_reference',\n",
307+
" 'board_key': '7fce016712fa373456ef279c297da5009a2020d9',\n",
308+
" 'board': {'key': '7fce016712fa373456ef279c297da5009a2020d9',\n",
309+
" 'name': 'vulcain_test',\n",
310+
" 'type': 'api',\n",
311+
" 'subtype': 'python',\n",
312+
" 'environment': 'production'},\n",
313+
" 'name': 'Data Engineer',\n",
314+
" 'url': 'https://www.pole-emploi.ai/jobs/data_engineer',\n",
315+
" 'picture': None,\n",
316+
" 'summary': 'As an engineer for the Data Engineering Infrastructure team, you will design, build, scale, and evolve our data engineering platform, services and tooling. Your work will have a critical impact on all areas of business:supporting detailed internal analytics, calculating customer usage, securing our platform, and much more.',\n",
317+
" 'location': {'text': 'Dampierre en Burly (45)',\n",
318+
" 'lat': None,\n",
319+
" 'lng': None,\n",
320+
" 'gmaps': None,\n",
321+
" 'fields': []},\n",
322+
" 'archive': None,\n",
323+
" 'archived_at': None,\n",
324+
" 'updated_at': '2023-06-21T15:54:45+0000',\n",
325+
" 'created_at': '2023-06-21T15:54:45+0000',\n",
326+
" 'sections': [{'name': 'section 1',\n",
327+
" 'title': 'title section 1',\n",
328+
" 'description': 'text section 1'}],\n",
329+
" 'culture': 'This is a New CULTURE 123!!',\n",
330+
" 'responsibilities': 'FILL THIS WITH A TEXT ABOUT THE RESPONSIBILITIES OF THE JOB',\n",
331+
" 'requirements': 'FILL THIS WITH A TEXT ABOUT THE REQUIREMENTS OF THE JOB',\n",
332+
" 'benefits': 'FILL THIS WITH A TEXT ABOUT THE BENEFITS OF THE JOB',\n",
333+
" 'interviews': 'FILL THIS WITH A TEXT ABOUT THE INTERVIEWS OF THE JOB',\n",
334+
" 'skills': [{'name': 'python', 'value': None, 'type': 'hard'},\n",
335+
" {'name': 'spark', 'value': 0.9, 'type': 'hard'}],\n",
336+
" 'languages': [{'name': 'english', 'value': None},\n",
337+
" {'name': 'french', 'value': None}],\n",
338+
" 'certifications': [],\n",
339+
" 'courses': [],\n",
340+
" 'tasks': [],\n",
341+
" 'tags': [{'name': 'company', 'value': 'Google'}],\n",
342+
" 'metadatas': [{'name': 'metadata example', 'value': 'metadata'}],\n",
343+
" 'ranges_float': [{'name': 'salary',\n",
344+
" 'value_min': 45000,\n",
345+
" 'value_max': 50000,\n",
346+
" 'unit': 'eur'}],\n",
347+
" 'ranges_date': [{'name': 'interview_dates',\n",
348+
" 'value_min': '2023-05-18T21:59',\n",
349+
" 'value_max': '2023-09-15T21:59'}]}}"
350+
]
351+
},
352+
"execution_count": 7,
353+
"metadata": {},
354+
"output_type": "execute_result"
355+
}
356+
],
299357
"source": [
300358
"# Edit a job : edit is a Put not a Patch so you need to provide all the fields\n",
301359
"\n",
302360
"# let's get the job by reference\n",
303-
"reference = \"a2n1j000000g0AAAAY\" # <-- Replace with your job reference\n",
361+
"reference = \"my_custom_reference\" # <-- Replace with your job reference\n",
304362
"\n",
305363
"response = client.job.storing.get(board_key=board_key, reference=reference)\n",
306364
"\n",
307365
"job = response['data']\n",
308366
"\n",
309367
"# edit a field or more \n",
310-
"job['culture'] = \"This is a New CULTURE !!!\"\n",
368+
"job['culture'] = \"This is a New CULTURE 123!!\"\n",
311369
"\n",
312370
"# edit the job\n",
313371
"response = client.job.storing.edit(board_key=board_key,\n",
314-
" key=job['key'],\n",
372+
" # key=job['key'], # This is Optional, fand left for backward compatibility\n",
315373
" job_json=job)\n",
316374
"\n",
317375
"response"
318376
]
319377
},
378+
{
379+
"cell_type": "code",
380+
"execution_count": 8,
381+
"metadata": {},
382+
"outputs": [
383+
{
384+
"data": {
385+
"text/plain": [
386+
"'This is a New CULTURE !!'"
387+
]
388+
},
389+
"execution_count": 8,
390+
"metadata": {},
391+
"output_type": "execute_result"
392+
}
393+
],
394+
"source": [
395+
"response[\"data\"][\"culture\"]"
396+
]
397+
},
320398
{
321399
"cell_type": "code",
322400
"execution_count": null,
@@ -341,7 +419,7 @@
341419
"name": "python",
342420
"nbconvert_exporter": "python",
343421
"pygments_lexer": "ipython3",
344-
"version": "3.8.6"
422+
"version": "3.10.5"
345423
},
346424
"orig_nbformat": 4
347425
},

examples/profile/profile_endpoints_examples.ipynb

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 13,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"# Make sure you run the latest version of the SDK. You can update it with pip install hrflow --upgrade."
10+
]
11+
},
312
{
413
"attachments": {},
514
"cell_type": "markdown",
@@ -10,7 +19,7 @@
1019
},
1120
{
1221
"cell_type": "code",
13-
"execution_count": 6,
22+
"execution_count": 1,
1423
"metadata": {},
1524
"outputs": [],
1625
"source": [
@@ -19,10 +28,21 @@
1928
"import json \n",
2029
"from hrflow import Hrflow\n",
2130
"\n",
22-
"# # Get API credentials from environment variables\n",
23-
"api_secret = getpass(\"Enter your API secret: \")\n",
24-
"source_key = getpass(\"Enter your source key: \")\n",
25-
"user_email = getpass(\"Enter your user email: \")"
31+
"# # # Get API credentials from environment variables\n",
32+
"# api_secret = getpass(\"Enter your API secret: \")\n",
33+
"# source_key = getpass(\"Enter your source key: \")\n",
34+
"# user_email = getpass(\"Enter your user email: \")"
35+
]
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": 2,
40+
"metadata": {},
41+
"outputs": [],
42+
"source": [
43+
"api_secret, source_key, user_email = ('YOUR_SECRET_API_KEY',\n",
44+
" '2b4bf676b1a9aee2b7c2b422242c7d7fdb6cc093',\n",
45+
" 'connectors@hrflow.ai')"
2646
]
2747
},
2848
{
@@ -35,7 +55,7 @@
3555
},
3656
{
3757
"cell_type": "code",
38-
"execution_count": 10,
58+
"execution_count": 3,
3959
"metadata": {},
4060
"outputs": [],
4161
"source": [
@@ -104,9 +124,21 @@
104124
},
105125
{
106126
"cell_type": "code",
107-
"execution_count": null,
127+
"execution_count": 3,
108128
"metadata": {},
109-
"outputs": [],
129+
"outputs": [
130+
{
131+
"data": {
132+
"text/plain": [
133+
"{'code': 400,\n",
134+
" 'message': 'Cannot create profile with this reference: my_custom_reference. Already used!'}"
135+
]
136+
},
137+
"execution_count": 3,
138+
"metadata": {},
139+
"output_type": "execute_result"
140+
}
141+
],
110142
"source": [
111143
"input_data = {\n",
112144
" \"reference\": \"my_custom_reference\", # <-- Replace with your profile reference you want to set\n",
@@ -1055,28 +1087,48 @@
10551087
},
10561088
{
10571089
"cell_type": "code",
1058-
"execution_count": 33,
1090+
"execution_count": 6,
10591091
"metadata": {},
10601092
"outputs": [],
10611093
"source": [
10621094
"# Edit a profile : edit is a Put not a Patch so you need to provide all the fields\n",
10631095
"\n",
10641096
"# let's get the profile by reference\n",
1065-
"reference = \"ref_1234\" # <-- Replace with your profile reference\n",
1097+
"reference = \"my_custom_reference\" # <-- Replace with your profile reference\n",
10661098
"\n",
10671099
"response = client.profile.storing.get(source_key=source_key, reference=reference)\n",
10681100
"\n",
10691101
"profile = response['data']\n",
10701102
"\n",
10711103
"# edit a field or more \n",
1072-
"profile['info']['location']['text'] = \"Paris, France\"\n",
1104+
"profile['info']['location']['text'] = \"Puteaux, France\"\n",
10731105
"\n",
10741106
"# edit the profile\n",
10751107
"response = client.profile.storing.edit(source_key=source_key,\n",
1076-
" key=profile['key'],\n",
1108+
" # key=profile['key'], # This is Optional, it's kept for backward compatibility with previous versions of the SDK\n",
10771109
" profile_json=profile)"
10781110
]
10791111
},
1112+
{
1113+
"cell_type": "code",
1114+
"execution_count": 7,
1115+
"metadata": {},
1116+
"outputs": [
1117+
{
1118+
"data": {
1119+
"text/plain": [
1120+
"200"
1121+
]
1122+
},
1123+
"execution_count": 7,
1124+
"metadata": {},
1125+
"output_type": "execute_result"
1126+
}
1127+
],
1128+
"source": [
1129+
"response[\"code\"]"
1130+
]
1131+
},
10801132
{
10811133
"cell_type": "code",
10821134
"execution_count": null,
@@ -1101,7 +1153,7 @@
11011153
"name": "python",
11021154
"nbconvert_exporter": "python",
11031155
"pygments_lexer": "ipython3",
1104-
"version": "3.8.6"
1156+
"version": "3.10.5"
11051157
},
11061158
"orig_nbformat": 4
11071159
},

hrflow/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__title__ = "hrflow"
22
__description__ = "Python hrflow.ai API package"
33
__url__ = "https://github.com/hrflow/python-hrflow-api"
4-
__version__ = "3.0.0"
4+
__version__ = "3.1.0"
55
__author__ = "HrFlow.ai"
66
__author_email__ = "contact@hrflow.ai"
77
__license__ = "MIT"

hrflow/hrflow/job/storing.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,28 @@ def add_json(self, board_key, job_json):
2727
response = self.client.post("job/indexing", json=job_json)
2828
return validate_response(response)
2929

30-
def edit(self, board_key, key=None, job_json=None):
30+
def edit(self, board_key, job_json, key=None):
3131
"""
32-
This method allows to edit a job
33-
in HrFlow.ai.
34-
The job can be edited either through its key (passed as an argument) or its reference
35-
which is a field in the job_json,
36-
at least one of the two values must be provided.
37-
Args:
38-
board_key: <string>
39-
board id
40-
key: <string>
41-
job id
42-
job_json: <string>
43-
job json structure must follows the structure here https://developers.hrflow.ai/hr-json/job-objects/job-object
44-
45-
Returns
46-
Edit the job in the board with the specified identifier
47-
32+
Edit a job already stored in the given source.
33+
This method uses the endpoint : [PUT] https://api.hrflow.ai/v1/job/indexing
34+
It requires :
35+
- source_key : <string> The key of the source where the job is stored
36+
- job_json : <dict> The job data to update
37+
The job object must meet the criteria of the HrFlow.ai job Object
38+
Otherwise the Put request will return an error.
39+
A key or a reference must be provided in the job object `job_json`, to identify the job to update.
40+
The method will update the object already stored by the fields provided in the job_json.
4841
"""
42+
4943
if job_json is None:
5044
job_json = {}
5145

5246
job_json["board_key"] = validate_key("Board", board_key)
47+
# The argument key is kept for backward compatibility with previous versions of the SDK
48+
# It should be removed in the future after a Major release
5349
if key:
5450
job_json["key"] = validate_key("Job", key)
55-
"""Use the api to add a new profile using profile_data."""
51+
5652
response = self.client.put("job/indexing", json=job_json)
5753
return validate_response(response)
5854

hrflow/hrflow/profile/storing.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,24 @@ def add_json(self, source_key, profile_json):
2727
response = self.client.post("profile/indexing", json=profile_json)
2828
return validate_response(response)
2929

30-
def edit(self, source_key, key, profile_json):
31-
"""Use the api to add a new profile using profile_data."""
30+
def edit(self, source_key, profile_json, key=None):
31+
"""
32+
Edit a profile already stored in the given source.
33+
This method uses the endpoint : [PUT] https://api.hrflow.ai/v1/profile/indexing
34+
It requires :
35+
- source_key : <string> The key of the source where the profile is stored
36+
- profile_json : <dict> The profile data to update
37+
The profile object must meet the criteria of the HrFlow.ai Profile Object
38+
Otherwise the Put request will return an error.
39+
A key or a reference must be provided in the profile object `profile_json`, to identify the profile to update.
40+
The method will update the object already stored by the fields provided in the profile_json.
41+
"""
3242
profile_json["source_key"] = validate_key("Source", source_key)
33-
profile_json["key"] = validate_key("Profile", key)
43+
# The argument key is kept for backward compatibility with previous versions of the SDK
44+
# It should be removed in the future after a Major release
45+
if key:
46+
profile_json["key"] = validate_key("Profile", key)
47+
3448
response = self.client.put("profile/indexing", json=profile_json)
3549
return validate_response(response)
3650

0 commit comments

Comments
 (0)