Skip to content

Commit c496db6

Browse files
committed
switch to use nuxeo-client-library
basic switch out of `requests` for `nuxeo.request`
1 parent ffaa4f2 commit c496db6

File tree

4 files changed

+16
-20
lines changed

4 files changed

+16
-20
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ python:
66
- "2.7"
77
install:
88
- python setup.py install
9+
- pip install httpretty
910
script:
10-
- python setup.py test
11+
- python pynux/tests/test_utils.py
1112

1213
#before_script:
1314
# - git config --global user.name "Teracy" # Configure your git user.name here

pynux/tests/test_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class TestNuxeoREST(unittest.TestCase):
1313
def setUp(self):
1414
self.nx = utils.Nuxeo({
15-
'api': 'http://mockme/r',
15+
'api': 'http://localhost:8080/nuxeo/',
1616
}, rcfile=io.BytesIO(bytes()))
1717

1818
@httpretty.activate

pynux/utils.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from future import standard_library
1313
standard_library.install_aliases()
1414
from builtins import object
15-
import requests
1615
import json
1716
import sys
1817
import os
@@ -23,6 +22,7 @@
2322
from os.path import expanduser
2423
import codecs
2524
import urllib.parse
25+
import nuxeo.client
2626

2727
# set the output to utf8 in py2 or py3
2828
UTF8Writer = codecs.getwriter('utf8')
@@ -157,6 +157,8 @@ def __init__(self, conf={}, rcfile=None, loglevel=_loglevel_):
157157
redacted = self.conf
158158
redacted.update({'password': '...redacted...'})
159159
self.logger.debug(redacted)
160+
self.nuxeo_client = nuxeo.client.Nuxeo(auth=self.auth)
161+
self.request = self.nuxeo_client.client.request
160162

161163
## Python generator for paged API resource
162164
# based on http://stackoverflow.com/questions/17702785/
@@ -173,12 +175,8 @@ def _get_page(self, url, params, current_page_index):
173175
:returns: json from nuxeo
174176
"""
175177
params.update({'currentPageIndex': current_page_index})
176-
res = requests.get(
177-
url,
178-
headers=self.document_property_headers,
179-
params=params,
180-
auth=self.auth)
181-
res.raise_for_status()
178+
path = url.split(self.nuxeo_client.client.host,1)[1]
179+
res = self.request('GET', path, params=params)
182180
self.logger.debug(res.content)
183181
return json.loads(res.content.decode('utf-8'))
184182

@@ -249,9 +247,8 @@ def get_uid(self, path):
249247
:rtype: string
250248
"""
251249
url = u'/'.join([self.conf['api'], "path", escape_path(path).strip('/')])
252-
res = requests.get(
253-
url, headers=self.document_property_headers, auth=self.auth)
254-
res.raise_for_status()
250+
path = url.split(self.nuxeo_client.client.host,1)[1]
251+
res = self.request('GET', path)
255252
return json.loads(res.content.decode('utf-8'))['uid']
256253

257254
def get_metadata(self, **documentid):
@@ -268,9 +265,8 @@ def get_metadata(self, **documentid):
268265
elif 'uid' in documentid:
269266
uid = documentid['uid']
270267
url = u'/'.join([self.conf['api'], "id", uid])
271-
res = requests.get(
272-
url, headers=self.document_property_headers, auth=self.auth)
273-
res.raise_for_status()
268+
path = url.split(self.nuxeo_client.client.host,1)[1]
269+
res = self.request('GET', path)
274270
return json.loads(res.content.decode('utf-8'))
275271

276272
def update_nuxeo_properties(self, data, **documentid):
@@ -297,9 +293,8 @@ def update_nuxeo_properties(self, data, **documentid):
297293
payload['uid'] = uid
298294
payload['entity-type'] = data.get('entity-type', 'document')
299295
payload['properties'] = data['properties']
300-
res = requests.put(
301-
url, data=json.dumps(payload), auth=self.auth, headers=headers)
302-
res.raise_for_status()
296+
path = url.split(self.nuxeo_client.client.host,1)[1]
297+
res = self.request('PUT', path, data=json.dumps(payload))
303298
return json.loads(res.content)
304299

305300
def print_document_summary(self, documents):

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
from setuptools import setup, find_packages
33
setup(
44
name='pynux',
5-
version = "1.0.4",
5+
version = "1.1.0-alpha",
66
packages = find_packages(),
77
install_requires = [
8-
'requests',
98
'configparser',
109
'future',
1110
'EZID @ https://github.com/ucldc/ezid/archive/v0.4.2.tar.gz',
11+
'nuxeo',
1212
],
1313
test_suite = 'pynux.tests.test_utils',
1414
tests_require = ['httpretty'],

0 commit comments

Comments
 (0)