Skip to content

Commit e92d5fd

Browse files
author
Laurynas Butkus
committed
Remove configuration class
1 parent 91e86df commit e92d5fd

File tree

5 files changed

+24
-28
lines changed

5 files changed

+24
-28
lines changed

convertapi/__init__.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
__version__ = '0.0.1'
22

33
from .exceptions import *
4-
from .configuration import Configuration
54
from .client import Client
65
from .api import convert
76

8-
configuration = Configuration()
9-
client = Client(configuration)
7+
# configuration
8+
9+
api_secret = None
10+
base_uri = 'https://v2.convertapi.com/'
11+
user_agent = 'ConvertAPI-Python/' + __version__
12+
timeout = 60
13+
conversion_timeout = 180
14+
conversion_timeout_delta = 10
15+
upload_timeout = 600
16+
download_timeout = 600
17+
18+
client = Client()

convertapi/client.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
import requests
2+
import convertapi
23

34
from .exceptions import *
45

56
class Client:
6-
def __init__(self, configuration):
7-
self.configuration = configuration
8-
97
def get(self, path, params = {}, timeout = None):
10-
timeout = timeout or self.configuration.timeout
8+
timeout = timeout or convertapi.timeout
119
r = requests.get(self.url(path), params = params, headers = self.headers(), timeout = timeout)
1210
return self.handle_response(r)
1311

1412
def post(self, path, payload, timeout = None):
15-
timeout = timeout or self.configuration.timeout
13+
timeout = timeout or convertapi.timeout
1614
r = requests.post(self.url(path), data = payload, headers = self.headers(), timeout = timeout)
1715
return self.handle_response(r)
1816

1917
def download(self, url, path):
20-
r = requests.get(url, stream = True, timeout = self.configuration.download_timeout)
18+
r = requests.get(url, stream = True, timeout = convertapi.download_timeout)
2119

2220
with open(path, 'wb') as f:
2321
for chunk in r.iter_content(chunk_size = 1024):
@@ -37,9 +35,9 @@ def handle_response(self, r):
3735
return json
3836

3937
def url(self, path):
40-
return "%s%s?Secret=%s" % (self.configuration.base_uri, path, self.configuration.api_secret)
38+
return "%s%s?Secret=%s" % (convertapi.base_uri, path, convertapi.api_secret)
4139

4240
def headers(self):
4341
return {
44-
'User-Agent': self.configuration.user_agent,
42+
'User-Agent': convertapi.user_agent,
4543
}

convertapi/configuration.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

convertapi/task.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def __init__(self, from_format, to_format, params, conversion_timeout = None):
77
self.from_format = from_format
88
self.to_format = to_format
99
self.params = params
10-
self.conversion_timeout = conversion_timeout or convertapi.configuration.conversion_timeout
10+
self.conversion_timeout = conversion_timeout or convertapi.conversion_timeout
1111

1212
self.default_params = {
1313
'Timeout': self.conversion_timeout,
@@ -17,7 +17,7 @@ def __init__(self, from_format, to_format, params, conversion_timeout = None):
1717
def run(self):
1818
params = self.__normalize_params()
1919
from_format = self.from_format
20-
timeout = self.conversion_timeout + convertapi.configuration.conversion_timeout_delta
20+
timeout = self.conversion_timeout + convertapi.conversion_timeout_delta
2121
path = "convert/%s/to/%s" % (from_format, self.to_format)
2222

2323
response = convertapi.client.post(path, params, timeout = timeout)

tests/test_convertapi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
class TestConvertapi(utils.TestCase):
99
def setUp(self):
10-
convertapi.configuration.api_secret = os.environ['CONVERT_API_SECRET']
10+
convertapi.api_secret = os.environ['CONVERT_API_SECRET']
1111

1212
def test_defaults(self):
13-
eq_('https://v2.convertapi.com/', convertapi.configuration.base_uri)
13+
eq_('https://v2.convertapi.com/', convertapi.base_uri)
1414

1515
def test_configuration(self):
16-
convertapi.configuration.api_secret = 'TEST'
17-
eq_('TEST', convertapi.client.configuration.api_secret)
16+
convertapi.api_secret = 'TEST'
17+
eq_('TEST', convertapi.api_secret)
1818

1919
def test_convert(self):
2020
result = convertapi.convert('pdf', { 'Url': 'http://convertapi.com' }, 'web')

0 commit comments

Comments
 (0)