Skip to content

Commit

Permalink
Merge pull request #29 from admon84/dev
Browse files Browse the repository at this point in the history
feat: adding new api methods and prefix parameter
  • Loading branch information
admon84 authored Feb 14, 2022
2 parents 9ffbca7 + 2f9f354 commit f90eb02
Show file tree
Hide file tree
Showing 4 changed files with 431 additions and 162 deletions.
39 changes: 20 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,65 @@ This is an unofficial client for the [Screeps](https://screeps.com/) Unoffical A

Since the API is unofficial it could in theory change at any time. In practice though breaking changes are rare.

## Setup

## Setup:

Simply install the library using `pip`.

Simply install the Python `screepsapi` library using `pip`.

## Usage

### Authentication

To authenticate to the primary servers just supply a username and password.
The recommended way to authenticate to the official servers is providing an [Authorization Token](https://docs.screeps.com/auth-tokens.html) in the `token` parameter.

```python
import screepsapi
USER = "MyUsername"
PASSWORD = "TimeTravelingSecretAgentForHire"
api = screepsapi.API(USER, PASSWORD)
TOKEN = "3bdd1da7-3002-4aaa-be91-330562f54093"
api = screepsapi.API(token=TOKEN)
```

An optional `prefix` parameter can be included with values such as `"/ptr"` for the public test realm or `"/season"` for seasonal server.

It is also possible to access private servers with the `host` and `secure` parameters.

```python
import screepsapi
USER = "MyUsername"
PASSWORD = "TimeTravelingSecretAgentForHire"
api = screepsapi.API(USER, PASSWORD, host="server1.screepspl.us:443", secure=True)
HOST = "server1.screepspl.us:443"
api = screepsapi.API(USER, PASSWORD, host=HOST, secure=True)
```

Note that by default private servers do not use SSL and all traffic is unencrypted.

### Credentials

Developers are encouraged to align with [SS3: Unified Credentials File v1.0](https://github.com/screepers/screepers-standards/blob/master/SS3-Unified_Credentials_File.md) to standardize Screeps credentials storage with other third party tools.

### API

The API itself is a simple REST-based API. Each method in the api library corresponds to a different endpoint for the API.
The API class is a simple REST-based API. Each method corresponds to a different Screeps API endpoint.

The best way to discover functionality is to read through the library itself.
The best way to discover functionality is to read through the [screepsapi library](screepsapi/screepsapi.py) or [Endpoints.md](docs/Endpoints.md)

#### Console Example

```python
import screepsapi
USER = "MyUsername"
PASSWORD = "TimeTravelingSecretAgentForHire"
api = screepsapi.API(USER, PASSWORD, host="server1.screepspl.us:443", secure=True)
TOKEN = "3bdd1da7-3002-4aaa-be91-330562f54093"
api = screepsapi.API(token=TOKEN)

# Run "Game.time" on shard1 via the console
api.console('Game.time', shard='shard1')
api.console("Game.time", shard="shard1")
```

#### User Information Example

```python
import screepsapi
USER = "MyUsername"
PASSWORD = "TimeTravelingSecretAgentForHire"
api = screepsapi.API(USER, PASSWORD, host="server1.screepspl.us:443", secure=True)
TOKEN = "3bdd1da7-3002-4aaa-be91-330562f54093"
api = screepsapi.API(token=TOKEN)

# Find the GCL for `tedivm`
# Find the GCL for "tedivm"
user = api.user_find("tedivm")
print user["user"]["gcl"]
```
Expand Down
Loading

0 comments on commit f90eb02

Please sign in to comment.