Skip to content

Commit

Permalink
Support the subscription
Browse files Browse the repository at this point in the history
Closes #1
  • Loading branch information
mnogu committed Jun 3, 2023
1 parent f911099 commit 0810035
Show file tree
Hide file tree
Showing 31 changed files with 281 additions and 86 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ For example, you can use `get_timeline()` in `BskyAgent` to get the timeline as
```
$ git clone https://github.com/mnogu/chitose.git
$ cd chitose
$ python3 -m pip install -r requirements.txt
$ python3
>>> from chitose import BskyAgent
>>> agent = BskyAgent(service='https://bsky.social')
Expand All @@ -28,6 +29,7 @@ Alternatively, you can use `app.bsky.feed.get_timeline()` as in [the advanced AP
```
$ git clone https://github.com/mnogu/chitose.git
$ cd chitose
$ python3 -m pip install -r requirements.txt
$ python3
>>> from chitose import BskyAgent
>>> agent = BskyAgent(service='https://bsky.social')
Expand Down Expand Up @@ -68,6 +70,7 @@ Alternatively, you can build a Python package and install it:
```
$ git clone https://github.com/mnogu/chitose.git
$ cd chitose
$ python3 -m pip install -r requirements.txt
$ python3 -m pip install --upgrade build
$ python3 -m build
$ python3 -m pip install dist/chitose-*-py3-none-any.whl
Expand All @@ -94,7 +97,7 @@ $ git add chitose
$ git commit
```
```
$ python3 -m pip install sphinx
$ python3 -m pip install -r docs/source/requirements.txt
$ cd docs
$ sphinx-apidoc -o ./source ../chitose -f
```
13 changes: 11 additions & 2 deletions chitose/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
from .app import App_
from .com import Com_
from .xrpc import call
from .xrpc import subscribe
from .xrpc import XrpcParams
from .xrpc import XrpcData
from .xrpc import XrpcHandler
from .xrpc import XrpcHeaders


