mirror of
https://github.com/aljazceru/python-nostr.git
synced 2025-12-19 15:24:19 +01:00
add json conversion methods to classes
This commit is contained in:
@@ -12,6 +12,12 @@ class RelayPolicy:
|
||||
self.should_read = should_read
|
||||
self.should_write = should_write
|
||||
|
||||
def to_json_object(self) -> dict[str, bool]:
|
||||
return {
|
||||
"read": self.should_read,
|
||||
"write": self.should_write
|
||||
}
|
||||
|
||||
class Relay:
|
||||
def __init__(
|
||||
self,
|
||||
@@ -61,6 +67,13 @@ class Relay:
|
||||
|
||||
return None
|
||||
|
||||
def to_json_object(self) -> dict:
|
||||
return {
|
||||
"url": self.url,
|
||||
"policy": self.policy.to_json_object(),
|
||||
"subscriptions": [subscription.to_json_object() for subscription in self.subscriptions.values()]
|
||||
}
|
||||
|
||||
def _is_valid_message(self, message: str) -> bool:
|
||||
if not message or message[0] != '[' or message[-1] != ']':
|
||||
return False
|
||||
|
||||
@@ -4,3 +4,9 @@ class Subscription:
|
||||
def __init__(self, id: str, filters: Filters=None) -> None:
|
||||
self.id = id
|
||||
self.filters = filters
|
||||
|
||||
def to_json_object(self):
|
||||
return {
|
||||
"id": self.id,
|
||||
"filters": self.filters.to_json_array()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user