Skip to content

Commit

Permalink
Removes all FE1 client functions (#380)
Browse files Browse the repository at this point in the history
* Removes all FE1 client functions

* Removed usages of deprecated client functions

* removed trailing deprecated client function

* ruff

* Fixed last failing test
  • Loading branch information
JR-Morgan authored Feb 18, 2025
1 parent da6e2d9 commit d1b6755
Show file tree
Hide file tree
Showing 45 changed files with 112 additions and 4,337 deletions.
65 changes: 6 additions & 59 deletions src/specklepy/api/client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import contextlib

from deprecated import deprecated

from specklepy.api.credentials import Account
from specklepy.api.resources import (
ActiveUserResource,
Expand All @@ -12,12 +10,6 @@
ServerResource,
SubscriptionResource,
VersionResource,
branch,
commit,
object,
stream,
subscriptions,
user,
)
from specklepy.core.api.client import SpeckleClient as CoreSpeckleClient
from specklepy.logging import metrics
Expand All @@ -36,6 +28,7 @@ class SpeckleClient(CoreSpeckleClient):
```py
from specklepy.api.client import SpeckleClient
from specklepy.core.api.inputs.project_inputs import ProjectCreateInput
from specklepy.api.credentials import get_default_account
# initialise the client
Expand All @@ -47,11 +40,12 @@ class SpeckleClient(CoreSpeckleClient):
account = get_default_account()
client.authenticate_with_account(account)
# create a new stream. this returns the stream id
new_stream_id = client.stream.create(name="a shiny new stream")
# create a new project
input = ProjectCreateInput(name="a shiny new project")
project = self.project.create(input)
# use that stream id to get the stream from the server
new_stream = client.stream.get(id=new_stream_id)
# or, use a project id to get an existing project from the server
new_stream = client.project.get("abcdefghij")
```
"""

Expand Down Expand Up @@ -123,53 +117,6 @@ def _init_resources(self) -> None:
client=self.wsclient,
# todo: why doesn't this take a server version
)
# Deprecated Resources
self.user = user.Resource(
account=self.account,
basepath=self.url,
client=self.httpclient,
server_version=server_version,
)
self.stream = stream.Resource(
account=self.account,
basepath=self.url,
client=self.httpclient,
server_version=server_version,
)
self.commit = commit.Resource(
account=self.account, basepath=self.url, client=self.httpclient
)
self.branch = branch.Resource(
account=self.account, basepath=self.url, client=self.httpclient
)
self.object = object.Resource(
account=self.account, basepath=self.url, client=self.httpclient
)
self.subscribe = subscriptions.Resource(
account=self.account,
basepath=self.ws_url,
client=self.wsclient,
)

@deprecated(
version="2.6.0",
reason=(
"Renamed: please use `authenticate_with_account` or"
" `authenticate_with_token` instead."
),
)
def authenticate(self, token: str) -> None:
"""Authenticate the client using a personal access token
The token is saved in the client object and a synchronous GraphQL
entrypoint is created
Arguments:
token {str} -- an api token
"""
metrics.track(
metrics.SDK, self.account, {"name": "Client Authenticate_deprecated"}
)
return super().authenticate(token)

def authenticate_with_token(self, token: str) -> None:
"""
Expand Down
20 changes: 0 additions & 20 deletions src/specklepy/api/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,15 @@
# following imports seem to be unnecessary, but they need to stay
# to not break the scripts using these functions as non-core
from specklepy.core.api.models import (
Activity,
ActivityCollection,
Branch,
Branches,
Collaborator,
Commit,
Commits,
LimitedUser,
Object,
PendingStreamCollaborator,
ServerInfo,
Stream,
Streams,
User,
)

__all__ = [
"Activity",
"ActivityCollection",
"Branch",
"Branches",
"Collaborator",
"Commit",
"Commits",
"LimitedUser",
"Object",
"PendingStreamCollaborator",
"ServerInfo",
"Stream",
"Streams",
"User",
]
20 changes: 0 additions & 20 deletions src/specklepy/api/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,6 @@
from specklepy.api.resources.current.server_resource import ServerResource
from specklepy.api.resources.current.subscription_resource import SubscriptionResource
from specklepy.api.resources.current.version_resource import VersionResource
from specklepy.api.resources.deprecated import (
active_user,
branch,
commit,
object,
other_user,
server,
stream,
subscriptions,
user,
)

__all__ = [
"ActiveUserResource",
Expand All @@ -29,13 +18,4 @@
"ServerResource",
"SubscriptionResource",
"VersionResource",
"active_user",
"branch",
"commit",
"object",
"other_user",
"server",
"stream",
"subscriptions",
"user",
]
100 changes: 4 additions & 96 deletions src/specklepy/api/resources/current/active_user_resource.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
from datetime import datetime
from typing import List, Optional, overload

from deprecated import deprecated
from typing import List, Optional

from specklepy.core.api.inputs.user_inputs import UserProjectsFilter, UserUpdateInput
from specklepy.core.api.models import (
Expand All @@ -10,10 +7,6 @@
ResourceCollection,
User,
)
from specklepy.core.api.models.deprecated import (
FE1_DEPRECATION_REASON,
FE1_DEPRECATION_VERSION,
)
from specklepy.core.api.resources import ActiveUserResource as CoreResource
from specklepy.logging import metrics

Expand All @@ -35,40 +28,13 @@ def get(self) -> Optional[User]:
metrics.track(metrics.SDK, self.account, {"name": "Active User Get"})
return super().get()

@deprecated("Use UserUpdateInput overload", version=FE1_DEPRECATION_VERSION)
@overload
def update(
self,
name: Optional[str] = None,
company: Optional[str] = None,
bio: Optional[str] = None,
avatar: Optional[str] = None,
) -> User: ...

@overload
def update(self, *, input: UserUpdateInput) -> User: ...

def update(
self,
name: Optional[str] = None,
company: Optional[str] = None,
bio: Optional[str] = None,
avatar: Optional[str] = None,
*,
input: Optional[UserUpdateInput] = None,
input: UserUpdateInput,
) -> User:
metrics.track(metrics.SDK, self.account, {"name": "Active User Update"})
if isinstance(input, UserUpdateInput):
return super()._update(input=input)
else:
return super()._update(
input=UserUpdateInput(
name=name,
company=company,
bio=bio,
avatar=avatar,
)
)

return super().update(input=input)

def get_projects(
self,
Expand All @@ -85,61 +51,3 @@ def get_project_invites(self) -> List[PendingStreamCollaborator]:
metrics.SDK, self.account, {"name": "Active User Get Project Invites"}
)
return super().get_project_invites()

@deprecated(reason=FE1_DEPRECATION_REASON, version=FE1_DEPRECATION_VERSION)
def activity(
self,
limit: int = 20,
action_type: Optional[str] = None,
before: Optional[datetime] = None,
after: Optional[datetime] = None,
cursor: Optional[datetime] = None,
):
"""
Fetches collection the current authenticated user's activity
as filtered by given parameters
Note: all timestamps arguments should be `datetime` of any tz as they will be
converted to UTC ISO format strings
Args:
limit (int): The maximum number of activity items to return.
action_type (Optional[str]): Filter results to a single action type.
before (Optional[datetime]): Latest cutoff for activity to include.
after (Optional[datetime]): Oldest cutoff for an activity to include.
cursor (Optional[datetime]): Timestamp cursor for pagination.
Returns:
Activity collection, filtered according to the provided parameters.
"""
metrics.track(metrics.SDK, self.account, {"name": "User Active Activity"})
return super().activity(limit, action_type, before, after, cursor)

@deprecated(reason=FE1_DEPRECATION_REASON, version=FE1_DEPRECATION_VERSION)
def get_all_pending_invites(self) -> List[PendingStreamCollaborator]:
"""Fetches all of the current user's pending stream invitations.
Returns:
List[PendingStreamCollaborator]: A list of pending stream invitations.
"""
metrics.track(
metrics.SDK, self.account, {"name": "User Active Invites All Get"}
)
return super().get_all_pending_invites()

@deprecated(reason=FE1_DEPRECATION_REASON, version=FE1_DEPRECATION_VERSION)
def get_pending_invite(
self, stream_id: str, token: Optional[str] = None
) -> Optional[PendingStreamCollaborator]:
"""Fetches a specific pending invite for the current user on a given stream.
Args:
stream_id (str): The ID of the stream to look for invites on.
token (Optional[str]): The token of the invite to look for (optional).
Returns:
Optional[PendingStreamCollaborator]: The invite for the given stream,
or None if not found.
"""
metrics.track(metrics.SDK, self.account, {"name": "User Active Invite Get"})
return super().get_pending_invite(stream_id, token)
65 changes: 1 addition & 64 deletions src/specklepy/api/resources/current/other_user_resource.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
from datetime import datetime
from typing import List, Optional, Union

from deprecated import deprecated
from typing import Optional

from specklepy.core.api.models import (
ActivityCollection,
LimitedUser,
UserSearchResultCollection,
)
from specklepy.core.api.models.deprecated import (
FE1_DEPRECATION_REASON,
FE1_DEPRECATION_VERSION,
)
from specklepy.core.api.resources import OtherUserResource as CoreResource
from specklepy.logging import metrics
from specklepy.logging.exceptions import SpeckleException


class OtherUserResource(CoreResource):
Expand Down Expand Up @@ -52,57 +43,3 @@ def user_search(
return super().user_search(
query, limit=limit, cursor=cursor, archived=archived, emailOnly=emailOnly
)

@deprecated(reason="Use user_search instead", version=FE1_DEPRECATION_VERSION)
def search(
self, search_query: str, limit: int = 25
) -> Union[List[LimitedUser], SpeckleException]:
"""
Searches for users by name or email.
The search requires a minimum query length of 3 characters.
Args:
search_query (str): The search string.
limit (int): Maximum number of search results to return.
Returns:
Union[List[LimitedUser], SpeckleException]:
A list of users matching the search
query or an exception if the query is too short.
"""
if len(search_query) < 3:
return SpeckleException(
message="User search query must be at least 3 characters."
)

metrics.track(metrics.SDK, self.account, {"name": "Other User Search"})
return super().search(search_query, limit)

@deprecated(reason=FE1_DEPRECATION_REASON, version=FE1_DEPRECATION_VERSION)
def activity(
self,
user_id: str,
limit: int = 20,
action_type: Optional[str] = None,
before: Optional[datetime] = None,
after: Optional[datetime] = None,
cursor: Optional[datetime] = None,
) -> ActivityCollection:
"""
Retrieves a collection of activities for a specified user,
with optional filters for activity type, time frame, and pagination.
Args:
user_id (str): The ID of the user whose activities are being requested.
limit (int): The maximum number of activity items to return.
action_type (Optional[str]): A specific type of activity to filter.
before (Optional[datetime]): Latest timestamp to include activities before.
after (Optional[datetime]): Earliest timestamp to include activities after.
cursor (Optional[datetime]): Timestamp for pagination cursor.
Returns:
ActivityCollection: A collection of user activities filtered
according to specified criteria.
"""
metrics.track(metrics.SDK, self.account, {"name": "Other User Activity"})
return super().activity(user_id, limit, action_type, before, after, cursor)
9 changes: 0 additions & 9 deletions src/specklepy/api/resources/deprecated/active_user.py

This file was deleted.

Loading

0 comments on commit d1b6755

Please sign in to comment.