8000 :herb: Fern Regeneration -- August 29, 2023 by fern-api[bot] · Pull Request #1 · codecombat/codecombat-python · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

🌿 Fern Regeneration -- August 2 8000 9, 2023 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: ci
on: [push]
jobs:
compile:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
steps:
- name: Checkout repo
uses: actions/checkout@v3
Expand All @@ -13,17 +13,32 @@ jobs:
python-version: 3.7
- name: Bootstrap poetry
run: |
curl -sSL https://install.python-poetry.org | python - -y
curl -sSL https://install.python-poetry.org | python - -y --version 1.5.1
- name: Install dependencies
run: poetry install
- name: Compile
run: poetry run mypy .
test:
runs-on: ubuntu-20.04
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Set up python
uses: actions/setup-python@v4
with:
python-version: 3.7
- name: Bootstrap poetry
run: |
curl -sSL https://install.python-poetry.org | python - -y --version 1.5.1
- name: Install dependencies
run: poetry install
- name: Test
run: poetry run pytest .

publish:
needs: [ compile ]
needs: [compile, test]
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
runs-on: ubuntu-latest

runs-on: ubuntu-20.04
steps:
- name: Checkout repo
uses: actions/checkout@v3
Expand All @@ -33,7 +48,7 @@ jobs:
python-version: 3.7
- name: Bootstrap poetry
run: |
curl -sSL https://install.python-poetry.org | python - -y
curl -sSL https://install.python-poetry.org | python - -y --version 1.5.1
- name: Install dependencies
run: poetry install
- name: Publish to pypi
Expand All @@ -42,4 +57,4 @@ jobs:
poetry --no-interaction -v publish --build --repository remote --username "$PYPI_USERNAME" --password "$PYPI_PASSWORD"
env:
PYPI_USERNAME: ${{ secrets.PYPI_USERNAME }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
9 changes: 4 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@

[tool.poetry]
name = "codecombat"
version = "0.0 9E7A .18"
version = "0.1.5"
description = ""
readme = "README.md"
authors = []
packages = [
{ include = "codecombat", from = "src"}
]

[tool.poetry.dependencies]
python = "^3.7"
httpx = ">=0.21.2"
pydantic = "^1.9.2"
httpx = "0.23.3"
types-backports = "0.1.3"
backports-cached_property = "1.0.2"

[tool.poetry.dev-dependencies]
mypy = "0.971"
pytest = "^7.4.0"

[build-system]
requires = ["poetry-core"]
Expand Down
62 changes: 29 additions & 33 deletions src/codecombat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,61 @@
# This file was auto-generated by Fern from our API Definition.

from .environment import CodeCombatEnvironment
from .resources import (
AceConfig,
AuthIdentity,
from .types import (
ClanResponse,
ClassroomResponse,
ClassroomResponseCoursesItem,
ClassroomResponseWithCode,
Course,
ClassroomResponseWithCodeCoursesItem,
ClassroomsCreateRequestAceConfig,
ClassroomsGetMembersStatsResponseItem,
ClassroomsGetMembersStatsResponseItemStats,
DatetimeString,
HeroConfig,
Level,
LevelSessionResponse,
License,
LevelSessionResponseLevel,
LevelSessionResponseState,
LicenseStatsResponse,
MemberStat,
ObjectIdString,
PlayStats,
PlaytimeStatsResponse,
RoleString,
State,
Subscription,
UserResponse,
UserRole,
UserStats,
auth,
clans,
classrooms,
commons,
stats,
users,
UserResponseLicense,
UserResponseOAuthIdentitiesItem,
UserResponseStats,
UserResponseSubscription,
UsersCreateRequestHeroConfig,
UsersCreateRequestRole,
)
from .resources import auth, clans, classrooms, stats, users
from .environment import CodeCombatEnvironment

__all__ = [
"AceConfig",
"AuthIdentity",
"ClanResponse",
"ClassroomResponse",
"ClassroomResponseCoursesItem",
"ClassroomResponseWithCode",
"ClassroomResponseWithCodeCoursesItem",
"ClassroomsCreateRequestAceConfig",
"ClassroomsGetMembersStatsResponseItem",
"ClassroomsGetMembersStatsResponseItemStats",
"CodeCombatEnvironment",
"Course",
"DatetimeString",
"HeroConfig",
"Level",
"LevelSessionResponse",
"License",
"LevelSessionResponseLevel",
"LevelSessionResponseState",
"LicenseStatsResponse",
"MemberStat",
"ObjectIdString",
"PlayStats",
"PlaytimeStatsResponse",
"RoleString",
"State",
"Subscription",
"UserResponse",
"UserRole",
"UserStats",
"UserResponseLicense",
"UserResponseOAuthIdentitiesItem",
"UserResponseStats",
"UserResponseSubscription",
"UsersCreateRequestHeroConfig",
"UsersCreateRequestRole",
"auth",
"clans",
"classrooms",
"commons",
"stats",
"users",
]
187 changes: 138 additions & 49 deletions src/codecombat/client.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,157 @@
# This file was auto-generated by Fern from our API Definition.

from backports.cached_property import cached_property
import typing
import urllib.parse
from json.decoder import JSONDecodeError

import httpx
import pydantic

from .core.api_error import ApiError
from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .core.jsonable_encoder import jsonable_encoder
from .environment import CodeCombatEnvironment
from .resources.auth.client import AsyncAuthClient, AuthClient
from .resources.clans.client import AsyncClansClient, ClansClient
from .resources.classrooms.client import AsyncClassroomsClient, ClassroomsClient
from .resources.stats.client import AsyncStatsClient, StatsClient
from .resources.users.client import AsyncUsersClient, UsersClient
from .types.user_response import UserResponse

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class CodeCombat:
def __init__(
self, *, environment: CodeCombatEnvironment = CodeCombatEnvironment.PRODUCTION, username: str, password: str
self,
*,
base_url: typing.Optional[str] = None,
environment: CodeCombatEnvironment = CodeCombatEnvironment.DEFAULT,
username: typing.Union[str, typing.Callable[[], str]],
password: typing.Union[str, typing.Callable[[], str]],
timeout: typing.Optional[float] = 60,
):
self._environment = environment
self._username = username
self._password = password

@cached_property
def auth(self) -> AuthClient:
return AuthClient(environment=self._environment, username=self._username, password=self._password)

@cached_property
def clans(self) -> ClansClient:
return ClansClient(environment=self._environment, username=self._username, password=self._password)

@cached_property
def classrooms(self) -> ClassroomsClient:
return ClassroomsClient(environment=self._environment, username=self._username, password=self._password)

@cached_property
def stats(self) -> StatsClient:
return StatsClient(environment=self._environment, username=self._username, password=self._password)

@cached_property
def users(self) -> UsersClient:
return UsersClient(environment=self._environment, username=self._username, password=self._password)
self._client_wrapper = SyncClientWrapper(
base_url=_get_base_url(base_url=base_url, environment=environment),
username=username,
password=password,
httpx_client=httpx.Client(timeout=timeout),
)
self.auth = AuthClient(client_wrapper=self._client_wrapper)
self.clans = ClansClient(client_wrapper=self._client_wrapper)
self.classrooms = ClassroomsClient(client_wrapper=self._client_wrapper)
self.stats = StatsClient(client_wrapper=self._client_wrapper)
self.users = UsersClient(client_wrapper=self._client_wrapper)

def post_users_handle_o_auth_identities(
self,
handle: str,
*,
provider: str,
access_token: typing.Optional[str] = OMIT,
code: typing.Optional[str] = OMIT,
) -> UserResponse:
"""
Adds an OAuth2 identity to the user, so that they can be logged in with that identity. You need to send the OAuth code or the access token to this endpoint. 1. If no access token is provided, it will use your OAuth2 token URL to exchange the given code for an access token. 2. Then it will use the access token (given by you, or received from step 1) to look up the user on your service using the lookup URL, and expects a JSON object in response with an `id` property. 3. It will then save that user `id` to the user in our db as a new OAuthIdentity. In this example, we call your lookup URL (let's say, `https://oauth.provider/user?t=<%= accessToken %>`) with the access token (`1234`). The lookup URL returns `{ id: 'abcd' }` in this case, which we save to the user in our db.

Parameters:
- handle: str. The document's `_id` or `slug`.

- provider: str. Your OAuth Provider ID.

- access_token: typing.Optional[str]. Will be passed through your lookup URL to get the user ID. Required if no `code`.

- code: typing.Optional[str]. Will be passed to the OAuth token endpoint to get a token. Required if no `accessToken`.
"""
_request: typing.Dict[str, typing.Any] = {"provider": provider}
if access_token is not OMIT:
_request["accessToken"] = access_token
if code is not OMIT:
_request["code"] = code
_response = self._client_wrapper.httpx_client.request(
"POST",
urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"users/{handle}/o-auth-identities"),
json=jsonable_encoder(_request),
headers=self._client_wrapper.get_headers(),
timeout=60,
)
if 200 <= _response.status_code < 300:
return pydantic.parse_obj_as(UserResponse, _response.json()) # type: ignore
try:
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)


