Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 57
configured_endpoints: 61
34 changes: 27 additions & 7 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ Methods:
- <code title="get /v3/chats/{chatId}/location">client.chats.location.<a href="./src/linq/resources/chats/location.py">retrieve</a>(chat_id) -> <a href="./src/linq/types/chats/get_chat_location_response.py">GetChatLocationResponse</a></code>
- <code title="post /v3/chats/{chatId}/location/request">client.chats.location.<a href="./src/linq/resources/chats/location.py">request</a>(chat_id) -> <a href="./src/linq/types/chats/location_request_response.py">LocationRequestResponse</a></code>

## Polls

Types:

```python
from linq.types.chats import Poll, PollEnvelope
```

Methods:

- <code title="post /v3/chats/{chatId}/polls">client.chats.polls.<a href="./src/linq/resources/chats/polls.py">create</a>(chat_id, \*\*<a href="src/linq/types/chats/poll_create_params.py">params</a>) -> <a href="./src/linq/types/chats/poll_envelope.py">PollEnvelope</a></code>

# Messages

Types:
Expand All @@ -105,13 +117,21 @@ from linq.types import (

Methods:

- <code title="post /v3/messages">client.messages.<a href="./src/linq/resources/messages.py">create</a>(\*\*<a href="src/linq/types/message_create_params.py">params</a>) -> <a href="./src/linq/types/message_create_response.py">MessageCreateResponse</a></code>
- <code title="get /v3/messages/{messageId}">client.messages.<a href="./src/linq/resources/messages.py">retrieve</a>(message_id) -> <a href="./src/linq/types/message.py">Message</a></code>
- <code title="patch /v3/messages/{messageId}">client.messages.<a href="./src/linq/resources/messages.py">update</a>(message_id, \*\*<a href="src/linq/types/message_update_params.py">params</a>) -> <a href="./src/linq/types/message.py">Message</a></code>
- <code title="delete /v3/messages/{messageId}">client.messages.<a href="./src/linq/resources/messages.py">delete</a>(message_id) -> None</code>
- <code title="post /v3/messages/{messageId}/reactions">client.messages.<a href="./src/linq/resources/messages.py">add_reaction</a>(message_id, \*\*<a href="src/linq/types/message_add_reaction_params.py">params</a>) -> <a href="./src/linq/types/message_add_reaction_response.py">MessageAddReactionResponse</a></code>
- <code title="get /v3/messages/{messageId}/thread">client.messages.<a href="./src/linq/resources/messages.py">list_messages_thread</a>(message_id, \*\*<a href="src/linq/types/message_list_messages_thread_params.py">params</a>) -> <a href="./src/linq/types/message.py">SyncListMessagesPagination[Message]</a></code>
- <code title="post /v3/messages/{messageId}/update">client.messages.<a href="./src/linq/resources/messages.py">update_app_card</a>(message_id, \*\*<a href="src/linq/types/message_update_app_card_params.py">params</a>) -> <a href="./src/linq/types/message_update_app_card_response.py">MessageUpdateAppCardResponse</a></code>
- <code title="post /v3/messages">client.messages.<a href="./src/linq/resources/messages/messages.py">create</a>(\*\*<a href="src/linq/types/message_create_params.py">params</a>) -> <a href="./src/linq/types/message_create_response.py">MessageCreateResponse</a></code>
- <code title="get /v3/messages/{messageId}">client.messages.<a href="./src/linq/resources/messages/messages.py">retrieve</a>(message_id) -> <a href="./src/linq/types/message.py">Message</a></code>
- <code title="patch /v3/messages/{messageId}">client.messages.<a href="./src/linq/resources/messages/messages.py">update</a>(message_id, \*\*<a href="src/linq/types/message_update_params.py">params</a>) -> <a href="./src/linq/types/message.py">Message</a></code>
- <code title="delete /v3/messages/{messageId}">client.messages.<a href="./src/linq/resources/messages/messages.py">delete</a>(message_id) -> None</code>
- <code title="post /v3/messages/{messageId}/reactions">client.messages.<a href="./src/linq/resources/messages/messages.py">add_reaction</a>(message_id, \*\*<a href="src/linq/types/message_add_reaction_params.py">params</a>) -> <a href="./src/linq/types/message_add_reaction_response.py">MessageAddReactionResponse</a></code>
- <code title="get /v3/messages/{messageId}/thread">client.messages.<a href="./src/linq/resources/messages/messages.py">list_messages_thread</a>(message_id, \*\*<a href="src/linq/types/message_list_messages_thread_params.py">params</a>) -> <a href="./src/linq/types/message.py">SyncListMessagesPagination[Message]</a></code>
- <code title="post /v3/messages/{messageId}/update">client.messages.<a href="./src/linq/resources/messages/messages.py">update_app_card</a>(message_id, \*\*<a href="src/linq/types/message_update_app_card_params.py">params</a>) -> <a href="./src/linq/types/message_update_app_card_response.py">MessageUpdateAppCardResponse</a></code>

## Poll

Methods:

- <code title="get /v3/messages/{messageId}/poll">client.messages.poll.<a href="./src/linq/resources/messages/poll.py">retrieve</a>(message_id) -> <a href="./src/linq/types/chats/poll_envelope.py">PollEnvelope</a></code>
- <code title="post /v3/messages/{messageId}/poll/options">client.messages.poll.<a href="./src/linq/resources/messages/poll.py">add_options</a>(message_id, \*\*<a href="src/linq/types/messages/poll_add_options_params.py">params</a>) -> <a href="./src/linq/types/chats/poll_envelope.py">PollEnvelope</a></code>
- <code title="post /v3/messages/{messageId}/poll/votes">client.messages.poll.<a href="./src/linq/resources/messages/poll.py">vote</a>(message_id, \*\*<a href="src/linq/types/messages/poll_vote_params.py">params</a>) -> <a href="./src/linq/types/chats/poll_envelope.py">PollEnvelope</a></code>

# Attachments

Expand Down
41 changes: 22 additions & 19 deletions src/linq/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
)
from ._utils import (
is_given,
is_mapping,
is_mapping_t,
get_async_library,
)
Expand Down Expand Up @@ -53,7 +54,6 @@
payment_providers,
webhook_subscriptions,
)
from .resources.messages import MessagesResource, AsyncMessagesResource
from .resources.payments import PaymentsResource, AsyncPaymentsResource
from .resources.webhooks import WebhooksResource, AsyncWebhooksResource
from .resources.capability import CapabilityResource, AsyncCapabilityResource
Expand All @@ -67,6 +67,7 @@
from .resources.payment_handles import PaymentHandlesResource, AsyncPaymentHandlesResource
from .resources.available_number import AvailableNumberResource, AsyncAvailableNumberResource
from .resources.payment_requests import PaymentRequestsResource, AsyncPaymentRequestsResource
from .resources.messages.messages import MessagesResource, AsyncMessagesResource
from .resources.payment_providers import PaymentProvidersResource, AsyncPaymentProvidersResource
from .resources.webhook_subscriptions import WebhookSubscriptionsResource, AsyncWebhookSubscriptionsResource