Expand Down Expand Up @@ -66,13 +68,20 @@ def _call(self, method: str, params: XrpcParams,
return call(method, params, d, self.service,
self._add_auth_header(headers))

def _subscribe(self, method: str, params: XrpcParams,
handler: XrpcHandler) -> None:
# https -> wss
scheme = urllib.parse.urlparse(self.service).scheme
service = self.service.replace(scheme, 'wss', 1)
subscribe(method, params, service, handler)

@property
def app(self):
return App_(self._call)
return App_(self._call, self._subscribe)

@property
def com(self):
return Com_(self._call)
return Com_(self._call, self._subscribe)

def get_timeline(self, **kwargs: dict[str, typing.Any]) -> bytes:
"""See :doc:`chitose.app.bsky.feed` for available arguments."""
Expand Down
6 changes: 4 additions & 2 deletions chitose/app/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# GENERATED CODE - DO NOT MODIFY
from __future__ import annotations
from chitose.xrpc import XrpcCallable
from chitose.xrpc import XrpcSubscribe
from .bsky import Bsky_

class App_:
"""We recommend calling methods in this class via the :doc:`chitose.BskyAgent <chitose>` class instead of creating instances of this class directly."""

def __init__(self, call: XrpcCallable) -> None:
def __init__(self, call: XrpcCallable, subscribe: XrpcSubscribe) -> None:
self.call = call
self.subscribe = subscribe

@property
def bsky(self):
return Bsky_(self.call)
return Bsky_(self.call, self.subscribe)
18 changes: 10 additions & 8 deletions chitose/app/bsky/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# GENERATED CODE - DO NOT MODIFY
from __future__ import annotations
from chitose.xrpc import XrpcCallable
from chitose.xrpc import XrpcSubscribe
from .actor import Actor_
from .embed import Embed_
from .feed import Feed_
Expand All @@ -12,33 +13,34 @@
class Bsky_:
"""We recommend calling methods in this class via the :doc:`chitose.BskyAgent <chitose>` class instead of creating instances of this class directly."""

def __init__(self, call: XrpcCallable) -> None:
def __init__(self, call: XrpcCallable, subscribe: XrpcSubscribe) -> None:
self.call = call
self.subscribe = subscribe

@property
def actor(self):
return Actor_(self.call)
return Actor_(self.call, self.subscribe)

@property
def embed(self):
return Embed_(self.call)
return Embed_(self.call, self.subscribe)

@property
def feed(self):
return Feed_(self.call)
return Feed_(self.call, self.subscribe)

@property
def graph(self):
return Graph_(self.call)
return Graph_(self.call, self.subscribe)

@property
def notification(self):
return Notification_(self.call)
return Notification_(self.call, self.subscribe)

@property
def richtext(self):
return Richtext_(self.call)
return Richtext_(self.call, self.subscribe)

@property
def unspecced(self):
return Unspecced_(self.call)
return Unspecced_(self.call, self.subscribe)
4 changes: 3 additions & 1 deletion chitose/app/bsky/actor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# GENERATED CODE - DO NOT MODIFY
from __future__ import annotations
from chitose.xrpc import XrpcCallable
from chitose.xrpc import XrpcSubscribe
from .get_preferences import _get_preferences
from .get_profile import _get_profile
from .get_profiles import _get_profiles
Expand All @@ -14,8 +15,9 @@
class Actor_:
"""We recommend calling methods in this class via the :doc:`chitose.BskyAgent <chitose>` class instead of creating instances of this class directly."""

def __init__(self, call: XrpcCallable) -> None:
def __init__(self, call: XrpcCallable, subscribe: XrpcSubscribe) -> None:
self.call = call
self.subscribe = subscribe

def search_actors_typeahead(self, term: typing.Optional[str]=None, limit: typing.Optional[int]=None) -> bytes:
"""Find actor suggestions for a search term."""
Expand Down
6 changes: 4 additions & 2 deletions chitose/app/bsky/embed/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# GENERATED CODE - DO NOT MODIFY
from __future__ import annotations
from chitose.xrpc import XrpcCallable
from chitose.xrpc import XrpcSubscribe

class Embed_:
"""We recommend calling methods in this class via the :doc:`chitose.BskyAgent <chitose>` class instead of creating instances of this class directly."""

def __init__(self, call: XrpcCallable) -> None:
self.call = call
def __init__(self, call: XrpcCallable, subscribe: XrpcSubscribe) -> None:
self.call = call
self.subscribe = subscribe
4 changes: 3 additions & 1 deletion chitose/app/bsky/feed/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# GENERATED CODE - DO NOT MODIFY
from __future__ import annotations
from chitose.xrpc import XrpcCallable
from chitose.xrpc import XrpcSubscribe
from .describe_feed_generator import _describe_feed_generator
from .get_actor_feeds import _get_actor_feeds
from .get_author_feed import _get_author_feed
Expand All @@ -19,8 +20,9 @@
class Feed_:
"""We recommend calling methods in this class via the :doc:`chitose.BskyAgent <chitose>` class instead of creating instances of this class directly."""

def __init__(self, call: XrpcCallable) -> None:
def __init__(self, call: XrpcCallable, subscribe: XrpcSubscribe) -> None:
self.call = call
self.subscribe = subscribe

def get_feed_generators(self, feeds: list[str]) -> bytes:
"""Get information about a list of feed generators"""
Expand Down
4 changes: 3 additions & 1 deletion chitose/app/bsky/graph/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# GENERATED CODE - DO NOT MODIFY
from __future__ import annotations
from chitose.xrpc import XrpcCallable
from chitose.xrpc import XrpcSubscribe
from .get_blocks import _get_blocks
from .get_followers import _get_followers
from .get_follows import _get_follows
Expand All @@ -17,8 +18,9 @@
class Graph_:
"""We recommend calling methods in this class via the :doc:`chitose.BskyAgent <chitose>` class instead of creating instances of this class directly."""

def __init__(self, call: XrpcCallable) -> None:
def __init__(self, call: XrpcCallable, subscribe: XrpcSubscribe) -> None:
self.call = call
self.subscribe = subscribe

def unmute_actor_list(self, list: str) -> bytes:
"""Unmute a list of actors."""
Expand Down
4 changes: 3 additions & 1 deletion chitose/app/bsky/notification/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# GENERATED CODE - DO NOT MODIFY
from __future__ import annotations
from chitose.xrpc import XrpcCallable
from chitose.xrpc import XrpcSubscribe
from .get_unread_count import _get_unread_count
from .list_notifications import _list_notifications
from .update_seen import _update_seen
Expand All @@ -11,8 +12,9 @@
class Notification_:
"""We recommend calling methods in this class via the :doc:`chitose.BskyAgent <chitose>` class instead of creating instances of this class directly."""

def __init__(self, call: XrpcCallable) -> None:
def __init__(self, call: XrpcCallable, subscribe: XrpcSubscribe) -> None:
self.call = call
self.subscribe = subscribe

def update_seen(self, seen_at: str) -> bytes:
"""Notify server that the user has seen notifications."""
Expand Down
6 changes: 4 additions & 2 deletions chitose/app/bsky/richtext/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# GENERATED CODE - DO NOT MODIFY
from __future__ import annotations
from chitose.xrpc import XrpcCallable
from chitose.xrpc import XrpcSubscribe

class Richtext_:
"""We recommend calling methods in this class via the :doc:`chitose.BskyAgent <chitose>` class instead of creating instances of this class directly."""

def __init__(self, call: XrpcCallable) -> None:
self.call = call
def __init__(self, call: XrpcCallable, subscribe: XrpcSubscribe) -> None:
self.call = call
self.subscribe = subscribe
4 changes: 3 additions & 1 deletion chitose/app/bsky/unspecced/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# GENERATED CODE - DO NOT MODIFY
from __future__ import annotations
from chitose.xrpc import XrpcCallable
from chitose.xrpc import XrpcSubscribe
from .get_popular import _get_popular
from .get_popular_feed_generators import _get_popular_feed_generators
import typing

class Unspecced_:
"""We recommend calling methods in this class via the :doc:`chitose.BskyAgent <chitose>` class instead of creating instances of this class directly."""

def __init__(self, call: XrpcCallable) -> None:
def __init__(self, call: XrpcCallable, subscribe: XrpcSubscribe) -> None:
self.call = call
self.subscribe = subscribe

def get_popular(self, include_nsfw: typing.Optional[bool]=None, limit: typing.Optional[int]=None, cursor: typing.Optional[str]=None) -> bytes:
"""An unspecced view of globally popular items"""
Expand Down
6 changes: 4 additions & 2 deletions chitose/com/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# GENERATED CODE - DO NOT MODIFY
from __future__ import annotations
from chitose.xrpc import XrpcCallable
from chitose.xrpc import XrpcSubscribe
from .atproto import Atproto_

class Com_:
"""We recommend calling methods in this class via the :doc:`chitose.BskyAgent <chitose>` class instead of creating instances of this class directly."""

def __init__(self, call: XrpcCallable) -> None:
def __init__(self, call: XrpcCallable, subscribe: XrpcSubscribe) -> None:
self.call = call
self.subscribe = subscribe

@property
def atproto(self):
return Atproto_(self.call)
return Atproto_(self.call, self.subscribe)
18 changes: 10 additions & 8 deletions chitose/com/atproto/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# GENERATED CODE - DO NOT MODIFY
from __future__ import annotations
from chitose.xrpc import XrpcCallable
from chitose.xrpc import XrpcSubscribe
from .admin import Admin_
from .identity import Identity_
from .label import Label_
Expand All @@ -12,33 +13,34 @@
class Atproto_:
"""We recommend calling methods in this class via the :doc:`chitose.BskyAgent <chitose>` class instead of creating instances of this class directly."""

def __init__(self, call: XrpcCallable) -> None:
def __init__(self, call: XrpcCallable, subscribe: XrpcSubscribe) -> None:
self.call = call
self.subscribe = subscribe

@property
def admin(self):
return Admin_(self.call)
return Admin_(self.call, self.subscribe)

@property
def identity(self):
return Identity_(self.call)
return Identity_(self.call, self.subscribe)

@property
def label(self):
return Label_(self.call)
return Label_(self.call, self.subscribe)

@property
def moderation(self):
return Moderation_(self.call)
return Moderation_(self.call, self.subscribe)

@property
def repo(self):
return Repo_(self.call)
return Repo_(self.call, self.subscribe)

@property
def server(self):
return Server_(self.call)
return Server_(self.call, self.subscribe)

@property
def sync(self):
return Sync_(self.call)
return Sync_(self.call, self.subscribe)
4 changes: 3 additions & 1 deletion chitose/com/atproto/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# GENERATED CODE - DO NOT MODIFY
from __future__ import annotations
from chitose.xrpc import XrpcCallable
from chitose.xrpc import XrpcSubscribe
from .disable_account_invites import _disable_account_invites
from .disable_invite_codes import _disable_invite_codes
from .enable_account_invites import _enable_account_invites
Expand All @@ -24,8 +25,9 @@
class Admin_:
"""We recommend calling methods in this class via the :doc:`chitose.BskyAgent <chitose>` class instead of creating instances of this class directly."""

def __init__(self, call: XrpcCallable) -> None:
def __init__(self, call: XrpcCallable, subscribe: XrpcSubscribe) -> None:
self.call = call
self.subscribe = subscribe

def get_repo(self, did: str) -> bytes:
"""View details about a repository."""
Expand Down
4 changes: 3 additions & 1 deletion chitose/com/atproto/identity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# GENERATED CODE - DO NOT MODIFY
from __future__ import annotations
from chitose.xrpc import XrpcCallable
from chitose.xrpc import XrpcSubscribe
from .resolve_handle import _resolve_handle
from .update_handle import _update_handle

class Identity_:
"""We recommend calling methods in this class via the :doc:`chitose.BskyAgent <chitose>` class instead of creating instances of this class directly."""

def __init__(self, call: XrpcCallable) -> None:
def __init__(self, call: XrpcCallable, subscribe: XrpcSubscribe) -> None:
self.call = call
self.subscribe = subscribe

def update_handle(self, handle: str) -> bytes:
"""Updates the handle of the account"""
Expand Down
Loading

0 comments on commit 0810035

Please sign in to comment.