Skip to content

Commit 754dda9

Browse files
author
Raman Barkholenka
authored
Merge pull request #1 from ghpxi/master
update and add new items, remove deprecated code
2 parents b146c4d + 9fff575 commit 754dda9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+4717
-2758
lines changed

README.md

Lines changed: 294 additions & 27 deletions
Large diffs are not rendered by default.

pyadmitad/api.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1+
# coding: utf-8
2+
from __future__ import unicode_literals
3+
14
from pyadmitad import client, transport
25

36

4-
def get_authorizing_client(access_token, user_agent=None, debug=False):
7+
def get_oauth_client_token(access_token, user_agent=None, debug=False):
58
"""
69
Creates a client using an access token.
10+
711
"""
8-
http_transport = transport.HttpTransport(
9-
access_token, user_agent=user_agent, debug=debug)
12+
http_transport = transport.HttpTransport(access_token, user_agent=user_agent, debug=debug)
1013
return client.Client(http_transport)
1114

1215

13-
def get_oauth_client_client(
14-
client_id, client_secret, scopes, user_agent=None, debug=False):
16+
def get_oauth_client_client(client_id, client_secret, scopes, user_agent=None, debug=False):
17+
"""
18+
Creates a client using a client_id and client_secret.
19+
20+
"""
1521
auth = transport.oauth_client_authorization({
1622
'client_id': client_id,
1723
'client_secret': client_secret,
1824
'scopes': scopes
1925
})
20-
return get_authorizing_client(
21-
auth['access_token'], user_agent=user_agent, debug=debug)
22-
23-
24-
def get_oauth_client(access_token, user_agent=None, debug=False):
25-
return get_authorizing_client(access_token, user_agent=user_agent, debug=debug)
26+
return get_oauth_client_token(auth['access_token'], user_agent=user_agent, debug=debug)

pyadmitad/client.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
from pyadmitad import items
2-
3-
4-
class FailedRequest(Exception):
1+
# coding: utf-8
2+
from __future__ import unicode_literals
53

6-
def __init__(self, error):
7-
self.error = error
8-
9-
def __str__(self):
10-
return repr(self.error)
4+
from pyadmitad import items
115

126

137
class Client(object):

pyadmitad/constants.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
CURRENCIES = ('USD', 'RUB', 'EUR')
1+
# coding: utf-8
2+
from __future__ import unicode_literals
3+
24
# API date-format
3-
DATE_FORMAT = "%d.%m.%Y"
4-
LONG_DATE_FORMAT = "%d.%m.%Y %H:%M:%S"
5+
DATE_FORMAT = '%d.%m.%Y'
6+
LONG_DATE_FORMAT = '%d.%m.%Y %H:%M:%S'
7+
8+
SUPPORTED_LANGUAGES = ('ru', 'en', 'de', 'pl', 'es', 'tr')
59

610
# default values
711
DEFAULT_REQUEST_TIMEOUT = 60
812
DEFAULT_LANGUAGE = 'ru'
9-
MAX_PAGINATION_LIMIT = 200
10-
SUB_ID_MAX_LENGTH = 50
13+
DEFAULT_PAGINATION_LIMIT = 20
14+
DEFAULT_PAGINATION_OFFSET = 0
15+
16+
# constants
17+
MAX_PAGINATION_LIMIT = 500
18+
MAX_SUB_ID_LENGTH = 250
1119

1220
# urls
1321
BASE_URL = 'https://api.admitad.com/'

pyadmitad/exceptions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
# coding: utf-8
2+
from __future__ import unicode_literals
13

24

35
class HttpException(Exception):
46

57
def __init__(self, status, message, content):
8+
super(HttpException, self).__init__()
9+
610
self.status = status
711
self.message = message
812
self.content = content
@@ -19,6 +23,8 @@ def __repr__(self):
1923
class ConnectionException(Exception):
2024

2125
def __init__(self, content):
26+
super(ConnectionException, self).__init__()
27+
2228
self.content = content
2329

2430
def __str__(self):
@@ -31,6 +37,8 @@ def __repr__(self):
3137
class JsonException(Exception):
3238

3339
def __init__(self, content):
40+
super(JsonException, self).__init__()
41+
3442
self.content = content
3543

3644
def __str__(self):
@@ -43,6 +51,8 @@ def __repr__(self):
4351
class ApiException(Exception):
4452