class AsyncCodeCombat:
def __init__(
self, *, environment: CodeCombatEnvironment = CodeCombatEnvironment.PRODUCTION, username: str, password: str
self,
*,
base_url: typing.Optional[str] = None,
environment: CodeCombatEnvironment = CodeCombatEnvironment.DEFAULT,
username: typing.Union[str, typing.Callable[[], str]],
password: typing.Union[str, typing.Callable[[], str]],
timeout: typing.Optional[float] = 60,
):
self._environment = environment
self._username = username
self._password = password

@cached_property
def auth(self) -> AsyncAuthClient:
return AsyncAuthClient(environment=self._environment, username=self._username, password=self._password)

@cached_property
def clans(self) -> AsyncClansClient:
return AsyncClansClient(environment=self._environment, username=self._username, password=self._password)

@cached_property
def classrooms(self) -> AsyncClassroomsClient:
return AsyncClassroomsClient(environment=self._environment, username=self._username, password=self._password)

@cached_property
def stats(self) -> AsyncStatsClient:
return AsyncStatsClient(environment=self._environment, username=self._username, password=self._password)

@cached_property
def users(self) -> AsyncUsersClient:
return AsyncUsersClient(environment=self._environment, username=self._username, password=self._password)
self._client_wrapper = AsyncClientWrapper(
base_url=_get_base_url(base_url=base_url, environment=environment),
username=username,
password=password,
httpx_client=httpx.AsyncClient(timeout=timeout),
)
self.auth = AsyncAuthClient(client_wrapper=self._client_wrapper)
self.clans = AsyncClansClient(client_wrapper=self._client_wrapper)
self.classrooms = AsyncClassroomsClient(client_wrapper=self._client_wrapper)
self.stats = AsyncStatsClient(client_wrapper=self._client_wrapper)
self.users = AsyncUsersClient(client_wrapper=self._client_wrapper)

