Skip to content

Commit 9adf843

Browse files
Merge pull request #177 from lumapps/MP-824/get-article
feat(get-article): add generated api and models
2 parents f20a055 + 0b0eccb commit 9adf843

File tree

117 files changed

+18827
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+18827
-3
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ PYTHON ?= python3.7
88
PIP = .venv/bin/pip
99
POETRY ?= .venv/bin/poetry
1010

11+
pytest_args?=-xv
12+
1113
check: check-docs check-code-quality check-types ## Check it all!
1214

1315
check-code-quality: ## Check the code quality.
14-
@$(POETRY) run failprint -t "Checking code quality" -- flake8 --config=config/flake8.ini $(PY_SRC)
16+
@$(POETRY) run failprint -t "Checking code quality" -- flake8 --config config/flake8.ini $(PY_SRC)
1517

1618
check-docs: ## Check if the documentation builds correctly.
1719
@$(POETRY) run failprint -t "Building documentation" -- mkdocs build -s
@@ -58,7 +60,7 @@ setup: .venv ## Setup the development environment (install dependencies).
5860
$(POETRY) run pre-commit install --hook-type commit-msg
5961

6062
test: ## Run the test suite and report coverage. 2>/dev/null
61-
@$(POETRY) run pytest -c config/pytest.ini
63+
@$(POETRY) run pytest ${pytest_args} -c config/pytest.ini
6264
@$(POETRY) run coverage html --rcfile=config/coverage.ini
6365

6466
.venv: ## Install the virtual env directory

config/coverage.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ source =
1111
parallel = true
1212
omit =
1313
lumapps/api/authlib_helpers.py
14+
lumapps/latest/api/swagger/**
1415
**/__init__.py
1516
examples/**
1617
tests/*

config/flake8.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[flake8]
22
max-line-length = 88
3+
exclude = swagger
34
ignore =
45
W291 ;trailing whitespace
56
W293 ;blank line contains whitespace
@@ -11,4 +12,4 @@ ignore =
1112
ban-relative-imports = true
1213
docstring-convention = google
1314
max-complexity = 18
14-
select = B,C,E,F,W,T4,B901
15+
select = B,C,E,F,W,T4,B901

config/mypy.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ ignore_missing_imports = true
33

44
[mypy-lumapps.api.client]
55
ignore_errors = true
6+
7+
[mypy-lumapps.latest.api.swagger.*]
8+
ignore_errors = true

lumapps/latest/api/__init__.py

Whitespace-only changes.

lumapps/latest/api/article.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from lumapps.latest.client import IClient
2+
from lumapps.latest.entities.article import Article
3+
4+
from .swagger.contribution_v1 import ContributionV1GW
5+
6+
7+
class ArticleApi:
8+
9+
def __init__(self, client: IClient) -> None:
10+
self.gateway = ContributionV1GW(client)
11+
12+
def get_article(self, article_id: str) -> Article:
13+
model = self.gateway.get_article(article_id)
14+
return Article(
15+
model.id,
16+
model.author.user_id,
17+
model.created_at,
18+
model.structured_content.title.translations,
19+
model.structured_content.intro.translations,
20+
)

lumapps/latest/api/exceptions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class ApiException(Exception):
2+
pass

lumapps/latest/api/swagger/__init__.py

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .gateway import ContributionV1GW
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from lumapps.latest.client import IClient, Request
2+
3+
from lumapps.latest.api.exceptions import ApiException
4+
5+
from . import models
6+
from ..serialization import Serialization
7+
8+
class ContributionV1GW(object):
9+
10+
def __init__(self, client: IClient) -> None:
11+
self.client = client
12+
13+
def get_article(self, article_id: str) -> models.Article:
14+
request = Request(
15+
method="GET",
16+
url=f"/articles/{article_id}",
17+
)
18+
response = self.client.request(request)
19+
if response.status_code == 200:
20+
return Serialization(models).deserialize(response.json, models.Article)
21+
else:
22+
raise ApiException(
23+
Serialization(models).deserialize(
24+
response.json["errors"][0],
25+
models.Error
26+
).detail,
27+
)

0 commit comments

Comments
 (0)