Skip to content
Merged
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
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: ci

on:
push:
branches: [master]
pull_request:
workflow_call:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.13'
- run: python -m pip install -e '.[dev]'
- run: ruff check .
- run: ruff format --check .
- run: mypy

test:
name: test (python ${{ matrix.python }})
# setup-python has no 3.9 build for the newest ubuntu-latest image; 22.04 still ships it.
runs-on: ${{ matrix.python == '3.9' && 'ubuntu-22.04' || 'ubuntu-latest' }}
strategy:
fail-fast: false
matrix:
python: ['3.9', '3.10', '3.11', '3.12', '3.13']
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
# mypy (used by the docs-examples test) is installed where it supports the runtime; elsewhere that test skips.
- run: python -m pip install -e . pytest
- if: matrix.python != '3.9'
run: python -m pip install mypy
- run: python -m pytest

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.13'
- run: python -m pip install build twine
- run: python -m build
- run: python -m twine check --strict dist/*
50 changes: 50 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: docs

permissions:
contents: write

on:
push:
branches: [master]
paths:
- 'docs/**'
- 'CHANGELOG.md'
- '.github/workflows/docs.yml'
release:
types: [published]
workflow_dispatch:

jobs:
docs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: docs

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
# @nuxt/content uses node:sqlite (Node >= 22.5)
node-version: 22
cache: npm
cache-dependency-path: docs/package-lock.json

- run: npm ci

- name: Build docs (Nuxt generate)
env:
NUXT_APP_BASE_URL: /onlinesim-python-api/
run: npm run build

- name: Add nojekyll
run: '> .output/public/.nojekyll'

- name: Deploy to GitHub Pages
uses: crazy-max/ghaction-github-pages@v4
with:
target_branch: gh-pages
build_dir: docs/.output/public
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49 changes: 22 additions & 27 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,37 @@ name: Publish to PyPI
on:
push:
tags:
- 'v*' # Запускается при создании тега v*
- 'v*'

jobs:
ci:
uses: ./.github/workflows/ci.yml

publish:
needs: ci
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/onlinesimru

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- uses: actions/setup-python@v5
with:
python-version: '3.13'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Check the tag matches the package version
run: |
version=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml','rb'))['project']['version'])")
test "v${version}" = "${GITHUB_REF_NAME}" || { echo "tag ${GITHUB_REF_NAME} != v${version}"; exit 1; }

- name: Build package
run: |
python -m build --wheel --sdist
- name: Build package
run: |
python -m pip install build
python -m build

- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true

- name: Create Release
uses: softprops/action-gh-release@v1
with:
files: dist/*
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
25 changes: 18 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
.DS_Store
__pycache__
.idea
__pycache__/
*.pyc
.idea/
.vscode/
build/
dist/
*.pyc
*.egg-info/
.venv/
venv/
.pytest_cache/
.mypy_cache/
.ruff_cache/
.pypirc
*.egg-info
/venv
dosc.md
.egg
.env

# docs site (standalone package in docs/)
/docs/node_modules
/docs/.nuxt
/docs/.output
/docs/.data
/docs/dist
45 changes: 45 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,51 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.0.0]

A rewrite. The public API changed; see the [docs](https://s00d.github.io/onlinesim-python-api/).

### Removed
- The proxy API (`ProxyService`, `Driver.proxy()`, deprecated by the backend).
- `numbers.repeat` (getNumRepeat), `numbers.service` (getService), `numbers.service_number` (getServiceNumber): no backend route.
- `rent.port_reload`: deprecated no-op on the backend.
- `user.create_empty` (pay/createEmpty).
- The old free-number methods (getFreeCountryList / getFreePhoneList / getFreeMessageList): the backend returns empty data; use `free.list`.
- `Driver`, `API` and the per-service classes (`NumbersService`, `RentNumbersService`, `UserService`, `FreeNumbersService`), `RequestException`.
- Runtime dependencies `httpx`, `pydantic`, `dacite`; `requirements.txt`, `pytest.ini`, `deploy.sh`, `DEPLOYMENT.md`, `example/`, the live-API tests.

### Changed
- One client: `OnlineSim(api_key, *, base_url, lang, dev_id, timeout, transport)`; sections are attributes (`client.numbers`, `client.rent`, `client.user`, `client.free`).
- The API key is sent as `Authorization: Bearer <key>`, never in the query string. `base_url` is the full API base (`https://onlinesim.host/api/`).
- Errors: `OnlineSimError` → `ApiError` (`code`, `message`), `NoNumberError` (subclass of `ApiError`), `TransportError` (`status`, `body`), `TimeoutError` (also a built-in `TimeoutError`).
- `numbers.wait_code(tzid, *, interval, timeout, keep_open, full_message, since, sleep, clock)`, times in seconds.
- `numbers.get` / `get_with_number` take `reject=` as a keyword; `get_with_number` returns `{tzid, number, country, time, service}`.
- `numbers.state(*, message_to_code, order_by, msg_list)` / `state_one(tzid, ...)` take booleans; `order_by` is lowercase.
- `rent.get(country, days, extension)`: `extension` defaults to `True` (the server default; `False` makes the rent non-extendable for good).
- Results are plain dicts typed as `TypedDict`s; money parsed to numbers (`user.balance()["balance"]`, rent `sum`).
- Python ≥ 3.9, zero runtime dependencies (stdlib `urllib`), `py.typed`, hatchling build, `__version__` from the installed metadata.

### Fixed
- `lang` was also sent as `dev_id`; `dev_id` is sent only when set.
- `getService` was requested as `/apigetService`; old URL building is gone.
- `NO_NUMBER` / `NO_NUMBER_FOR_FORWARD` are mapped to `NoNumberError`; error messages come from the server or a fallback table.
- `response` is stripped from successful results.
- `getNum` was sent as POST; every call except the profile webhook update is a GET with query parameters.
- Booleans were sent as `true`/`false`; now `1`/`0`. `reject` is a comma list; unset parameters are omitted.
- `wait_code` polled with a broken counter; it now uses a deadline with an injectable clock.
- An HTTP 456 wrong-key answer is an `ApiError`; non-JSON answers and network errors raise `TransportError`.
- `state()` returns `[]` instead of raising when there are no operations.
- Empty maps sent by PHP as `[]` (rent `extend`, `paylist`, free `numbers`, country `services`) are returned as `{}`.
- Rent requests always send `pagination=0`, so `messages` is a flat list.
- `pytest.ini` used the `[tool:pytest]` header and was ignored; `.venv` was not git-ignored; `py.typed` was declared but missing.

### Added
- `user.set_webhook_url(url)`, `user.clear_webhook_url()`, `user.webhook_logs(page)`.
- `parse_webhook(payload)` for inbound `receiving_sms` / `rent_sms` webhooks.
- Injectable `transport` (`HttpRequest` → `HttpResponse`) and per-request `timeout`.
- Offline test suite (fake transport, fake clock), docs examples type-checked with mypy, opt-in integration test, CI on Python 3.9–3.13 with ruff and mypy.
- New documentation site (Nuxt Content).

## [2.1.0] - 2025-08-10
### Added
- API domain replacement capability through `base_url` parameter in `API` class constructor
Expand Down
Loading
Loading