-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathhrflow.py
More file actions
executable file
·179 lines (147 loc) · 6.29 KB
/
hrflow.py
File metadata and controls
executable file
·179 lines (147 loc) · 6.29 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import json
import requests as req
from .auth import Auth
from .board import Board
from .job import Job
from .profile import Profile
from .rating import Rating
from .source import Source
from .text import Text
from .tracking import Tracking
from .webhook import Webhook
from .workflow import Workflow
CLIENT_API_URL = "https://api.hrflow.ai/v1/"
class Hrflow(object):
"""client api wrapper client."""
def __init__(
self,
api_url=CLIENT_API_URL,
api_secret=None,
api_user=None,
webhook_secret=None,
):
"""
Hrflow client. This class is the main entry point to the Hrflow API.
Args:
api_url: <string>
The API URL. Defaults to https://api.hrflow.ai/v1/
api_secret: <string>
The API secret key. You can find it in your
Hrflow.ai account.
api_user: <string>
The API user email. You can find it in your
Hrflow.ai account.
webhook_secret: <string>
Returns
Hrflow client object
"""
self.api_url = api_url
self.auth_header = {"X-API-KEY": api_secret, "X-USER-EMAIL": api_user}
self.webhook_secret = webhook_secret
self.auth = Auth(self)
self.job = Job(self)
self.profile = Profile(self)
self.text = Text(self)
self.webhooks = Webhook(self)
self.source = Source(self)
self.board = Board(self)
self.tracking = Tracking(self)
self.rating = Rating(self)
self.workflow = Workflow(self)
def _create_request_url(self, resource_url):
return "{api_endpoint}{resource_url}".format(
api_endpoint=self.api_url, resource_url=resource_url
)
def _fill_headers(self, header, base={}):
for key, value in header.items():
base[key] = value
return base
def _validate_args(self, bodyparams):
for key, value in bodyparams.items():
if isinstance(value, list):
bodyparams[key] = json.dumps(value)
return bodyparams
def get(self, resource_endpoint, query_params={}):
"""
This a method for internal use only.
It is used to make a GET request to the Hrflow API.
It's not meant to be used directly by the user.
Args:
resource_endpoint: <string>
The resource endpoint. For example: "job/indexing"
query_params: <dict>
The query parameters to be sent to the API. It
must be a dictionary.
Returns
Make the corresponding GET request to the Hrflow API and returns the
response object.
"""
url = self._create_request_url(resource_endpoint)
if query_params:
query_params = self._validate_args(query_params)
return req.get(url, headers=self.auth_header, params=query_params)
else:
return req.get(url, headers=self.auth_header)
def post(self, resource_endpoint, data={}, json={}, files=None):
"""
This a method for internal use only.
It is used to make a POST request to the Hrflow API.
It's not meant to be used directly by the user.
Args:
resource_endpoint: <string>
The resource endpoint. For example: "job/indexing"
data: <dict>
The data payload (for multipart/formdata) to be
sent to the API. It must be a dictionary.
json: <dict>
The json payload to be sent to the API. It must
be a dictionary.
files: <dict>
The files payload to be sent to the API. It must
be a dictionary. (ie. {"file": open("file.pdf",
"rb")}
Returns:
Makes the corresponding POST request to the Hrflow API and returns the
response object.
"""
url = self._create_request_url(resource_endpoint)
if files:
data = self._validate_args(data)
return req.post(url, headers=self.auth_header, files=files, data=data)
else:
return req.post(url, headers=self.auth_header, data=data, json=json)
def patch(self, resource_endpoint, json={}):
"""
This a method for internal use only.
It is used to make a PATCH request to the Hrflow API.
It's not meant to be used directly by the user.
Args:
resource_endpoint: <string>
The resource endpoint. For example: "job/indexing"
json: <dict>
The json payload to be sent to the API. It must
be a dictionary.
Returns:
Makes the corresponding PATCH request to the Hrflow API and returns the
response object.
"""
url = self._create_request_url(resource_endpoint)
data = self._validate_args(json)
return req.patch(url, headers=self.auth_header, json=data)
def put(self, resource_endpoint, json={}):
"""
This a method for internal use only.
It is used to make a PUT request to the Hrflow API.
It's not meant to be used directly by the user.
Args:
resource_endpoint: <string>
The resource endpoint. For example: "job/indexing"
json: <dict>
The json payload to be sent to the API. It must
be a dictionary.
Returns:
Makes the corresponding PUT request to the Hrflow API and returns the
response object.
"""
url = self._create_request_url(resource_endpoint)
return req.put(url, headers=self.auth_header, json=json)