Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PBE-1321] support campaign endpoints #155

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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
35 changes: 20 additions & 15 deletions stream_chat/async_chat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
)
from urllib.parse import urlparse

from stream_chat.types.campaign import CampaignData, QueryCampaignsOptions
from stream_chat.types.segment import SegmentType, SegmentData, QuerySegmentsOptions, UpdateSegmentData
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
from stream_chat.types.segment import SegmentType, SegmentData, QuerySegmentsOptions, UpdateSegmentData
from stream_chat.types.segment import (
SegmentType,
SegmentData,
QuerySegmentsOptions,
UpdateSegmentData,
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <1> reported by reviewdog 🐶
isort found an import in the wrong position


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <5> reported by reviewdog 🐶
isort found an unexpected missing import

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <5> reported by reviewdog 🐶
isort found an unexpected missing import

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <5> reported by reviewdog 🐶
isort found an unexpected missing import

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <5> reported by reviewdog 🐶
isort found an unexpected missing import

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <5> reported by reviewdog 🐶
isort found an unexpected missing import

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <5> reported by reviewdog 🐶
isort found an unexpected missing import

if sys.version_info >= (3, 8):
from typing import Literal
else:
Expand Down Expand Up @@ -537,35 +540,37 @@ async def delete_role(self, name: str) -> StreamResponse:
async def list_roles(self) -> StreamResponse:
return await self.get("roles")

async def create_segment(self, segment: Dict) -> StreamResponse:
return await self.post("segments", data={"segment": segment})
async def create_segment(self, segment_type: SegmentType, segment_id: str, segment_name: str, data: SegmentData) -> StreamResponse:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [mypy] reported by reviewdog 🐶
Signature of "create_segment" incompatible with supertype "StreamChatInterface" [override]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
Superclass:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
def create_segment(self, segment_type: SegmentType, segment_id: str | None, data: SegmentData | None = ...) -> StreamResponse | Awaitable[StreamResponse]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
Subclass:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
def create_segment(self, segment_type: SegmentType, segment_id: str, segment_name: str, data: SegmentData) -> Coroutine[Any, Any, StreamResponse]

return await self.post("segments", data={"type": segment_type.value, "id": segment_id, "name": segment_name, "data": data})

async def query_segments(self, **params: Any) -> StreamResponse:
return await self.get("segments", params={"payload": json.dumps(params)})
async def query_segments(self, filter_conditions: Dict, options: QuerySegmentsOptions) -> StreamResponse:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
async def create_segment(self, segment_type: SegmentType, segment_id: str, segment_name: str, data: SegmentData) -> StreamResponse:
return await self.post("segments", data={"type": segment_type.value, "id": segment_id, "name": segment_name, "data": data})
async def query_segments(self, **params: Any) -> StreamResponse:
return await self.get("segments", params={"payload": json.dumps(params)})
async def query_segments(self, filter_conditions: Dict, options: QuerySegmentsOptions) -> StreamResponse:
async def create_segment(
self,
segment_type: SegmentType,
segment_id: str,
segment_name: str,
data: SegmentData,
) -> StreamResponse:
return await self.post(
"segments",
data={
"type": segment_type.value,
"id": segment_id,
"name": segment_name,
"data": data,
},
)
async def query_segments(
self, filter_conditions: Dict, options: QuerySegmentsOptions
) -> StreamResponse:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
async def query_segments(self, filter_conditions: Dict, options: QuerySegmentsOptions) -> StreamResponse:
async def query_segments(
self, filter_conditions: Dict, options: QuerySegmentsOptions
) -> StreamResponse:

payload = {"filter": filter_conditions, **options}
return await self.post("segments/query", params=payload)

async def update_segment(self, segment_id: str, data: Dict) -> StreamResponse:
return await self.put(f"segments/{segment_id}", data={"segment": data})
async def update_segment(self, segment_id: str, data: UpdateSegmentData) -> StreamResponse:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
async def update_segment(self, segment_id: str, data: UpdateSegmentData) -> StreamResponse:
async def update_segment(
self, segment_id: str, data: UpdateSegmentData
) -> StreamResponse:

return await self.put(f"segments/{segment_id}", data=data)

async def delete_segment(self, segment_id: str) -> StreamResponse:
return await self.delete(f"segments/{segment_id}")

async def create_campaign(self, campaign: Dict) -> StreamResponse:
return await self.post("campaigns", data={"campaign": campaign})
async def create_campaign(self, params: CampaignData) -> StreamResponse:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [mypy] reported by reviewdog 🐶
Signature of "create_campaign" incompatible with supertype "StreamChatInterface" [override]

return await self.post("campaigns", data=params)

async def query_campaigns(self, **params: Any) -> StreamResponse:
return await self.get("campaigns", params={"payload": json.dumps(params)})
async def query_campaigns(self, filter_conditions: Dict[str, Any], options: QueryCampaignsOptions = None) -> StreamResponse:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
async def query_campaigns(self, filter_conditions: Dict[str, Any], options: QueryCampaignsOptions = None) -> StreamResponse:
async def query_campaigns(
self, filter_conditions: Dict[str, Any], options: QueryCampaignsOptions = None
) -> StreamResponse:

payload = {"filter": filter_conditions, **options}
return await self.post("campaigns/query", params=payload)

async def update_campaign(self, campaign_id: str, data: Dict) -> StreamResponse:
return await self.put(f"campaigns/{campaign_id}", data={"campaign": data})
async def update_campaign(self, campaign_id: str, params: CampaignData) -> StreamResponse:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
async def update_campaign(self, campaign_id: str, params: CampaignData) -> StreamResponse:
async def update_campaign(
self, campaign_id: str, params: CampaignData
) -> StreamResponse:

return await self.put(f"campaigns/{campaign_id}", data=params)

async def delete_campaign(self, campaign_id: str, **options: Any) -> StreamResponse:
return await self.delete(f"campaigns/{campaign_id}", params=options)

async def schedule_campaign(
self, campaign_id: str, scheduled_for: int = None
async def start_campaign(
self, campaign_id: str, scheduled_for: Optional[datetime.datetime] = None
) -> StreamResponse:
return await self.patch(
f"campaigns/{campaign_id}/schedule", data={"scheduled_for": scheduled_for}
f"campaigns/{campaign_id}/start", data={"scheduled_for": scheduled_for}
)

async def query_recipients(self, **params: Any) -> StreamResponse:
Expand Down
42 changes: 42 additions & 0 deletions stream_chat/base/campaign.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import abc
from typing import Awaitable, Dict, List, Union, Optional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <1> reported by reviewdog 🐶
isort found an import in the wrong position

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[flake8] <401> reported by reviewdog 🐶
'typing.Dict' imported but unused

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[flake8] <401> reported by reviewdog 🐶
'typing.List' imported but unused


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <5> reported by reviewdog 🐶
isort found an unexpected missing import

from stream_chat.base.client import StreamChatInterface
from stream_chat.types.campaign import CampaignData
from stream_chat.types.stream_response import StreamResponse


class CampaignInterface(abc.ABC):
def __init__(
self,
client: StreamChatInterface,
campaign_id: Optional[str] = None,
data: CampaignData = None,
):
self.client = client
self.campaign_id = campaign_id
self.data = data

@abc.abstractmethod
def create(self) -> Union[StreamResponse, Awaitable[StreamResponse]]:
pass

@abc.abstractmethod
def get(self) -> Union[StreamResponse, Awaitable[StreamResponse]]:
pass

@abc.abstractmethod
def update(self) -> Union[StreamResponse, Awaitable[StreamResponse]]:
pass

@abc.abstractmethod
def delete(self) -> Union[StreamResponse, Awaitable[StreamResponse]]:
pass

@abc.abstractmethod
def start(self) -> Union[StreamResponse, Awaitable[StreamResponse]]:
pass

@abc.abstractmethod
def stop(self) -> Union[StreamResponse, Awaitable[StreamResponse]]:
pass
56 changes: 46 additions & 10 deletions stream_chat/base/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import hmac
import os
import sys
from typing import Any, Awaitable, Dict, Iterable, List, TypeVar, Union
from typing import Any, Awaitable, Dict, Iterable, List, TypeVar, Union, Optional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <1> reported by reviewdog 🐶
isort found an import in the wrong position


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <5> reported by reviewdog 🐶
isort found an unexpected missing import

from stream_chat.types.campaign import CampaignData, QueryCampaignsOptions
from stream_chat.types.segment import SegmentType, SegmentData, QuerySegmentsOptions, UpdateSegmentData
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
from stream_chat.types.segment import SegmentType, SegmentData, QuerySegmentsOptions, UpdateSegmentData
from stream_chat.types.segment import (
SegmentType,
SegmentData,
QuerySegmentsOptions,
UpdateSegmentData,
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <1> reported by reviewdog 🐶
isort found an import in the wrong position


if sys.version_info >= (3, 8):
from typing import Literal
Expand All @@ -18,6 +21,10 @@

TChannel = TypeVar("TChannel")

TSegment = TypeVar("TSegment")

TCampaign = TypeVar("TCampaign")


class StreamChatInterface(abc.ABC):
def __init__(
Expand Down Expand Up @@ -585,7 +592,6 @@ def channel(
) -> TChannel: # type: ignore[type-var]
"""
Creates a channel object

:param channel_type: the channel type
:param channel_id: the id of the channel
:param data: additional data, ie: {"members":[id1, id2, ...]}
Expand Down Expand Up @@ -918,9 +924,20 @@ def list_roles(self) -> Union[StreamResponse, Awaitable[StreamResponse]]:
"""
pass

def segment(self, segment_type: SegmentType, segment_id: str, segment_name: str) -> TSegment:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
def segment(self, segment_type: SegmentType, segment_id: str, segment_name: str) -> TSegment:
def segment(
self, segment_type: SegmentType, segment_id: str, segment_name: str
) -> TSegment:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[flake8] <27> reported by reviewdog 🐶
segment is an empty method in an abstract base class, but has no abstract decorator. Consider adding @AbstractMethod.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [mypy] reported by reviewdog 🐶
A function returning TypeVar should receive at least one argument containing the same TypeVar [type-var]

"""
Creates a channel object
:param segment_type: the segment type
:param segment_id: the id of the segment
:param segment_name: the name of the segment
:param data: additional data, ie: {"members":[id1, id2, ...]}
:return: Channel
"""
pass

@abc.abstractmethod
def create_segment(
self, segment: Dict
self, segment_type: SegmentType, segment_id: str, segment_name: str, data: SegmentData
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
self, segment_type: SegmentType, segment_id: str, segment_name: str, data: SegmentData
self,
segment_type: SegmentType,
segment_id: str,
segment_name: str,
data: SegmentData,

) -> Union[StreamResponse, Awaitable[StreamResponse]]:
"""
Create a segment
Expand All @@ -929,7 +946,7 @@ def create_segment(

@abc.abstractmethod
def query_segments(
self, **params: Any
self, filter_conditions: Dict, options: QuerySegmentsOptions
) -> Union[StreamResponse, Awaitable[StreamResponse]]:
"""
Query segments
Expand All @@ -938,7 +955,7 @@ def query_segments(

@abc.abstractmethod
def update_segment(
self, segment_id: str, data: Dict
self, segment_id: str, data: UpdateSegmentData
) -> Union[StreamResponse, Awaitable[StreamResponse]]:
"""
Update a segment by id
Expand All @@ -954,9 +971,28 @@ def delete_segment(
"""
pass

def campaign(self, campaign_id: Optional[str]):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[flake8] <27> reported by reviewdog 🐶
campaign is an empty method in an abstract base class, but has no abstract decorator. Consider adding @AbstractMethod.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [mypy] reported by reviewdog 🐶
Function is missing a return type annotation [no-untyped-def]

"""
Creates a channel object
:param channel_type: the channel type
:param channel_id: the id of the channel
:param data: additional data, ie: {"members":[id1, id2, ...]}
:return: Channel
"""
pass

@abc.abstractmethod
def create_campaign(
self, campaign: Dict
self, campaign_id: Optional[str], data: Optional[CampaignData]
) -> Union[StreamResponse, Awaitable[StreamResponse]]:
"""
Create a campaign
"""
pass

@abc.abstractmethod
def get_campaign(
self, campaign_id: str
) -> Union[StreamResponse, Awaitable[StreamResponse]]:
"""
Create a campaign
Expand All @@ -965,7 +1001,7 @@ def create_campaign(

@abc.abstractmethod
def query_campaigns(
self, **params: Any
self, filter_conditions: Dict[str, Any], options: QueryCampaignsOptions = None
) -> Union[StreamResponse, Awaitable[StreamResponse]]:
"""
Query campaigns
Expand All @@ -974,7 +1010,7 @@ def query_campaigns(

@abc.abstractmethod
def update_campaign(
self, campaign_id: str, data: Dict
self, campaign_id: str, data: CampaignData
) -> Union[StreamResponse, Awaitable[StreamResponse]]:
"""
Update a campaign
Expand All @@ -991,8 +1027,8 @@ def delete_campaign(
pass

@abc.abstractmethod
def schedule_campaign(
self, campaign_id: str, scheduled_for: int = None
def start_campaign(
self, campaign_id: str, scheduled_for: Optional[datetime.datetime] = None
) -> Union[StreamResponse, Awaitable[StreamResponse]]:
"""
Schedule a campaign at given time
Expand Down
38 changes: 38 additions & 0 deletions stream_chat/base/segment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import abc
from typing import Optional, Awaitable, Union
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <1> reported by reviewdog 🐶
isort found an import in the wrong position


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <5> reported by reviewdog 🐶
isort found an unexpected missing import

from stream_chat.base.client import StreamChatInterface
from stream_chat.types.segment import SegmentType, SegmentData, UpdateSegmentData
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <1> reported by reviewdog 🐶
isort found an import in the wrong position

from stream_chat.types.stream_response import StreamResponse
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <5> reported by reviewdog 🐶
isort found an unexpected missing import



class SegmentInterface(abc.ABC):
def __init__(
self,
client: StreamChatInterface,
segment_type: SegmentType,
segment_id: Optional[str] = None,
segment_name: Optional[str] = None,
data: Optional[SegmentData] = None,
):
self.segment_type = segment_type
self.segment_id = segment_id
self.segment_name = segment_name
self.client = client
self.data = data

@abc.abstractmethod
def create(self) -> Union[StreamResponse, Awaitable[StreamResponse]]:
pass

@abc.abstractmethod
def get(self) -> Union[StreamResponse, Awaitable[StreamResponse]]:
pass

@abc.abstractmethod
def update(self, data: UpdateSegmentData) -> Union[StreamResponse, Awaitable[StreamResponse]]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
def update(self, data: UpdateSegmentData) -> Union[StreamResponse, Awaitable[StreamResponse]]:
def update(
self, data: UpdateSegmentData
) -> Union[StreamResponse, Awaitable[StreamResponse]]:

pass

@abc.abstractmethod
def delete(self) -> Union[StreamResponse, Awaitable[StreamResponse]]:
pass
31 changes: 31 additions & 0 deletions stream_chat/campaign.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from stream_chat.base.campaign import CampaignInterface
from stream_chat.types.stream_response import StreamResponse


class Campaign(CampaignInterface):

def create(self) -> StreamResponse:
state = self.client.create_campaign(campaign_id=self.campaign_id, data=self.data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
state = self.client.create_campaign(campaign_id=self.campaign_id, data=self.data)
state = self.client.create_campaign(
campaign_id=self.campaign_id, data=self.data
)


if self.campaign_id is None and state.is_ok() and "campaign" in state:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [mypy] reported by reviewdog 🐶
Item "Awaitable[StreamResponse]" of "StreamResponse | Awaitable[StreamResponse]" has no attribute "is_ok" [union-attr]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
Maybe you forgot to use "await"?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [mypy] reported by reviewdog 🐶
Unsupported right operand type for in ("StreamResponse | Awaitable[StreamResponse]") [operator]

self.campaign_id = state["campaign"]["id"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [mypy] reported by reviewdog 🐶
Value of type "StreamResponse | Awaitable[StreamResponse]" is not indexable [index]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
Maybe you forgot to use "await"?

return state
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [mypy] reported by reviewdog 🐶
Incompatible return value type (got "StreamResponse | Awaitable[StreamResponse]", expected "StreamResponse") [return-value]


def get(self) -> StreamResponse:
return self.client.get_campaign(campaign_id=self.campaign_id)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [mypy] reported by reviewdog 🐶
Incompatible return value type (got "StreamResponse | Awaitable[StreamResponse]", expected "StreamResponse") [return-value]


def update(self, name: str = None, description: str = None) -> StreamResponse:
payload = {"name": name, "description": description}
return self.client.put(f"campaigns/{self.campaign_id}", data=payload)

def delete(self) -> StreamResponse:
return self.client.delete(f"campaigns/{self.campaign_id}")

def start(self) -> StreamResponse:
return self.client.get(f"campaigns/{self.campaign_id}")

def stop(self) -> StreamResponse:
return self.client.get(f"campaigns/{self.campaign_id}")

def query(self) -> StreamResponse:
return self.client.get(f"campaigns/{self.campaign_id}")
57 changes: 40 additions & 17 deletions stream_chat/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@
import json
import sys
import warnings
from typing import Any, Callable, Dict, Iterable, List, Union
from typing import Any, Callable, Dict, Iterable, List, Union, Optional
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <1> reported by reviewdog 🐶
isort found an import in the wrong position

from urllib.parse import urlparse
from urllib.request import Request, urlopen

from stream_chat.campaign import Campaign
from stream_chat.segment import Segment
from stream_chat.types.campaign import QueryCampaignsOptions, CampaignData
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <1> reported by reviewdog 🐶
isort found an import in the wrong position

from stream_chat.types.segment import SegmentType, QuerySegmentsOptions, UpdateSegmentData, SegmentData
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
from stream_chat.types.segment import SegmentType, QuerySegmentsOptions, UpdateSegmentData, SegmentData
from stream_chat.types.segment import (
SegmentType,
QuerySegmentsOptions,
UpdateSegmentData,
SegmentData,
)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <1> reported by reviewdog 🐶
isort found an import in the wrong position


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <5> reported by reviewdog 🐶
isort found an unexpected missing import

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <5> reported by reviewdog 🐶
isort found an unexpected missing import

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <5> reported by reviewdog 🐶
isort found an unexpected missing import

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <5> reported by reviewdog 🐶
isort found an unexpected missing import

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <5> reported by reviewdog 🐶
isort found an unexpected missing import

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [flake8] <5> reported by reviewdog 🐶
isort found an unexpected missing import

if sys.version_info >= (3, 8):
from typing import Literal
else:
from typing_extensions import Literal


import requests

from stream_chat.__pkg__ import __version__
Expand Down Expand Up @@ -518,35 +522,54 @@ def delete_role(self, name: str) -> StreamResponse:
def list_roles(self) -> StreamResponse:
return self.get("roles")

def create_segment(self, segment: Dict) -> StreamResponse:
return self.post("segments", data={"segment": segment})
def segment(self, segment_type: SegmentType, segment_id: Optional[str] = None, segment_name: Optional[str] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [mypy] reported by reviewdog 🐶
Signature of "segment" incompatible with supertype "StreamChatInterface" [override]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
Superclass:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
def [TSegment] segment(self, segment_type: SegmentType, segment_id: str, segment_name: str) -> TSegment

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
Subclass:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
def segment(self, segment_type: SegmentType, segment_id: str | None = ..., segment_name: str | None = ..., data: SegmentData | None = ...) -> Segment

data: Optional[SegmentData] = None) -> Segment:
return Segment(client=self, segment_type=segment_type, segment_id=segment_id, segment_name=segment_name,
data=data)

def create_segment(self, segment_type: SegmentType, segment_id: Optional[str] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [mypy] reported by reviewdog 🐶
Signature of "create_segment" incompatible with supertype "StreamChatInterface" [override]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
Superclass:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
def create_segment(self, segment_type: SegmentType, segment_id: str, segment_name: str, data: SegmentData) -> StreamResponse | Awaitable[StreamResponse]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
Subclass:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
def create_segment(self, segment_type: SegmentType, segment_id: str | None = ..., segment_name: str | None = ..., data: dict[Any, Any] = ...) -> StreamResponse

segment_name: Optional[str] = None, data: Dict = None) -> StreamResponse:
return self.post("segments",
data={"type": segment_type.value, "id": segment_id, "name": segment_name, "data": data})

def query_segments(self, **params: Any) -> StreamResponse:
return self.get("segments", params={"payload": json.dumps(params)})
def query_segments(self, filter_conditions: Dict, options: QuerySegmentsOptions) -> StreamResponse:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
def segment(self, segment_type: SegmentType, segment_id: Optional[str] = None, segment_name: Optional[str] = None,
data: Optional[SegmentData] = None) -> Segment:
return Segment(client=self, segment_type=segment_type, segment_id=segment_id, segment_name=segment_name,
data=data)
def create_segment(self, segment_type: SegmentType, segment_id: Optional[str] = None,
segment_name: Optional[str] = None, data: Dict = None) -> StreamResponse:
return self.post("segments",
data={"type": segment_type.value, "id": segment_id, "name": segment_name, "data": data})
def query_segments(self, **params: Any) -> StreamResponse:
return self.get("segments", params={"payload": json.dumps(params)})
def query_segments(self, filter_conditions: Dict, options: QuerySegmentsOptions) -> StreamResponse:
def segment(
self,
segment_type: SegmentType,
segment_id: Optional[str] = None,
segment_name: Optional[str] = None,
data: Optional[SegmentData] = None,
) -> Segment:
return Segment(
client=self,
segment_type=segment_type,
segment_id=segment_id,
segment_name=segment_name,
data=data,
)
def create_segment(
self,
segment_type: SegmentType,
segment_id: Optional[str] = None,
segment_name: Optional[str] = None,
data: Dict = None,
) -> StreamResponse:
return self.post(
"segments",
data={
"type": segment_type.value,
"id": segment_id,
"name": segment_name,
"data": data,
},
)
def query_segments(
self, filter_conditions: Dict, options: QuerySegmentsOptions
) -> StreamResponse:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
def query_segments(self, filter_conditions: Dict, options: QuerySegmentsOptions) -> StreamResponse:
def query_segments(
self, filter_conditions: Dict, options: QuerySegmentsOptions
) -> StreamResponse:

payload = {"filter": filter_conditions, **options}
return self.post("segments/query", data=payload)

def update_segment(self, segment_id: str, data: Dict) -> StreamResponse:
return self.put(f"segments/{segment_id}", data={"segment": data})
def update_segment(self, segment_id: str, data: UpdateSegmentData) -> StreamResponse:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
def update_segment(self, segment_id: str, data: UpdateSegmentData) -> StreamResponse:
def update_segment(
self, segment_id: str, data: UpdateSegmentData
) -> StreamResponse:

return self.put(f"segments/{segment_id}", data=data)

def delete_segment(self, segment_id: str) -> StreamResponse:
return self.delete(f"segments/{segment_id}")

def create_campaign(self, campaign: Dict) -> StreamResponse:
return self.post("campaigns", data={"campaign": campaign})
def campaign(self, campaign_id: Optional[str] = None, data: CampaignData = None) -> Campaign:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
def campaign(self, campaign_id: Optional[str] = None, data: CampaignData = None) -> Campaign:
def campaign(
self, campaign_id: Optional[str] = None, data: CampaignData = None
) -> Campaign:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [mypy] reported by reviewdog 🐶
Signature of "campaign" incompatible with supertype "StreamChatInterface" [override]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
Superclass:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
def [TCampaign] campaign(self, campaign_id: str | None, data: CampaignData | None) -> TCampaign

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
Subclass:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
def campaign(self, campaign_id: str | None = ..., data: CampaignData = ...) -> Campaign

return Campaign(client=self, campaign_id=campaign_id, data=data)

def create_campaign(self, campaign_id: Optional[str] = None, data: CampaignData = None) -> StreamResponse:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
def create_campaign(self, campaign_id: Optional[str] = None, data: CampaignData = None) -> StreamResponse:
def create_campaign(
self, campaign_id: Optional[str] = None, data: CampaignData = None
) -> StreamResponse:

payload = {"id": campaign_id}
if data is not None:
payload.update(data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [mypy] reported by reviewdog 🐶
Argument 1 to "update" of "MutableMapping" has incompatible type "CampaignData"; expected "SupportsKeysAndGetItem[str, str]" [arg-type]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
Following member(s) of "CampaignData" have conflicts:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
Expected:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
def getitem(self, str, /) -> str

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
Got:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 [mypy] reported by reviewdog 🐶
def getitem(self, str, /) -> object

return self.post("campaigns", data=payload)

def get_campaign(self, campaign_id: str) -> StreamResponse:
return self.get(f"campaigns/{campaign_id}")

def query_campaigns(self, **params: Any) -> StreamResponse:
return self.get("campaigns", params={"payload": json.dumps(params)})
def query_campaigns(self, filter_conditions: Dict[str, Any],
options: QueryCampaignsOptions = None) -> StreamResponse:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
def query_campaigns(self, filter_conditions: Dict[str, Any],
options: QueryCampaignsOptions = None) -> StreamResponse:
def query_campaigns(
self, filter_conditions: Dict[str, Any], options: QueryCampaignsOptions = None
) -> StreamResponse:

payload = {"filter": filter_conditions, **options}
return self.post("campaigns/query", data=payload)

def update_campaign(self, campaign_id: str, data: Dict) -> StreamResponse:
return self.put(f"campaigns/{campaign_id}", data={"campaign": data})
def update_campaign(self, campaign_id: str, params: CampaignData) -> StreamResponse:
return self.put(f"campaigns/{campaign_id}", data=params)

def delete_campaign(self, campaign_id: str, **options: Any) -> StreamResponse:
return self.delete(f"campaigns/{campaign_id}", params=options)

def schedule_campaign(
self, campaign_id: str, scheduled_for: int = None
def start_campaign(
self, campaign_id: str, scheduled_for: Optional[datetime.datetime] = None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[black] reported by reviewdog 🐶

Suggested change
self, campaign_id: str, scheduled_for: Optional[datetime.datetime] = None
self, campaign_id: str, scheduled_for: Optional[datetime.datetime] = None

) -> StreamResponse:
return self.patch(
f"campaigns/{campaign_id}/schedule", data={"scheduled_for": scheduled_for}
f"campaigns/{campaign_id}/start", data={"scheduled_for": scheduled_for}
)

def stop_campaign(self, campaign_id: str) -> StreamResponse:
Expand Down
Loading
Loading