Skip to content

Commit 36f7882

Browse files
author
Carlo Smouter
committed
Support new client credentials flow and deprecate the old api token flow.
1 parent 6cfd0ae commit 36f7882

16 files changed

+575
-381
lines changed

.drone.yml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pipeline:
2+
build:
3+
image: python:${PYTHON_VERSION}-alpine3.8
4+
commands:
5+
- find . -name "*.py[co]" -delete
6+
- pip install --upgrade pip
7+
- pip install -e .
8+
- pip install -e .[tests]
9+
- py.test
10+
- find . -name "*.py[co]" -delete
11+
when:
12+
include: [ master, develop, feature/*, release/* ]
13+
matrix:
14+
PYTHON_VERSION:
15+
- "3.7"
16+
- "3.6"
17+
- "3.5"
18+
- "2.7"

CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Changelog
2+
3+
## 2.0 (In Development)
4+
5+
* Deprecate 1.0 WowApi
6+
* Implement client credentials flow for OAuth authentication
7+
* Add dronefile for testing against multiple python versions
8+
* Add coverage to pytest
9+
* Add logging

LICENSE.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
python-wowapi
22
-----------------
3-
Copyright (c) 2013 python-wowapi | Carlo Smouter
3+
Copyright (c) 2018 python-wowapi | Carlo Smouter
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

MANIFEST.in

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
include setup.py README.rst Makefile MANIFEST.in
1+
include setup.py
2+
include README.md
3+
include CHANGELOG.md
4+
include Makefile
5+
include MANIFEST.in
26
include LICENSE.txt
37
include Makefile
48
include pytest.ini

README.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# python-wowapi
2+
3+
Python-wowapi is a client library for interacting with the World of Warcraft
4+
Community API.
5+
6+
Documentation about installing and usage can be found at [python-wowapi.readthedocs.org](https://python-wowapi.readthedocs.org)
7+
8+
## Installing
9+
10+
```bash
11+
pip install python-wowapi
12+
```
13+
14+
## Usage
15+
16+
```python
17+
import os
18+
19+
from wowapi import WowApi
20+
21+
22+
api = WowApi(os.environ['WOW_CLIENT_ID'], os.environ['WOW_CLIENT_SECRET'])
23+
data = api.get_auctions('eu', 'silvermoon', locale='de_DE')
24+
print(data)
25+
```
26+
27+
## Development & Testing
28+
29+
```bash
30+
pip install -e .
31+
pip install -e .[tests]
32+
py.test
33+
```
34+
35+
## Drone test runner
36+
37+
```
38+
PYTHON_VERSION=3.7 drone exec
39+
PYTHON_VERSION=3.6 drone exec
40+
PYTHON_VERSION=3.5 drone exec
41+
PYTHON_VERSION=2.7 drone exec
42+
```
43+
44+
For more information about Drone, visit [Drone.io](https://drone.io/)

README.rst

-7
This file was deleted.

docs/conf.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,16 @@
4444

4545
# General information about the project.
4646
project ='python-wowapi'
47-
copyright ='2013, Carlo Smouter'
47+
copyright ='2018, Carlo Smouter'
4848

4949
# The version info for the project you're documenting, acts as replacement for
5050
# |version| and |release|, also used in various other places throughout the
5151
# built documents.
5252
#
5353
# The short X.Y version.
54-
version = '1.0'
54+
version = '2.0'
5555
# The full version, including alpha/beta/rc tags.
56-
release = '1.0'
56+
release = '2.0'
5757

5858
# The language for content autogenerated by Sphinx. Refer to documentation
5959
# for a list of supported languages.

docs/index.rst

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ Python-wowapi
33

44
Python-wowapi is a client library for interacting with the World of Warcraft Community API.
55

6+
This library requires a client-id and client secret for the Community API OAuth client credentials flow.
7+
68
For more information visit:
79

8-
- `Official API documentation <https://dev.battle.net/io-docs>`_
9-
- `Official API Forum <http://us.battle.net/forums/en/bnet/15051532/>`_
10+
- `Official API documentation <https://develop.battle.net/documentation>`_
11+
- `Official API Forum <https://us.battle.net/forums/en/bnet/15051532/>`_
1012

1113

1214
Usage
1315
-----
1416

15-
.. warning::
16-
`WOWAPI_APIKEY` has to be set as an environment variable before calling the api endpoints.
17-
1817
::
1918

2019
>>> from wowapi import WowApi
21-
>>> item = WowApi.get_item('eu', 9999)
20+
>>> api = WowApi('client-id', 'client-secret')
21+
>>> item = api.get_item('eu', 9999)
2222

2323
{
2424
"id": 9999,
@@ -31,7 +31,7 @@ Usage
3131

3232
::
3333

34-
>>> item = WowApi.get_item('eu', 9999, locale='de_DE')
34+
>>> item = api.get_item('eu', 9999, locale='de_DE')
3535

3636
{
3737
"id": 9999,

examples/main.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import logging
2+
import os
3+
from pprint import pprint
4+
5+
from wowapi import WowApi
6+
7+
8+
logger = logging.getLogger('wowapi')
9+
logger.setLevel(logging.INFO)
10+
handler = logging.StreamHandler()
11+
handler.setLevel(logging.INFO)
12+
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
13+
handler.setFormatter(formatter)
14+
logger.addHandler(handler)
15+
16+
logger.info('WowApi example')
17+
18+
api = WowApi(os.environ['WOW_CLIENT_ID'], os.environ['WOW_CLIENT_SECRET'])
19+
data = api.get_auctions('eu', 'silvermoon', locale='de_DE')
20+
pprint(data)
21+
22+
data = api.get_realm_status('us')
23+
pprint(data)

pytest.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[pytest]
2-
addopts = --tb=short --pep8 --flakes
2+
addopts = -vs --tb=short --pep8 --flakes --cov=wowapi --cov-config .coveragerc
33

44
python_files =
55
test_*.py

setup.py

+11-13
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from setuptools import setup
44

55

6-
__version__ = '1.0'
6+
__version__ = '2.0'
77

88

99
def read(*parts):
@@ -13,24 +13,20 @@ def read(*parts):
1313

1414

1515
install_requirements = [
16-
'requests==2.11.1',
16+
'requests==2.19.1',
1717
]
1818

1919
test_requirements = [
20-
'tox==2.4.1',
21-
'py==1.4.31',
22-
'pyflakes==1.3.0',
23-
'pytest==3.0.3',
24-
'pytest-cache==1.0',
25-
'pytest-flakes==1.0.1',
20+
'pytest==3.8.2',
21+
'pytest-flakes==4.0.0',
2622
'pytest-pep8==1.0.6',
27-
'mock==1.0.1',
28-
'pep8==1.7.0',
29-
'pytest-mock==1.2',
23+
'pytest-cov==2.6.0',
24+
'mock==2.0.0',
25+
'pytest-mock==1.10.0',
3026
]
3127

3228
docs_requirements = [
33-
'Sphinx==1.4.8',
29+
'Sphinx==1.8.1',
3430
]
3531

3632
setup(
@@ -55,7 +51,9 @@ def read(*parts):
5551
'Operating System :: OS Independent',
5652
'Programming Language :: Python',
5753
'Programming Language :: Python :: 2.7',
58-
'Programming Language :: Python :: 3.4',
54+
'Programming Language :: Python :: 3.5',
55+
'Programming Language :: Python :: 3.6',
56+
'Programming Language :: Python :: 3.7',
5957
'Topic :: Internet :: WWW/HTTP',
6058
],
6159
packages=[

tests/fixtures.py

+18-23
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,33 @@
11
import pytest
22
import requests
3-
from requests.exceptions import RequestException
4-
5-
6-
def response_mock():
7-
mock = requests.models.Response()
8-
mock.status_code = 200
9-
mock._content = b'{}'
10-
return mock
113

124

135
@pytest.fixture
14-
def get_mock(mocker):
15-
return mocker.patch('requests.get', return_value=response_mock())
6+
def session_get_mock(mocker):
7+
return mocker.patch('requests.Session.get')
168

179

1810
@pytest.fixture
19-
def get_404_mock(mocker):
20-
mock = response_mock()
21-
mock.status_code = 404
22-
mock._content = 'Not Found'
11+
def utc_mock(mocker):
12+
return mocker.patch('wowapi.api.WowApi._utcnow')
2313

24-
return mocker.patch('requests.get', return_value=mock)
2514

15+
def get_success_response():
16+
mock = requests.models.Response()
17+
mock.status_code = 200
18+
mock._content = b'{}'
19+
return mock
2620

27-
@pytest.fixture
28-
def invalid_json_mock(mocker):
29-
mock = response_mock()
30-
mock._content = b'{"foo": "bar"},'
3121

32-
return mocker.patch('requests.get', return_value=mock)
22+
class ResponseMock(object):
3323

24+
def __call__(self, status_code, content):
25+
mock = requests.models.Response()
26+
mock.status_code = status_code
27+
mock._content = content
28+
return mock
3429

35-
@pytest.fixture
36-
def request_exception_mock(mocker):
3730

38-
return mocker.patch('requests.get', side_effect=RequestException('Problem'))
31+
@pytest.fixture
32+
def response_mock(mocker):
33+
return mocker.patch('requests.Session.get', return_value=get_success_response())

0 commit comments

Comments
 (0)