async def post_users_handle_o_auth_identities(
self,
handle: str,
*,
provider: str,
access_token: typing.Optional[str] = OMIT,
code: typing.Optional[str] = OMIT,
) -> UserResponse:
"""
Adds an OAuth2 identity to the user, so that they can be logged in with that identity. You need to send the OAuth code or the access token to this endpoint. 1. If no access token is provided, it will use your OAuth2 token URL to exchange the given code for an access token. 2. Then it will use the access token (given by you, or received from step 1) to look up the user on your service using the lookup URL, and expects a JSON object in response with an `id` property. 3. It will then save that user `id` to the user in our db as a new OAuthIdentity. In this example, we call your lookup URL (let's say, `https://oauth.provider/user?t=<%= accessToken %>`) with the access token (`1234`). The lookup URL returns `{ id: 'abcd' }` in this case, which we save to the user in our db.

Parameters:
- handle: str. The document's `_id` or `slug`.

- provider: str. Your OAuth Provider ID.

- access_token: typing.Optional[str]. Will be passed through your lookup URL to get the user ID. Required if no `code`.

- code: typing.Optional[str]. Will be passed to the OAuth token endpoint to get a token. Required if no `accessToken`.
"""
_request: typing.Dict[str, typing.Any] = {"provider": provider}
if access_token is not OMIT:
_request["accessToken"] = access_token
if code is not OMIT:
_request["code"] = code
_response = await self._client_wrapper.httpx_client.request(
"POST",
urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"users/{handle}/o-auth-identities"),
json=jsonable_encoder(_request),
headers=self._client_wrapper.get_headers(),
timeout=60,
)
if 200 <= _response.status_code < 300:
return pydantic.parse_obj_as(UserResponse, _response.json()) # type: ignore
try:
_response_json = _response.json()
except JSONDecodeError:
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)


def _get_base_url(*, base_url: typing.Optional[str] = None, environment: CodeCombatEnvironment) -> str:
if base_url is not None:
return base_url
elif environment is not None:
return environment.value
else:
raise Exception("Please pass in either base_url or environment to construct the client")
Loading
0