Skip to content

Commit 2dfebb9

Browse files
committed
Merge branch 'release/2.0'
2 parents f6631b3 + 1afa5f8 commit 2dfebb9

File tree

14 files changed

+85
-600
lines changed

14 files changed

+85
-600
lines changed

LICENSE

Lines changed: 26 additions & 560 deletions
Large diffs are not rendered by default.

magento/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
'''
33
magento API
44
5-
:copyright: (c) 2010 by Sharoon Thomas.
6-
:copyright: (c) 2010-2013 by Openlabs Technologies & Consulting (P) LTD
7-
:license: AGPLv3, see LICENSE for more details
5+
:license: BSD, see LICENSE for more details
86
'''
97
__all__ = [
108
'API', 'Store', 'Magento',

magento/api.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
# -*- coding: UTF-8 -*-
1+
# -*- coding: utf-8 -*-
22
'''
33
magento.api
44
55
Generic API for magento
66
7-
:copyright: (c) 2010 by Sharoon Thomas.
8-
:copyright: (c) 2010 by Openlabs Technologies & Consulting (P) LTD
9-
:license: AGPLv3, see LICENSE for more details
7+
:license: BSD, see LICENSE for more details
108
'''
119

1210
PROTOCOLS = []
@@ -24,6 +22,15 @@
2422
else:
2523
PROTOCOLS.append('soap')
2624

25+
from . import rest
26+
try:
27+
import requests
28+
import json
29+
except ImportError:
30+
pass
31+
else:
32+
PROTOCOLS.append('rest')
33+
2734
from magento.utils import expand_url
2835

2936

@@ -33,7 +40,8 @@ class API(object):
3340
"""
3441

3542
def __init__(self, url, username, password,
36-
version='1.3.2.4', full_url=False, protocol='xmlrpc', transport=None):
43+
version='1.3.2.4', full_url=False, protocol='xmlrpc', transport=None,
44+
verify_ssl=True):
3745
"""
3846
This is the Base API class which other APIs have to subclass. By
3947
default the inherited classes also get the properties of this
@@ -98,6 +106,7 @@ def store_views(self):
98106
:param protocol: 'xmlrpc' and 'soap' are valid values
99107
:param transport: optional xmlrpclib.Transport subclass for
100108
use in xmlrpc requests
109+
:param verify_ssl: for REST API, skip SSL validation if False
101110
"""
102111
assert protocol \
103112
in PROTOCOLS, "protocol must be %s" % ' OR '.join(PROTOCOLS)
@@ -109,6 +118,7 @@ def store_views(self):
109118
self.transport = transport
110119
self.session = None
111120
self.client = None
121+
self.verify_ssl = verify_ssl
112122

113123
def connect(self):
114124
"""
@@ -121,6 +131,10 @@ def connect(self):
121131
self.url, allow_none=True, transport=self.transport)
122132
else:
123133
self.client = ServerProxy(self.url, allow_none=True)
134+
elif self.protocol == 'rest':
135+
# Use an authentication token as the password
136+
self.client = rest.Client(self.url, self.password,
137+
verify_ssl=self.verify_ssl)
124138
else:
125139
self.client = Client(self.url)
126140

@@ -134,6 +148,8 @@ def __enter__(self):
134148
if self.protocol == 'xmlrpc':
135149
self.session = self.client.login(
136150
self.username, self.password)
151+
elif self.protocol == 'rest':
152+
self.session = True
137153
else:
138154
self.session = self.client.service.login(
139155
self.username, self.password)
@@ -147,7 +163,7 @@ def __exit__(self, type, value, traceback):
147163
"""
148164
if self.protocol == 'xmlrpc':
149165
self.client.endSession(self.session)
150-
else:
166+
elif self.protocol == 'soap':
151167
self.client.service.endSession(self.session)
152168
self.session = None
153169

@@ -157,6 +173,8 @@ def call(self, resource_path, arguments):
157173
"""
158174
if self.protocol == 'xmlrpc':
159175
return self.client.call(self.session, resource_path, arguments)
176+
elif self.protocol == 'rest':
177+
return self.client.call(resource_path, arguments)
160178
else:
161179
return self.client.service.call(
162180
self.session, resource_path, arguments)

magento/catalog.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
55
Product Catalog API for magento
66
7-
:copyright: (c) 2010 by Sharoon Thomas.
8-
:copyright: (c) 2010 by Openlabs Technologies & Consulting (P) LTD
9-
:license: AGPLv3, see LICENSE for more details
7+
:license: BSD, see LICENSE for more details
108
'''
119

1210
import warnings

magento/checkout.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
Checkout API for magento
66
Allows you to manage shopping carts and the checkout process.
77
8-
:copyright: (c) 2010 by Sharoon Thomas.
9-
:copyright: (c) 2010 by Openlabs Technologies & Consulting (P) LTD.
108
11-
:license: AGPLv3, see LICENSE for more details
9+
:license: BSD, see LICENSE for more details
1210
'''
1311

1412
from .api import API

magento/client.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
55
Client API for magento
66
7-
:copyright: (c) 2014 by Openlabs Technologies & Consulting (P) LTD
8-
:license: BSD, see LICENSE for more details
97
'''
108
from threading import RLock
119

magento/customer.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
55
Customer API for magento
66
7-
:copyright: (c) 2010 by Sharoon Thomas.
8-
:copyright: (c) 2010 by Openlabs Technologies & Consulting (P) LTD.
97
10-
:license: AGPLv3, see LICENSE for more details
8+
:license: BSD, see LICENSE for more details
119
'''
1210
from magento.api import API
1311

magento/directory.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
55
Directory Country API for magento
66
7-
:copyright: (c) 2010 by Sharoon Thomas.
8-
:copyright: (c) 2010 by Openlabs Technologies & Consulting (P) LTD
9-
:license: AGPLv3, see LICENSE for more details
7+
:license: BSD, see LICENSE for more details
108
'''
119
from magento.api import API
1210

magento/miscellaneous.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
55
This API allows to access additional magento information
66
7-
:copyright: (c) 2013 by Openlabs Technologies & Consulting (P) Limited
8-
:license: AGPLv3, see LICENSE for more details.
97
"""
108
from magento.api import API
119

magento/rest.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# coding: utf-8
2+
try:
3+
import requests
4+
import json
5+
except ImportError:
6+
pass
7+
8+
9+
class Client(object):
10+
11+
def __init__(self, url, token, verify_ssl=True):
12+
self._url = url
13+
self._token = token
14+
self._verify_ssl = verify_ssl
15+
16+
def call(self, resource_path, arguments):
17+
url = '%s/%s' % (self._url, resource_path)
18+
res = requests.get(
19+
url, params=arguments, verify=self._verify_ssl,
20+
headers={'Authorization': 'Bearer %s' % self._token})
21+
res.raise_for_status()
22+
return res.json()

0 commit comments

Comments
 (0)