Skip to content

Commit

Permalink
Merge pull request #6 from golnazads/master
Browse files Browse the repository at this point in the history
added /resolver to the endpoint path since this is not API and needs …
  • Loading branch information
golnazads authored Mar 29, 2018
2 parents c4bc15c + c1d7809 commit fad5a4b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 3 additions & 2 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# This is the URL to communicate with resolver_service api
RESOLVER_SERVICE_URL = 'http://localhost:5000/%s'
# These are the URL and token for resolver_service api
RESOLVER_SERVICE_URL = 'https://dev.adsabs.harvard.edu/v1/resolver/%s'
RESOLVER_SERVICE_ADSWS_API_TOKEN = 'this is a secret api token!'
4 changes: 2 additions & 2 deletions resolverway/tests/unittests/test_resolver_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_route(self):
Tests for the existence of a /resolver route, and that it returns
properly formatted JSON data when the URL is supplied
"""
r= self.client.get('/1987gady.book.....B/ABSTRACT/https://ui.adsabs.harvard.edu/#abs/1987gady.book.....B/ABSTRACT')
r= self.client.get('/resolver/1987gady.book.....B/ABSTRACT/https://ui.adsabs.harvard.edu/#abs/1987gady.book.....B/ABSTRACT')
self.assertEqual(r.status_code, 302)

def test_single_link(self):
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_route_error(self):
"""
Tests for wrong link type
"""
r = self.client.get('/1987gady.book.....B/ERROR')
r = self.client.get('/resolver/1987gady.book.....B/ERROR')
self.assertEqual(r.status_code, 400)

def test_with_header_and_cookie(self):
Expand Down
9 changes: 5 additions & 4 deletions resolverway/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def process_request(self):
try:
# if no url then send request to resolver_service to get link(s)
params = self.bibcode + '/' + self.link_type
response = requests.get(url=current_app.config['RESOLVER_SERVICE_URL'] %(params), headers=request.headers)
headers = {'Authorization': 'Bearer ' + current_app.config['RESOLVER_SERVICE_ADSWS_API_TOKEN']}
response = requests.get(url=current_app.config['RESOLVER_SERVICE_URL'] %(params), headers=headers)

contentType = response.headers.get('content-type')

Expand All @@ -98,9 +99,9 @@ def process_request(self):


@advertise(scopes=[], rate_limit=[1000, 3600 * 24])
@bp.route('/<bibcode>', defaults={'link_type': '', 'url': None}, methods=['GET'])
@bp.route('/<bibcode>/<link_type>', defaults={'url': None}, methods=['GET'])
@bp.route('/<bibcode>/<link_type>/<path:url>', methods=['GET'])
@bp.route('/resolver/<bibcode>', defaults={'link_type': '', 'url': None}, methods=['GET'])
@bp.route('/resolver/<bibcode>/<link_type>', defaults={'url': None}, methods=['GET'])
@bp.route('/resolver/<bibcode>/<link_type>/<path:url>', methods=['GET'])
def resolver(bibcode, link_type, url):
"""
Expand Down

0 comments on commit fad5a4b

Please sign in to comment.