Skip to content

Commit

Permalink
Update version
Browse files Browse the repository at this point in the history
  • Loading branch information
7vlad7 committed Jan 1, 2024
1 parent 9174571 commit 85571cd
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ __pycache__/

.venv/
.mypy_cache
dev.py
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
project = 'python-outline'
copyright = '2024, Vladislav Fedin'
author = 'Vladislav Fedin'
release = '1.0.0'
release = '1.0.1'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
4 changes: 1 addition & 3 deletions examples/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

client = OutlineClient(base_url="https://localhost:777/secretpath")

new_key = client.new()

new_key.rename("This is a new name")
new_key = client.new(name="New key!")

# set a data limit of 1GB
new_key.change_data_limit(1000000000)
Expand Down
41 changes: 41 additions & 0 deletions outline/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,30 @@ def __init__(self, data: dict):
self.__dict__ = data


class DataTransfered(BaseMeta):
"""
Base class for Outline data transfered
"""
bytesTransferredByUserId: dict[str, int] = {}

@property
def total(self) -> int:
"""
Returns the total data transfered
"""
return sum(self.bytesTransferredByUserId.values())

def by_key(self, access_key: str | int | OutlineAccessKey) -> int:
"""
Returns the data transfered by the given access key
"""

if isinstance(access_key, OutlineAccessKey):
access_key = access_key.id

return self.bytesTransferredByUserId.get(str(access_key), 0)


class OutlineAccessKey(BaseMeta):
"""
Base class for Outline access keys
Expand Down Expand Up @@ -88,6 +112,13 @@ def rename(self, name: str):
self.client.rename_key(self, name)
self.name = name

@property
def metrics(self) -> int:
"""
Returns the data transfered by the access key
"""
return self.client.metrics.by_key(self)


@dataclass
class OutlineClientInfo:
Expand Down Expand Up @@ -321,3 +352,13 @@ def new(self, method: str = "aes-192-gcm", name: str = ""):
key.rename(name)

return key

@property
def metrics(self) -> DataTransfered:
"""
Returns the data transfered
"""

r = self.request.get("/metrics/transfer")
r.raise_for_status()
return DataTransfered(r.json())
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ build-backend = "setuptools.build_meta"

[project]
name = "python-outline"
description = "Simple and easy to use wrapper for the Outline API."
requires-python = ">= 3.7"
version = "1.0.0"
version = "1.0.1"
authors = [{name = "Vladislav Fedin", email = "[email protected]"}]
readme = {file = "README.rst", content-type = "text/x-rst"}
license = {file = "LICENSE"}
Expand Down

0 comments on commit 85571cd

Please sign in to comment.