4553
def __init__(self, content):
54+
super(ApiException, self).__init__()
55+
4656
self.content = content
4757

4858
def __str__(self):

pyadmitad/items/__init__.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
from pyadmitad.items.me import *
2+
from pyadmitad.items.websites import *
23
from pyadmitad.items.auxiliary import *
4+
from pyadmitad.items.announcements import *
5+
from pyadmitad.items.news import *
6+
from pyadmitad.items.links import *
7+
from pyadmitad.items.landings import *
8+
from pyadmitad.items.deeplinks import *
9+
from pyadmitad.items.referrals import *
10+
from pyadmitad.items.payments import *
311
from pyadmitad.items.coupons import *
4-
from pyadmitad.items.websites import *
512
from pyadmitad.items.statistics import *
6-
from pyadmitad.items.referrals import *
713
from pyadmitad.items.banners import *
814
from pyadmitad.items.campaigns import *
9-
from pyadmitad.items.announcements import *
10-
from pyadmitad.items.payments import *
11-
from pyadmitad.items.landings import *
1215
from pyadmitad.items.optcodes import *
13-
from pyadmitad.items.news import *
14-
from pyadmitad.items.deeplinks import *
15-
from pyadmitad.items.links import *
1616
from pyadmitad.items.lost_orders import *
17+
from pyadmitad.items.arecords import *
18+
from pyadmitad.items.retag import *
19+
from pyadmitad.items.broken_links import *
20+
from pyadmitad.items.tickets import *

pyadmitad/items/announcements.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,43 @@
1+
# coding: utf-8
2+
from __future__ import unicode_literals
3+
14
from pyadmitad.items.base import Item
25

3-
__all__ = (
6+
7+
__all__ = [
48
'Announcements',
5-
)
9+
]
610

711

812
class Announcements(Item):
913
"""
1014
List of announcements
1115
12-
Required scope - "announcements"
1316
"""
17+
18+
SCOPE = 'announcements'
19+
1420
URL = Item.prepare_url('announcements')
15-
SINGLE_URL = Item.prepare_url('announcements/%(id)s')
21+
SINGLE_URL = Item.prepare_url('announcements/%(announcement_id)s')
1622

1723
def get(self, **kwargs):
1824
"""
19-
res = client.Announcements.get()
20-
res = client.Announcements.get(limit=1, offset=2)
25+
Args:
26+
limit (int)
27+
offset (int)
28+
2129
"""
22-
kwargs['url'] = self.URL
23-
return self.transport.set_method('GET').set_pagination(**kwargs).request(**kwargs)
30+
return self.transport.get().set_pagination(**kwargs).request(url=self.URL)
2431

2532
def getOne(self, _id, **kwargs):
2633
"""
27-
Here _id is an announcement id
34+
Args:
35+
_id (int)
2836
29-
res = client.Announcements.getOne(2)
3037
"""
31-
kwargs['url'] = self.SINGLE_URL
32-
kwargs['id'] = self.sanitize_id(_id)
33-
return self.transport.set_method('GET').request(**kwargs)
38+
request_data = {
39+
'url': self.SINGLE_URL,
40+
'announcement_id': Item.sanitize_id(_id)
41+
}
42+
43+
return self.transport.get().request(**request_data)

pyadmitad/items/arecords.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# coding: utf-8
2+
from __future__ import unicode_literals
3+
4+
from pyadmitad.items.base import Item
5+
6+
7+
__all__ = [
8+
'Arecords'
9+
]
10+
11+
12+
class Arecords(Item):
13+
14+
SCOPE = 'arecords'
15+
16+
URL = Item.prepare_url('arecords')
17+
FOR_WEBSITE_URL = Item.prepare_url('arecords/%(website_id)s')
18+
19+
def get(self, **kwargs):
20+
"""
21+
Args:
22+
limit (int)
23+
offset (int)
24+
25+
"""
26+
27+
return self.transport.get().set_pagination(**kwargs).request(url=self.URL)
28+
29+
def getForWebsite(self, website_id, **kwargs):
30+
"""
31+
Args:
32+
website_id (int)
33+
34+
"""
35+
36+
request_data = {
37+
'url': self.FOR_WEBSITE_URL,
38+
'website_id': Item.sanitize_id(website_id)
39+
}
40+
41+
return self.transport.get().request(**request_data)

0 commit comments

Comments
 (0)