linkedapi 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- linkedapi/__init__.py +127 -0
- linkedapi/admin/__init__.py +13 -0
- linkedapi/admin/accounts.py +91 -0
- linkedapi/admin/admin.py +22 -0
- linkedapi/admin/http_client.py +73 -0
- linkedapi/admin/limits.py +70 -0
- linkedapi/admin/subscription.py +69 -0
- linkedapi/client.py +160 -0
- linkedapi/config.py +10 -0
- linkedapi/core/__init__.py +4 -0
- linkedapi/core/operation.py +89 -0
- linkedapi/core/polling.py +48 -0
- linkedapi/errors.py +119 -0
- linkedapi/http/__init__.py +4 -0
- linkedapi/http/base.py +22 -0
- linkedapi/http/linked_api_http_client.py +74 -0
- linkedapi/mappers/__init__.py +16 -0
- linkedapi/mappers/array.py +49 -0
- linkedapi/mappers/base.py +70 -0
- linkedapi/mappers/simple.py +56 -0
- linkedapi/mappers/then.py +175 -0
- linkedapi/mappers/void.py +33 -0
- linkedapi/operations/__init__.py +58 -0
- linkedapi/operations/check_connection_status.py +15 -0
- linkedapi/operations/comment_on_post.py +12 -0
- linkedapi/operations/create_post.py +15 -0
- linkedapi/operations/custom_workflow.py +22 -0
- linkedapi/operations/fetch_company.py +35 -0
- linkedapi/operations/fetch_person.py +43 -0
- linkedapi/operations/fetch_post.py +33 -0
- linkedapi/operations/nv_fetch_company.py +33 -0
- linkedapi/operations/nv_fetch_person.py +23 -0
- linkedapi/operations/nv_search_companies.py +15 -0
- linkedapi/operations/nv_search_people.py +15 -0
- linkedapi/operations/nv_send_message.py +12 -0
- linkedapi/operations/nv_sync_conversation.py +12 -0
- linkedapi/operations/react_to_post.py +12 -0
- linkedapi/operations/remove_connection.py +12 -0
- linkedapi/operations/retrieve_connections.py +15 -0
- linkedapi/operations/retrieve_pending_requests.py +15 -0
- linkedapi/operations/retrieve_performance.py +15 -0
- linkedapi/operations/retrieve_ssi.py +15 -0
- linkedapi/operations/search_companies.py +15 -0
- linkedapi/operations/search_people.py +15 -0
- linkedapi/operations/send_connection_request.py +12 -0
- linkedapi/operations/send_message.py +12 -0
- linkedapi/operations/sync_conversation.py +12 -0
- linkedapi/operations/withdraw_connection_request.py +12 -0
- linkedapi/py.typed +1 -0
- linkedapi/types/__init__.py +336 -0
- linkedapi/types/account.py +8 -0
- linkedapi/types/admin/__init__.py +91 -0
- linkedapi/types/admin/accounts.py +71 -0
- linkedapi/types/admin/config.py +8 -0
- linkedapi/types/admin/limits.py +77 -0
- linkedapi/types/admin/subscription.py +58 -0
- linkedapi/types/base.py +47 -0
- linkedapi/types/company.py +140 -0
- linkedapi/types/connection.py +86 -0
- linkedapi/types/message.py +48 -0
- linkedapi/types/params.py +15 -0
- linkedapi/types/person.py +105 -0
- linkedapi/types/post.py +119 -0
- linkedapi/types/responses.py +18 -0
- linkedapi/types/search_companies.py +72 -0
- linkedapi/types/search_people.py +46 -0
- linkedapi/types/statistics.py +27 -0
- linkedapi/types/workflow.py +55 -0
- linkedapi-1.0.0.dist-info/METADATA +125 -0
- linkedapi-1.0.0.dist-info/RECORD +72 -0
- linkedapi-1.0.0.dist-info/WHEEL +4 -0
- linkedapi-1.0.0.dist-info/licenses/LICENSE +21 -0
linkedapi/__init__.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
from linkedapi.admin import (
|
|
2
|
+
AdminAccounts,
|
|
3
|
+
AdminHttpClient,
|
|
4
|
+
AdminLimits,
|
|
5
|
+
AdminSubscription,
|
|
6
|
+
LinkedApiAdmin,
|
|
7
|
+
)
|
|
8
|
+
from linkedapi.client import LinkedApi
|
|
9
|
+
from linkedapi.config import LinkedApiConfig
|
|
10
|
+
from linkedapi.core import Operation, poll_workflow_result
|
|
11
|
+
from linkedapi.errors import (
|
|
12
|
+
LINKED_API_ACTION_ERROR_TYPES,
|
|
13
|
+
LINKED_API_ERROR_TYPES,
|
|
14
|
+
LinkedApiActionErrorType,
|
|
15
|
+
LinkedApiError,
|
|
16
|
+
LinkedApiErrorType,
|
|
17
|
+
LinkedApiWorkflowTimeoutError,
|
|
18
|
+
)
|
|
19
|
+
from linkedapi.http import HttpClient, LinkedApiHttpClient
|
|
20
|
+
from linkedapi.mappers import (
|
|
21
|
+
ActionConfig,
|
|
22
|
+
ArrayWorkflowMapper,
|
|
23
|
+
BaseMapper,
|
|
24
|
+
MappedResponse,
|
|
25
|
+
ResponseMapping,
|
|
26
|
+
SimpleWorkflowMapper,
|
|
27
|
+
ThenWorkflowMapper,
|
|
28
|
+
VoidWorkflowMapper,
|
|
29
|
+
)
|
|
30
|
+
from linkedapi.operations import (
|
|
31
|
+
CheckConnectionStatus,
|
|
32
|
+
CommentOnPost,
|
|
33
|
+
CreatePost,
|
|
34
|
+
CustomWorkflow,
|
|
35
|
+
FetchCompany,
|
|
36
|
+
FetchCompanyMapper,
|
|
37
|
+
FetchPerson,
|
|
38
|
+
FetchPersonMapper,
|
|
39
|
+
FetchPost,
|
|
40
|
+
FetchPostMapper,
|
|
41
|
+
NvFetchCompany,
|
|
42
|
+
NvFetchCompanyMapper,
|
|
43
|
+
NvFetchPerson,
|
|
44
|
+
NvFetchPersonMapper,
|
|
45
|
+
NvSearchCompanies,
|
|
46
|
+
NvSearchPeople,
|
|
47
|
+
NvSendMessage,
|
|
48
|
+
NvSyncConversation,
|
|
49
|
+
ReactToPost,
|
|
50
|
+
RemoveConnection,
|
|
51
|
+
RetrieveConnections,
|
|
52
|
+
RetrievePendingRequests,
|
|
53
|
+
RetrievePerformance,
|
|
54
|
+
RetrieveSSI,
|
|
55
|
+
SearchCompanies,
|
|
56
|
+
SearchPeople,
|
|
57
|
+
SendConnectionRequest,
|
|
58
|
+
SendMessage,
|
|
59
|
+
SyncConversation,
|
|
60
|
+
WithdrawConnectionRequest,
|
|
61
|
+
)
|
|
62
|
+
from linkedapi.types import * # noqa: F403
|
|
63
|
+
from linkedapi.types import __all__ as _types_all
|
|
64
|
+
|
|
65
|
+
__version__ = "1.0.0"
|
|
66
|
+
PredefinedOperation = Operation
|
|
67
|
+
|
|
68
|
+
__all__ = [
|
|
69
|
+
*_types_all,
|
|
70
|
+
"AdminAccounts",
|
|
71
|
+
"AdminHttpClient",
|
|
72
|
+
"AdminLimits",
|
|
73
|
+
"AdminSubscription",
|
|
74
|
+
"ActionConfig",
|
|
75
|
+
"ArrayWorkflowMapper",
|
|
76
|
+
"BaseMapper",
|
|
77
|
+
"CheckConnectionStatus",
|
|
78
|
+
"CommentOnPost",
|
|
79
|
+
"CreatePost",
|
|
80
|
+
"CustomWorkflow",
|
|
81
|
+
"FetchCompany",
|
|
82
|
+
"FetchCompanyMapper",
|
|
83
|
+
"FetchPerson",
|
|
84
|
+
"FetchPersonMapper",
|
|
85
|
+
"FetchPost",
|
|
86
|
+
"FetchPostMapper",
|
|
87
|
+
"HttpClient",
|
|
88
|
+
"LINKED_API_ACTION_ERROR_TYPES",
|
|
89
|
+
"LINKED_API_ERROR_TYPES",
|
|
90
|
+
"LinkedApi",
|
|
91
|
+
"LinkedApiActionErrorType",
|
|
92
|
+
"LinkedApiAdmin",
|
|
93
|
+
"LinkedApiConfig",
|
|
94
|
+
"LinkedApiError",
|
|
95
|
+
"LinkedApiErrorType",
|
|
96
|
+
"LinkedApiHttpClient",
|
|
97
|
+
"LinkedApiWorkflowTimeoutError",
|
|
98
|
+
"MappedResponse",
|
|
99
|
+
"NvFetchCompany",
|
|
100
|
+
"NvFetchCompanyMapper",
|
|
101
|
+
"NvFetchPerson",
|
|
102
|
+
"NvFetchPersonMapper",
|
|
103
|
+
"NvSearchCompanies",
|
|
104
|
+
"NvSearchPeople",
|
|
105
|
+
"NvSendMessage",
|
|
106
|
+
"NvSyncConversation",
|
|
107
|
+
"Operation",
|
|
108
|
+
"PredefinedOperation",
|
|
109
|
+
"ReactToPost",
|
|
110
|
+
"RemoveConnection",
|
|
111
|
+
"ResponseMapping",
|
|
112
|
+
"RetrieveConnections",
|
|
113
|
+
"RetrievePendingRequests",
|
|
114
|
+
"RetrievePerformance",
|
|
115
|
+
"RetrieveSSI",
|
|
116
|
+
"SearchCompanies",
|
|
117
|
+
"SearchPeople",
|
|
118
|
+
"SendConnectionRequest",
|
|
119
|
+
"SendMessage",
|
|
120
|
+
"SimpleWorkflowMapper",
|
|
121
|
+
"SyncConversation",
|
|
122
|
+
"ThenWorkflowMapper",
|
|
123
|
+
"VoidWorkflowMapper",
|
|
124
|
+
"WithdrawConnectionRequest",
|
|
125
|
+
"__version__",
|
|
126
|
+
"poll_workflow_result",
|
|
127
|
+
]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from linkedapi.admin.accounts import AdminAccounts
|
|
2
|
+
from linkedapi.admin.admin import LinkedApiAdmin
|
|
3
|
+
from linkedapi.admin.http_client import AdminHttpClient
|
|
4
|
+
from linkedapi.admin.limits import AdminLimits
|
|
5
|
+
from linkedapi.admin.subscription import AdminSubscription
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"AdminAccounts",
|
|
9
|
+
"AdminHttpClient",
|
|
10
|
+
"AdminLimits",
|
|
11
|
+
"AdminSubscription",
|
|
12
|
+
"LinkedApiAdmin",
|
|
13
|
+
]
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, TypeVar
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
from linkedapi.errors import LinkedApiError
|
|
8
|
+
from linkedapi.http import HttpClient
|
|
9
|
+
from linkedapi.types.admin import (
|
|
10
|
+
AccountsResult,
|
|
11
|
+
CancelConnectionSessionParams,
|
|
12
|
+
ConnectionSessionResult,
|
|
13
|
+
CreateConnectionSessionResult,
|
|
14
|
+
DisconnectParams,
|
|
15
|
+
GetConnectionSessionParams,
|
|
16
|
+
RegenerateTokenParams,
|
|
17
|
+
RegenerateTokenResult,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
TModel = TypeVar("TModel", bound=BaseModel)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class AdminAccounts:
|
|
24
|
+
def __init__(self, http_client: HttpClient[Any]) -> None:
|
|
25
|
+
self.http_client = http_client
|
|
26
|
+
|
|
27
|
+
def get_all(self) -> AccountsResult:
|
|
28
|
+
return self._post_result("/admin/accounts.getAll", AccountsResult, "Failed to get accounts")
|
|
29
|
+
|
|
30
|
+
def disconnect(self, params: DisconnectParams) -> None:
|
|
31
|
+
self._post_void("/admin/accounts.disconnect", "Failed to disconnect account", params)
|
|
32
|
+
|
|
33
|
+
def regenerate_identification_token(
|
|
34
|
+
self,
|
|
35
|
+
params: RegenerateTokenParams,
|
|
36
|
+
) -> RegenerateTokenResult:
|
|
37
|
+
return self._post_result(
|
|
38
|
+
"/admin/accounts.regenerateIdentificationToken",
|
|
39
|
+
RegenerateTokenResult,
|
|
40
|
+
"Failed to regenerate token",
|
|
41
|
+
params,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
def create_connection_session(self) -> CreateConnectionSessionResult:
|
|
45
|
+
return self._post_result(
|
|
46
|
+
"/admin/accounts.createConnectionSession",
|
|
47
|
+
CreateConnectionSessionResult,
|
|
48
|
+
"Failed to create connection session",
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
def get_connection_session(
|
|
52
|
+
self,
|
|
53
|
+
params: GetConnectionSessionParams,
|
|
54
|
+
) -> ConnectionSessionResult:
|
|
55
|
+
return self._post_result(
|
|
56
|
+
"/admin/accounts.getConnectionSession",
|
|
57
|
+
ConnectionSessionResult,
|
|
58
|
+
"Failed to get connection session",
|
|
59
|
+
params,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
def cancel_connection_session(self, params: CancelConnectionSessionParams) -> None:
|
|
63
|
+
self._post_void(
|
|
64
|
+
"/admin/accounts.cancelConnectionSession",
|
|
65
|
+
"Failed to cancel connection session",
|
|
66
|
+
params,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
def _post_result(
|
|
70
|
+
self,
|
|
71
|
+
path: str,
|
|
72
|
+
model: type[TModel],
|
|
73
|
+
default_message: str,
|
|
74
|
+
params: Any | None = None,
|
|
75
|
+
) -> TModel:
|
|
76
|
+
response = self.http_client.post(path, params)
|
|
77
|
+
if response.success and response.result is not None:
|
|
78
|
+
return model.model_validate(response.result)
|
|
79
|
+
raise LinkedApiError(
|
|
80
|
+
response.error.type if response.error else "httpError",
|
|
81
|
+
response.error.message if response.error else default_message,
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
def _post_void(self, path: str, default_message: str, params: Any | None = None) -> None:
|
|
85
|
+
response = self.http_client.post(path, params)
|
|
86
|
+
if response.success:
|
|
87
|
+
return
|
|
88
|
+
raise LinkedApiError(
|
|
89
|
+
response.error.type if response.error else "httpError",
|
|
90
|
+
response.error.message if response.error else default_message,
|
|
91
|
+
)
|
linkedapi/admin/admin.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from linkedapi.admin.accounts import AdminAccounts
|
|
6
|
+
from linkedapi.admin.http_client import AdminHttpClient
|
|
7
|
+
from linkedapi.admin.limits import AdminLimits
|
|
8
|
+
from linkedapi.admin.subscription import AdminSubscription
|
|
9
|
+
from linkedapi.http import HttpClient
|
|
10
|
+
from linkedapi.types.admin import AdminConfig
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class LinkedApiAdmin:
|
|
14
|
+
"""Admin SDK for Linked API subscription, account, and limit management."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, config: AdminConfig | HttpClient[Any]) -> None:
|
|
17
|
+
http_client = (
|
|
18
|
+
config if isinstance(config, HttpClient) else AdminHttpClient(config, config.client)
|
|
19
|
+
)
|
|
20
|
+
self.subscription = AdminSubscription(http_client)
|
|
21
|
+
self.accounts = AdminAccounts(http_client)
|
|
22
|
+
self.limits = AdminLimits(http_client)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
import requests
|
|
6
|
+
|
|
7
|
+
from linkedapi.errors import LinkedApiError
|
|
8
|
+
from linkedapi.http import HttpClient
|
|
9
|
+
from linkedapi.types import LinkedApiResponse, serialize_value
|
|
10
|
+
from linkedapi.types.admin import AdminConfig
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class AdminHttpClient(HttpClient[Any]):
|
|
14
|
+
def __init__(
|
|
15
|
+
self,
|
|
16
|
+
config: AdminConfig,
|
|
17
|
+
client: str | None = None,
|
|
18
|
+
base_url: str = "https://api.linkedapi.io",
|
|
19
|
+
session: requests.Session | None = None,
|
|
20
|
+
) -> None:
|
|
21
|
+
self.base_url = base_url.rstrip("/")
|
|
22
|
+
self.session = session or requests.Session()
|
|
23
|
+
self.headers = {
|
|
24
|
+
"Content-Type": "application/json",
|
|
25
|
+
"linked-api-token": config.linked_api_token,
|
|
26
|
+
"client": client or config.client,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
def get(self, path: str) -> LinkedApiResponse[Any]:
|
|
30
|
+
return self._request("GET", path)
|
|
31
|
+
|
|
32
|
+
def post(self, path: str, data: Any | None = None) -> LinkedApiResponse[Any]:
|
|
33
|
+
return self._request("POST", path, data)
|
|
34
|
+
|
|
35
|
+
def delete(self, path: str) -> LinkedApiResponse[Any]:
|
|
36
|
+
return self._request("DELETE", path)
|
|
37
|
+
|
|
38
|
+
def _request(self, method: str, path: str, data: Any | None = None) -> LinkedApiResponse[Any]:
|
|
39
|
+
try:
|
|
40
|
+
response = self.session.request(
|
|
41
|
+
method,
|
|
42
|
+
f"{self.base_url}{path}",
|
|
43
|
+
headers=self.headers,
|
|
44
|
+
json=serialize_value(data) if data is not None else None,
|
|
45
|
+
)
|
|
46
|
+
return self._handle_response(response)
|
|
47
|
+
except LinkedApiError:
|
|
48
|
+
raise
|
|
49
|
+
except requests.RequestException as error:
|
|
50
|
+
raise LinkedApiError(
|
|
51
|
+
"httpError", f"Request error: {error}", {"error": error}
|
|
52
|
+
) from error
|
|
53
|
+
|
|
54
|
+
def _handle_response(self, response: requests.Response) -> LinkedApiResponse[Any]:
|
|
55
|
+
if response.ok:
|
|
56
|
+
return LinkedApiResponse[Any].model_validate(response.json())
|
|
57
|
+
|
|
58
|
+
try:
|
|
59
|
+
error_data = response.json()
|
|
60
|
+
error = error_data["error"]
|
|
61
|
+
raise LinkedApiError(error["type"], error["message"], error_data)
|
|
62
|
+
except LinkedApiError:
|
|
63
|
+
raise
|
|
64
|
+
except (KeyError, TypeError, ValueError) as error:
|
|
65
|
+
raise LinkedApiError(
|
|
66
|
+
"httpError",
|
|
67
|
+
f"HTTP {response.status_code}: {response.reason}",
|
|
68
|
+
{
|
|
69
|
+
"status": response.status_code,
|
|
70
|
+
"statusText": response.reason,
|
|
71
|
+
"url": response.url,
|
|
72
|
+
},
|
|
73
|
+
) from error
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, TypeVar
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
from linkedapi.errors import LinkedApiError
|
|
8
|
+
from linkedapi.http import HttpClient
|
|
9
|
+
from linkedapi.types.admin import (
|
|
10
|
+
DeleteLimitsParams,
|
|
11
|
+
GetLimitsParams,
|
|
12
|
+
GetLimitsUsageParams,
|
|
13
|
+
LimitsResult,
|
|
14
|
+
LimitUsageResult,
|
|
15
|
+
ResetLimitsParams,
|
|
16
|
+
SetLimitsParams,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
TModel = TypeVar("TModel", bound=BaseModel)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class AdminLimits:
|
|
23
|
+
def __init__(self, http_client: HttpClient[Any]) -> None:
|
|
24
|
+
self.http_client = http_client
|
|
25
|
+
|
|
26
|
+
def get_defaults(self) -> LimitsResult:
|
|
27
|
+
return self._post_result(
|
|
28
|
+
"/admin/limits.getDefaults", LimitsResult, "Failed to get default limits"
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
def get(self, params: GetLimitsParams) -> LimitsResult:
|
|
32
|
+
return self._post_result("/admin/limits.get", LimitsResult, "Failed to get limits", params)
|
|
33
|
+
|
|
34
|
+
def get_usage(self, params: GetLimitsUsageParams) -> LimitUsageResult:
|
|
35
|
+
return self._post_result(
|
|
36
|
+
"/admin/limits.getUsage", LimitUsageResult, "Failed to get limits usage", params
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
def set(self, params: SetLimitsParams) -> None:
|
|
40
|
+
self._post_void("/admin/limits.set", "Failed to set limits", params)
|
|
41
|
+
|
|
42
|
+
def delete(self, params: DeleteLimitsParams) -> None:
|
|
43
|
+
self._post_void("/admin/limits.delete", "Failed to delete limits", params)
|
|
44
|
+
|
|
45
|
+
def reset_to_defaults(self, params: ResetLimitsParams) -> None:
|
|
46
|
+
self._post_void("/admin/limits.resetToDefaults", "Failed to reset limits", params)
|
|
47
|
+
|
|
48
|
+
def _post_result(
|
|
49
|
+
self,
|
|
50
|
+
path: str,
|
|
51
|
+
model: type[TModel],
|
|
52
|
+
default_message: str,
|
|
53
|
+
params: Any | None = None,
|
|
54
|
+
) -> TModel:
|
|
55
|
+
response = self.http_client.post(path, params)
|
|
56
|
+
if response.success and response.result is not None:
|
|
57
|
+
return model.model_validate(response.result)
|
|
58
|
+
raise LinkedApiError(
|
|
59
|
+
response.error.type if response.error else "httpError",
|
|
60
|
+
response.error.message if response.error else default_message,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
def _post_void(self, path: str, default_message: str, params: Any | None = None) -> None:
|
|
64
|
+
response = self.http_client.post(path, params)
|
|
65
|
+
if response.success:
|
|
66
|
+
return
|
|
67
|
+
raise LinkedApiError(
|
|
68
|
+
response.error.type if response.error else "httpError",
|
|
69
|
+
response.error.message if response.error else default_message,
|
|
70
|
+
)
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, TypeVar
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
from linkedapi.errors import LinkedApiError
|
|
8
|
+
from linkedapi.http import HttpClient
|
|
9
|
+
from linkedapi.types.admin import (
|
|
10
|
+
BillingLinkResult,
|
|
11
|
+
CancelResult,
|
|
12
|
+
SetSeatsParams,
|
|
13
|
+
SetSeatsResult,
|
|
14
|
+
SubscriptionPricingResult,
|
|
15
|
+
SubscriptionSeatsResult,
|
|
16
|
+
SubscriptionStatus,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
TModel = TypeVar("TModel", bound=BaseModel)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class AdminSubscription:
|
|
23
|
+
def __init__(self, http_client: HttpClient[Any]) -> None:
|
|
24
|
+
self.http_client = http_client
|
|
25
|
+
|
|
26
|
+
def get_status(self) -> SubscriptionStatus:
|
|
27
|
+
return self._post_result(
|
|
28
|
+
"/admin/subscription.getStatus", SubscriptionStatus, "Failed to get subscription status"
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
def get_seats(self) -> SubscriptionSeatsResult:
|
|
32
|
+
return self._post_result(
|
|
33
|
+
"/admin/subscription.getSeats", SubscriptionSeatsResult, "Failed to get seats"
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
def get_pricing(self) -> SubscriptionPricingResult:
|
|
37
|
+
return self._post_result(
|
|
38
|
+
"/admin/subscription.getPricing", SubscriptionPricingResult, "Failed to get pricing"
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
def set_seats(self, params: SetSeatsParams) -> SetSeatsResult:
|
|
42
|
+
return self._post_result(
|
|
43
|
+
"/admin/subscription.setSeats", SetSeatsResult, "Failed to set seats", params
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
def get_billing_link(self) -> BillingLinkResult:
|
|
47
|
+
return self._post_result(
|
|
48
|
+
"/admin/subscription.getBillingLink", BillingLinkResult, "Failed to get billing link"
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
def cancel(self) -> CancelResult:
|
|
52
|
+
return self._post_result(
|
|
53
|
+
"/admin/subscription.cancel", CancelResult, "Failed to cancel subscription"
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
def _post_result(
|
|
57
|
+
self,
|
|
58
|
+
path: str,
|
|
59
|
+
model: type[TModel],
|
|
60
|
+
default_message: str,
|
|
61
|
+
params: Any | None = None,
|
|
62
|
+
) -> TModel:
|
|
63
|
+
response = self.http_client.post(path, params)
|
|
64
|
+
if response.success and response.result is not None:
|
|
65
|
+
return model.model_validate(response.result)
|
|
66
|
+
raise LinkedApiError(
|
|
67
|
+
response.error.type if response.error else "httpError",
|
|
68
|
+
response.error.message if response.error else default_message,
|
|
69
|
+
)
|
linkedapi/client.py
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
from urllib.parse import urlencode
|
|
5
|
+
|
|
6
|
+
from linkedapi.config import LinkedApiConfig
|
|
7
|
+
from linkedapi.errors import LinkedApiError
|
|
8
|
+
from linkedapi.http import HttpClient, LinkedApiHttpClient
|
|
9
|
+
from linkedapi.mappers import MappedResponse
|
|
10
|
+
from linkedapi.operations import (
|
|
11
|
+
CheckConnectionStatus,
|
|
12
|
+
CommentOnPost,
|
|
13
|
+
CreatePost,
|
|
14
|
+
CustomWorkflow,
|
|
15
|
+
FetchCompany,
|
|
16
|
+
FetchPerson,
|
|
17
|
+
FetchPost,
|
|
18
|
+
NvFetchCompany,
|
|
19
|
+
NvFetchPerson,
|
|
20
|
+
NvSearchCompanies,
|
|
21
|
+
NvSearchPeople,
|
|
22
|
+
NvSendMessage,
|
|
23
|
+
NvSyncConversation,
|
|
24
|
+
ReactToPost,
|
|
25
|
+
RemoveConnection,
|
|
26
|
+
RetrieveConnections,
|
|
27
|
+
RetrievePendingRequests,
|
|
28
|
+
RetrievePerformance,
|
|
29
|
+
RetrieveSSI,
|
|
30
|
+
SearchCompanies,
|
|
31
|
+
SearchPeople,
|
|
32
|
+
SendConnectionRequest,
|
|
33
|
+
SendMessage,
|
|
34
|
+
SyncConversation,
|
|
35
|
+
WithdrawConnectionRequest,
|
|
36
|
+
)
|
|
37
|
+
from linkedapi.types import AccountInfo, LinkedApiActionError, serialize_value
|
|
38
|
+
from linkedapi.types.message import ConversationPollRequest, ConversationPollResult
|
|
39
|
+
from linkedapi.types.statistics import ApiUsageAction, ApiUsageParams
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class LinkedApi:
|
|
43
|
+
"""Official synchronous Python SDK for Linked API."""
|
|
44
|
+
|
|
45
|
+
def __init__(self, config: LinkedApiConfig | HttpClient[Any]) -> None:
|
|
46
|
+
self.http_client = (
|
|
47
|
+
config
|
|
48
|
+
if isinstance(config, HttpClient)
|
|
49
|
+
else LinkedApiHttpClient(config, config.client, config.base_url)
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
self.custom_workflow = CustomWorkflow(self.http_client)
|
|
53
|
+
self.send_message = SendMessage(self.http_client)
|
|
54
|
+
self.sync_conversation = SyncConversation(self.http_client)
|
|
55
|
+
self.check_connection_status = CheckConnectionStatus(self.http_client)
|
|
56
|
+
self.send_connection_request = SendConnectionRequest(self.http_client)
|
|
57
|
+
self.withdraw_connection_request = WithdrawConnectionRequest(self.http_client)
|
|
58
|
+
self.retrieve_pending_requests = RetrievePendingRequests(self.http_client)
|
|
59
|
+
self.retrieve_connections = RetrieveConnections(self.http_client)
|
|
60
|
+
self.remove_connection = RemoveConnection(self.http_client)
|
|
61
|
+
self.search_companies = SearchCompanies(self.http_client)
|
|
62
|
+
self.search_people = SearchPeople(self.http_client)
|
|
63
|
+
self.fetch_company = FetchCompany(self.http_client)
|
|
64
|
+
self.fetch_person = FetchPerson(self.http_client)
|
|
65
|
+
self.fetch_post = FetchPost(self.http_client)
|
|
66
|
+
self.react_to_post = ReactToPost(self.http_client)
|
|
67
|
+
self.comment_on_post = CommentOnPost(self.http_client)
|
|
68
|
+
self.create_post = CreatePost(self.http_client)
|
|
69
|
+
self.retrieve_ssi = RetrieveSSI(self.http_client)
|
|
70
|
+
self.retrieve_performance = RetrievePerformance(self.http_client)
|
|
71
|
+
self.nv_send_message = NvSendMessage(self.http_client)
|
|
72
|
+
self.nv_sync_conversation = NvSyncConversation(self.http_client)
|
|
73
|
+
self.nv_search_companies = NvSearchCompanies(self.http_client)
|
|
74
|
+
self.nv_search_people = NvSearchPeople(self.http_client)
|
|
75
|
+
self.nv_fetch_company = NvFetchCompany(self.http_client)
|
|
76
|
+
self.nv_fetch_person = NvFetchPerson(self.http_client)
|
|
77
|
+
|
|
78
|
+
self.operations = [
|
|
79
|
+
self.custom_workflow,
|
|
80
|
+
self.send_message,
|
|
81
|
+
self.sync_conversation,
|
|
82
|
+
self.check_connection_status,
|
|
83
|
+
self.send_connection_request,
|
|
84
|
+
self.withdraw_connection_request,
|
|
85
|
+
self.retrieve_pending_requests,
|
|
86
|
+
self.retrieve_connections,
|
|
87
|
+
self.remove_connection,
|
|
88
|
+
self.search_companies,
|
|
89
|
+
self.search_people,
|
|
90
|
+
self.fetch_company,
|
|
91
|
+
self.fetch_person,
|
|
92
|
+
self.fetch_post,
|
|
93
|
+
self.react_to_post,
|
|
94
|
+
self.comment_on_post,
|
|
95
|
+
self.create_post,
|
|
96
|
+
self.retrieve_ssi,
|
|
97
|
+
self.retrieve_performance,
|
|
98
|
+
self.nv_send_message,
|
|
99
|
+
self.nv_sync_conversation,
|
|
100
|
+
self.nv_search_companies,
|
|
101
|
+
self.nv_search_people,
|
|
102
|
+
self.nv_fetch_company,
|
|
103
|
+
self.nv_fetch_person,
|
|
104
|
+
]
|
|
105
|
+
|
|
106
|
+
def poll_conversations(
|
|
107
|
+
self,
|
|
108
|
+
conversations: list[ConversationPollRequest],
|
|
109
|
+
) -> MappedResponse[list[ConversationPollResult]]:
|
|
110
|
+
"""Poll previously synced standard or Sales Navigator conversations."""
|
|
111
|
+
|
|
112
|
+
try:
|
|
113
|
+
response = self.http_client.post("/conversations/poll", serialize_value(conversations))
|
|
114
|
+
if response.success and response.result is not None:
|
|
115
|
+
return MappedResponse(
|
|
116
|
+
data=[ConversationPollResult.model_validate(item) for item in response.result],
|
|
117
|
+
errors=[],
|
|
118
|
+
)
|
|
119
|
+
return MappedResponse(
|
|
120
|
+
data=None,
|
|
121
|
+
errors=[
|
|
122
|
+
LinkedApiActionError(
|
|
123
|
+
type=response.error.type if response.error else "",
|
|
124
|
+
message=response.error.message if response.error else "",
|
|
125
|
+
),
|
|
126
|
+
],
|
|
127
|
+
)
|
|
128
|
+
except LinkedApiError as error:
|
|
129
|
+
if error.type == "conversationsNotSynced":
|
|
130
|
+
return MappedResponse(
|
|
131
|
+
data=None,
|
|
132
|
+
errors=[LinkedApiActionError(type=error.type, message=error.message)],
|
|
133
|
+
)
|
|
134
|
+
raise
|
|
135
|
+
|
|
136
|
+
def get_account_info(self) -> MappedResponse[AccountInfo]:
|
|
137
|
+
"""Retrieve basic information about the current LinkedIn account."""
|
|
138
|
+
|
|
139
|
+
response = self.http_client.get("/account")
|
|
140
|
+
if response.success and response.result is not None:
|
|
141
|
+
return MappedResponse(data=AccountInfo.model_validate(response.result), errors=[])
|
|
142
|
+
raise LinkedApiError(
|
|
143
|
+
response.error.type if response.error else "httpError",
|
|
144
|
+
response.error.message if response.error else "",
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
def get_api_usage(self, params: ApiUsageParams) -> MappedResponse[list[ApiUsageAction]]:
|
|
148
|
+
"""Retrieve Linked API action usage statistics for a time period."""
|
|
149
|
+
|
|
150
|
+
query_params = urlencode({"start": params.start, "end": params.end})
|
|
151
|
+
response = self.http_client.get(f"/stats/actions?{query_params}")
|
|
152
|
+
if response.success and response.result is not None:
|
|
153
|
+
return MappedResponse(
|
|
154
|
+
data=[ApiUsageAction.model_validate(item) for item in response.result],
|
|
155
|
+
errors=[],
|
|
156
|
+
)
|
|
157
|
+
raise LinkedApiError(
|
|
158
|
+
response.error.type if response.error else "httpError",
|
|
159
|
+
response.error.message if response.error else "",
|
|
160
|
+
)
|
linkedapi/config.py
ADDED