Expand Down Expand Up @@ -1009,30 +1010,31 @@ def _make_status_error(
body: object,
response: httpx.Response,
) -> APIStatusError:
data = body.get("error", body) if is_mapping(body) else body
if response.status_code == 400:
return _exceptions.BadRequestError(err_msg, response=response, body=body)
return _exceptions.BadRequestError(err_msg, response=response, body=data)

if response.status_code == 401:
return _exceptions.AuthenticationError(err_msg, response=response, body=body)
return _exceptions.AuthenticationError(err_msg, response=response, body=data)

if response.status_code == 403:
return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
return _exceptions.PermissionDeniedError(err_msg, response=response, body=data)

if response.status_code == 404:
return _exceptions.NotFoundError(err_msg, response=response, body=body)
return _exceptions.NotFoundError(err_msg, response=response, body=data)

if response.status_code == 409:
return _exceptions.ConflictError(err_msg, response=response, body=body)
return _exceptions.ConflictError(err_msg, response=response, body=data)

if response.status_code == 422:
return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
return _exceptions.UnprocessableEntityError(err_msg, response=response, body=data)

if response.status_code == 429:
return _exceptions.RateLimitError(err_msg, response=response, body=body)
return _exceptions.RateLimitError(err_msg, response=response, body=data)

if response.status_code >= 500:
return _exceptions.InternalServerError(err_msg, response=response, body=body)
return APIStatusError(err_msg, response=response, body=body)
return _exceptions.InternalServerError(err_msg, response=response, body=data)
return APIStatusError(err_msg, response=response, body=data)


