elementapi 0.8__tar.gz → 0.9.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {elementapi-0.8 → elementapi-0.9.1}/PKG-INFO +11 -2
- {elementapi-0.8 → elementapi-0.9.1}/elementapi/__init__.py +73 -13
- {elementapi-0.8 → elementapi-0.9.1}/elementapi.egg-info/PKG-INFO +11 -2
- {elementapi-0.8 → elementapi-0.9.1}/setup.py +2 -2
- {elementapi-0.8 → elementapi-0.9.1}/elementapi.egg-info/SOURCES.txt +0 -0
- {elementapi-0.8 → elementapi-0.9.1}/elementapi.egg-info/dependency_links.txt +0 -0
- {elementapi-0.8 → elementapi-0.9.1}/elementapi.egg-info/requires.txt +0 -0
- {elementapi-0.8 → elementapi-0.9.1}/elementapi.egg-info/top_level.txt +0 -0
- {elementapi-0.8 → elementapi-0.9.1}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: elementapi
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.9.1
|
|
4
4
|
Summary: element-iot api client lib
|
|
5
5
|
Home-page: https://github.com/ZennerIoT/python-elementapi
|
|
6
6
|
Download-URL: https://github.com/ZennerIoT/python-elementapi/archive/master.zip
|
|
@@ -12,3 +12,12 @@ Classifier: Intended Audience :: Developers
|
|
|
12
12
|
Classifier: License :: OSI Approved :: MIT License
|
|
13
13
|
Classifier: Programming Language :: Python :: 2.7
|
|
14
14
|
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Requires-Dist: requests
|
|
16
|
+
Dynamic: author
|
|
17
|
+
Dynamic: author-email
|
|
18
|
+
Dynamic: classifier
|
|
19
|
+
Dynamic: download-url
|
|
20
|
+
Dynamic: home-page
|
|
21
|
+
Dynamic: keywords
|
|
22
|
+
Dynamic: requires-dist
|
|
23
|
+
Dynamic: summary
|
|
@@ -68,6 +68,7 @@ class ElementAPI:
|
|
|
68
68
|
custom_ca = None
|
|
69
69
|
https_no_verify = False
|
|
70
70
|
headers = {'Accept': 'application/json'}
|
|
71
|
+
_meta=None
|
|
71
72
|
|
|
72
73
|
def __init__(
|
|
73
74
|
self,
|
|
@@ -121,24 +122,71 @@ class ElementAPI:
|
|
|
121
122
|
if self.https_no_verify:
|
|
122
123
|
self.requestargs['verify'] = False
|
|
123
124
|
|
|
125
|
+
|
|
126
|
+
@property
|
|
127
|
+
def meta(self):
|
|
128
|
+
if not self._meta:
|
|
129
|
+
resp=self._raw_req(('mandates', ))
|
|
130
|
+
|
|
131
|
+
mandates = resp.json()
|
|
132
|
+
parent = None
|
|
133
|
+
is_multi = len(mandates)>1
|
|
134
|
+
|
|
135
|
+
if is_multi:
|
|
136
|
+
for m in mandates:
|
|
137
|
+
if not m.get('parent_id'):
|
|
138
|
+
parent = m
|
|
139
|
+
break
|
|
140
|
+
|
|
141
|
+
mandate_id = resp.headers.get('x-zis-platform-mandate-id') if not is_multi else parent.get('id')
|
|
142
|
+
mandate = parent.get('name') if parent else( bytearray(resp.headers.get('x-zis-platform-mandate-name'), 'ISO-8859-1').decode(
|
|
143
|
+
'utf-8') if 'x-zis-platform-mandate-name' in resp.headers else None)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
resp = self._raw_req(('status',),noapi=True)
|
|
147
|
+
|
|
148
|
+
self._meta = {
|
|
149
|
+
'mandate_id': mandate_id ,
|
|
150
|
+
'mandate': mandate,
|
|
151
|
+
'is_multi': is_multi,
|
|
152
|
+
'mandates': mandates.get('body'),
|
|
153
|
+
'version': resp.json().get('nodes',[{}])[0].get('version')
|
|
154
|
+
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return self._meta
|
|
158
|
+
|
|
159
|
+
|
|
124
160
|
# TODO: allow plain string paths !
|
|
125
|
-
def genurl(self, _path=None, **opts):
|
|
161
|
+
def genurl(self, _path=None, noapi=False, **opts):
|
|
126
162
|
if 'limit' not in opts or not opts['limit'] or opts['limit'] > 100:
|
|
127
163
|
opts['limit'] = 100
|
|
128
164
|
|
|
129
165
|
if opts.get('nolimit', False):
|
|
130
166
|
opts.pop('limit')
|
|
131
167
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
168
|
+
if noapi:
|
|
169
|
+
rurl = "%s%s:%s/%s?auth=%s%s" \
|
|
170
|
+
% (
|
|
171
|
+
"https://" if self.https else "http://",
|
|
172
|
+
self.baseurl,
|
|
173
|
+
self.port,
|
|
174
|
+
'/'.join(_path) if _path else '/',
|
|
175
|
+
self.apitoken,
|
|
176
|
+
'' if (not opts or not len(opts))
|
|
177
|
+
else ('&%s' % '&'.join(['%s=%s' % (k, v) for k, v in opts.items() if v]))
|
|
178
|
+
)
|
|
179
|
+
else:
|
|
180
|
+
rurl = "%s%s:%s%s/%s?auth=%s%s" \
|
|
181
|
+
% (
|
|
182
|
+
"https://" if self.https else "http://",
|
|
183
|
+
self.baseurl,
|
|
184
|
+
self.port,
|
|
185
|
+
self.apiversion, '/'.join(_path) if _path else '/',
|
|
186
|
+
self.apitoken,
|
|
187
|
+
'' if (not opts or not len(opts))
|
|
188
|
+
else ('&%s' % '&'.join(['%s=%s' % (k, v) for k, v in opts.items() if v]))
|
|
189
|
+
)
|
|
142
190
|
return rurl
|
|
143
191
|
|
|
144
192
|
def _log_request(self, meth, url, data=None):
|
|
@@ -149,7 +197,10 @@ class ElementAPI:
|
|
|
149
197
|
)
|
|
150
198
|
)
|
|
151
199
|
|
|
152
|
-
def
|
|
200
|
+
def _raw_req(self, uri=None, limit=None, lib_filter=None, stream=False, raise_rl=False, noapi=False, **opts):
|
|
201
|
+
return list(self._req(uri=uri, limit=limit, lib_filter=lib_filter, stream=stream, raise_rl=raise_rl, noapi=noapi, raw=True, **opts))[-1]
|
|
202
|
+
|
|
203
|
+
def _req(self, uri=None, limit=None, lib_filter=None, stream=False, raise_rl=False, raw=False, noapi=False, **opts):
|
|
153
204
|
resp = None
|
|
154
205
|
count = 0
|
|
155
206
|
|
|
@@ -159,11 +210,15 @@ class ElementAPI:
|
|
|
159
210
|
url = self.genurl(
|
|
160
211
|
(uri if uri else ()) + ('stream',),
|
|
161
212
|
nolimit=True,
|
|
213
|
+
noapi=noapi,
|
|
162
214
|
**opts
|
|
163
215
|
)
|
|
164
216
|
self._log_request("GET (streaming)", url)
|
|
165
217
|
resp = requests.get(url, **self.requestargs)
|
|
166
218
|
|
|
219
|
+
if raw:
|
|
220
|
+
yield resp
|
|
221
|
+
|
|
167
222
|
if resp.status_code >= 400:
|
|
168
223
|
raise ElementAPIException('HTTP Error', resp.status_code, get_body(resp))
|
|
169
224
|
|
|
@@ -186,12 +241,17 @@ class ElementAPI:
|
|
|
186
241
|
url = self.genurl(
|
|
187
242
|
(uri if uri else ()),
|
|
188
243
|
retrieve_after=(resp.get('retrieve_after_id', None) if resp else None),
|
|
189
|
-
|
|
244
|
+
noapi=noapi,
|
|
245
|
+
limit=limit,
|
|
246
|
+
**opts,
|
|
190
247
|
)
|
|
191
248
|
self._log_request("GET", url)
|
|
192
249
|
last_response = resp
|
|
193
250
|
resp = requests.get(url, **self.requestargs)
|
|
194
251
|
|
|
252
|
+
if raw:
|
|
253
|
+
yield resp
|
|
254
|
+
|
|
195
255
|
if resp.status_code >= 400:
|
|
196
256
|
if resp.status_code == 429 and not raise_rl:
|
|
197
257
|
# hit create-limit
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: elementapi
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.9.1
|
|
4
4
|
Summary: element-iot api client lib
|
|
5
5
|
Home-page: https://github.com/ZennerIoT/python-elementapi
|
|
6
6
|
Download-URL: https://github.com/ZennerIoT/python-elementapi/archive/master.zip
|
|
@@ -12,3 +12,12 @@ Classifier: Intended Audience :: Developers
|
|
|
12
12
|
Classifier: License :: OSI Approved :: MIT License
|
|
13
13
|
Classifier: Programming Language :: Python :: 2.7
|
|
14
14
|
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Requires-Dist: requests
|
|
16
|
+
Dynamic: author
|
|
17
|
+
Dynamic: author-email
|
|
18
|
+
Dynamic: classifier
|
|
19
|
+
Dynamic: download-url
|
|
20
|
+
Dynamic: home-page
|
|
21
|
+
Dynamic: keywords
|
|
22
|
+
Dynamic: requires-dist
|
|
23
|
+
Dynamic: summary
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
from
|
|
1
|
+
from setuptools import setup
|
|
2
2
|
|
|
3
3
|
setup(
|
|
4
4
|
name='elementapi',
|
|
5
5
|
packages=['elementapi'],
|
|
6
|
-
version='0.
|
|
6
|
+
version='0.9.1',
|
|
7
7
|
description='element-iot api client lib',
|
|
8
8
|
author='Stefan Reiser',
|
|
9
9
|
author_email='sr@zenner-iot.com',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|