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
126 changes: 26 additions & 100 deletions docs/api/client.md
Original file line number Diff line number Diff line change
@@ -1,108 +1,34 @@
# Client Reference

## MCSRRanked

The synchronous client for the MCSR Ranked API.

```python
from mcsrranked import MCSRRanked

client = MCSRRanked(
api_key=None, # API key for expanded rate limits
private_key=None, # Private key for live data
base_url=None, # Custom API base URL
timeout=30.0, # Request timeout in seconds
max_retries=2, # Maximum retry attempts
)
```

### Constructor Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `api_key` | `str \| None` | `None` | API key for expanded rate limits. Falls back to `MCSRRANKED_API_KEY` env var. |
| `private_key` | `str \| None` | `None` | Private key for live data. Falls back to `MCSRRANKED_PRIVATE_KEY` env var. |
| `base_url` | `str \| None` | `"https://api.mcsrranked.com"` | API base URL. |
| `timeout` | `float \| None` | `30.0` | Request timeout in seconds. |
| `max_retries` | `int \| None` | `2` | Maximum number of retries. |

### Resources

| Resource | Description |
|----------|-------------|
| `client.users` | User profiles, matches, versus stats |
| `client.matches` | Match listings and details |
| `client.leaderboards` | Elo, phase, and record leaderboards |
| `client.live` | Online players and live streams |
| `client.weekly_races` | Weekly race data |

### Methods

#### `with_options(**kwargs)`

Create a new client with modified options:

```python
new_client = client.with_options(timeout=60.0)
```

#### `close()`

Close the HTTP client:

```python
client.close()
```

### Context Manager

```python
with MCSRRanked() as client:
user = client.users.get("Feinberg")
# Client automatically closed
```
## Synchronous Client

::: mcsrranked.MCSRRanked
options:
members:
- __init__
- users
- matches
- leaderboards
- live
- weekly_races
- with_options
- close

---

## AsyncMCSRRanked

The asynchronous client for the MCSR Ranked API.

```python
from mcsrranked import AsyncMCSRRanked

client = AsyncMCSRRanked(
api_key=None,
private_key=None,
base_url=None,
timeout=30.0,
max_retries=2,
)
```

### Async Context Manager

```python
async with AsyncMCSRRanked() as client:
user = await client.users.get("Feinberg")
# Client automatically closed
```

### Async Methods

All resource methods are async:

```python
user = await client.users.get("Feinberg")
matches = await client.matches.list()
leaderboard = await client.leaderboards.elo()
```

### Async Close

```python
await client.close()
```
## Asynchronous Client

::: mcsrranked.AsyncMCSRRanked
options:
members:
- __init__
- users
- matches
- leaderboards
- live
- weekly_races
- with_options
- close

---

Expand Down
146 changes: 39 additions & 107 deletions docs/api/exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,151 +10,83 @@ MCSRRankedError
│ │ ├── AuthenticationError
│ │ ├── NotFoundError
│ │ └── RateLimitError
── APIConnectionError
│ └── APITimeoutError
── APIConnectionError
└── APITimeoutError
```

---

## Base Exceptions

### MCSRRankedError
::: mcsrranked.MCSRRankedError
options:
show_docstring_attributes: true

Base exception for all SDK errors.

```python
from mcsrranked import MCSRRankedError

try:
user = mcsrranked.users.get("someone")
except MCSRRankedError as e:
print(f"SDK error: {e}")
```

### APIError

Base exception for API-related errors.

| Attribute | Type | Description |
|-----------|------|-------------|
| `message` | `str` | Error message |
::: mcsrranked.APIError
options:
show_docstring_attributes: true

---

## HTTP Status Exceptions

### APIStatusError

Exception for HTTP error responses.
::: mcsrranked.APIStatusError
options:
show_docstring_attributes: true

| Attribute | Type | Description |
|-----------|------|-------------|
| `message` | `str` | Error message |
| `status_code` | `int` | HTTP status code |
| `response` | `httpx.Response` | Raw response object |
| `body` | `object \| None` | Response body |
::: mcsrranked.BadRequestError

### BadRequestError
::: mcsrranked.AuthenticationError

Raised for HTTP 400 responses (invalid parameters).
::: mcsrranked.NotFoundError

```python
from mcsrranked import BadRequestError
::: mcsrranked.RateLimitError

try:
matches = mcsrranked.matches.list(count=1000)
except BadRequestError as e:
print(f"Status: {e.status_code}") # 400
print(f"Message: {e.message}")
```
---

### AuthenticationError
## Connection Exceptions

Raised for HTTP 401 responses (invalid credentials).
::: mcsrranked.APIConnectionError

```python
from mcsrranked import AuthenticationError
::: mcsrranked.APITimeoutError

try:
live = mcsrranked.users.live("uuid")
except AuthenticationError as e:
print(f"Status: {e.status_code}") # 401
```
---

### NotFoundError
## Usage Examples

Raised for HTTP 404 responses (resource not found).
### Catching all SDK errors

```python
from mcsrranked import NotFoundError
from mcsrranked import MCSRRankedError

try:
user = mcsrranked.users.get("nonexistent")
except NotFoundError as e:
print(f"Status: {e.status_code}") # 404
user = mcsrranked.users.get("someone")
except MCSRRankedError as e:
print(f"SDK error: {e}")
```

### RateLimitError

Raised for HTTP 429 responses (too many requests).
### Catching specific errors

```python
from mcsrranked import RateLimitError
from mcsrranked import NotFoundError, RateLimitError

try:
# Too many requests
for i in range(1000):
mcsrranked.users.get("Feinberg")
user = mcsrranked.users.get("nonexistent")
except NotFoundError as e:
print(f"User not found: {e.status_code}")
except RateLimitError as e:
print(f"Status: {e.status_code}") # 429
```

---

## Connection Exceptions

### APIConnectionError

Raised for network-related errors.

```python
from mcsrranked import APIConnectionError

try:
user = mcsrranked.users.get("Feinberg")
except APIConnectionError as e:
print(f"Connection failed: {e.message}")
print(f"Rate limited: {e.status_code}")
```

### APITimeoutError

Raised when a request times out. Inherits from `APIConnectionError`.
### Accessing error details

```python
from mcsrranked import APITimeoutError, MCSRRanked

client = MCSRRanked(timeout=1.0)
from mcsrranked import APIStatusError

try:
user = client.users.get("Feinberg")
except APITimeoutError as e:
print(f"Request timed out: {e.message}")
```

---

## Import All Exceptions

```python
from mcsrranked import (
MCSRRankedError,
APIError,
APIStatusError,
APIConnectionError,
APITimeoutError,
BadRequestError,
AuthenticationError,
NotFoundError,
RateLimitError,
)
user = mcsrranked.users.get("invalid")
except APIStatusError as e:
print(f"Status: {e.status_code}")
print(f"Message: {e.message}")
print(f"Body: {e.body}")
```
Loading