class AsyncLinqAPIV3(AsyncAPIClient):
Expand Down Expand Up @@ -1962,30 +1964,31 @@ def _make_status_error(
body: object,
response: httpx.Response,
) -> APIStatusError:
data = body.get("error", body) if is_mapping(body) else body
if response.status_code == 400:
return _exceptions.BadRequestError(err_msg, response=response, body=body)
return _exceptions.BadRequestError(err_msg, response=response, body=data)

if response.status_code == 401:
return _exceptions.AuthenticationError(err_msg, response=response, body=body)
return _exceptions.AuthenticationError(err_msg, response=response, body=data)

if response.status_code == 403:
return _exceptions.PermissionDeniedError(err_msg, response=response, body=body)
return _exceptions.PermissionDeniedError(err_msg, response=response, body=data)

if response.status_code == 404:
return _exceptions.NotFoundError(err_msg, response=response, body=body)
return _exceptions.NotFoundError(err_msg, response=response, body=data)

if response.status_code == 409:
return _exceptions.ConflictError(err_msg, response=response, body=body)
return _exceptions.ConflictError(err_msg, response=response, body=data)

if response.status_code == 422:
return _exceptions.UnprocessableEntityError(err_msg, response=response, body=body)
return _exceptions.UnprocessableEntityError(err_msg, response=response, body=data)

if response.status_code == 429:
return _exceptions.RateLimitError(err_msg, response=response, body=body)
return _exceptions.RateLimitError(err_msg, response=response, body=data)

if response.status_code >= 500:
return _exceptions.InternalServerError(err_msg, response=response, body=body)
return APIStatusError(err_msg, response=response, body=body)
return _exceptions.InternalServerError(err_msg, response=response, body=data)
return APIStatusError(err_msg, response=response, body=data)


class LinqAPIV3WithRawResponse:
Expand Down
25 changes: 24 additions & 1 deletion src/linq/_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

from __future__ import annotations

from typing import Any, Optional, cast
from typing_extensions import Literal

import httpx

from ._utils import is_dict
from ._models import construct_type

__all__ = [
"BadRequestError",
"AuthenticationError",
Expand Down Expand Up @@ -37,12 +41,31 @@ class APIError(LinqApiv3Error):
If there was no response associated with this error then it will be `None`.
"""

def __init__(self, message: str, request: httpx.Request, *, body: object | None) -> None: # noqa: ARG002
code: Optional[int]
"""Linq API error code."""
doc_url: Optional[str]
"""Link to documentation for this error code"""
retry_after: Optional[int] = None
"""Number of seconds to wait before retrying.

Only present on 429 rate limit errors.
"""

def __init__(self, message: str, request: httpx.Request, *, body: object | None) -> None:
super().__init__(message)
self.request = request
self.message = message
self.body = body

if is_dict(body):
self.code = cast(Any, construct_type(type_=int, value=body.get("code")))
self.doc_url = cast(Any, construct_type(type_=str, value=body.get("doc_url")))
self.retry_after = cast(Any, construct_type(type_=Optional[int], value=body.get("retry_after")))
else:
self.code = None
self.doc_url = None
self.retry_after = None


class APIResponseValidationError(APIError):
response: httpx.Response
Expand Down
14 changes: 14 additions & 0 deletions src/linq/resources/chats/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
ChatsResourceWithStreamingResponse,
AsyncChatsResourceWithStreamingResponse,
)
from .polls import (
PollsResource,
AsyncPollsResource,
PollsResourceWithRawResponse,
AsyncPollsResourceWithRawResponse,
PollsResourceWithStreamingResponse,
AsyncPollsResourceWithStreamingResponse,
)
from .typing import (
TypingResource,
AsyncTypingResource,
Expand Down Expand Up @@ -66,6 +74,12 @@
"AsyncLocationResourceWithRawResponse",
"LocationResourceWithStreamingResponse",
"AsyncLocationResourceWithStreamingResponse",
"PollsResource",
"AsyncPollsResource",
"PollsResourceWithRawResponse",
"AsyncPollsResourceWithRawResponse",
"PollsResourceWithStreamingResponse",
"AsyncPollsResourceWithStreamingResponse",
"ChatsResource",
"AsyncChatsResource",
"ChatsResourceWithRawResponse",
Expand Down
Loading
Loading