Skip to content

Commit

Permalink
rename search_api -> search-api, searchsvr -> search-service; refacto…
Browse files Browse the repository at this point in the history
…ring search-api
  • Loading branch information
datamut committed Sep 19, 2016
1 parent fd9d837 commit 8a75472
Show file tree
Hide file tree
Showing 14 changed files with 18 additions and 10 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions search_api/application.py → search-api/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Date: 09/18/2016
"""

from search_api import application
from searchapi.service import application

if __name__ == '__main__':
application.run(debug=True)
application.run()
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class AuthService(object):

def __init__(self, server):
self.prefix = server

Expand All @@ -18,7 +17,6 @@ def verify(self, client_id, token):


class SearchService(object):

def __init__(self, server):
self.prefix = server

Expand All @@ -29,5 +27,7 @@ def search(self, query, limit):
return response.json()


auth_service = AuthService('http://authsvr.kc7ctmpd2z.us-west-2.elasticbeanstalk.com')
search_service = SearchService('http://searchsvr.kc7ctmpd2z.us-west-2.elasticbeanstalk.com')
auth_service = AuthService(
'http://authsvr.kc7ctmpd2z.us-west-2.elasticbeanstalk.com')
search_service = SearchService(
'http://searchsvr.kc7ctmpd2z.us-west-2.elasticbeanstalk.com')
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,24 @@
from flask import Flask, Response, request, render_template
import json

from search_api.provider import auth_service, search_service
from searchapi.provider import auth_service, search_service


application = Flask(__name__)


@application.route('/')
def index():
"""A simple web interface of API for better interaction.
"""
return render_template('index.html')


@application.route('/search/<client_id>/<token>', methods=['POST'])
def search(client_id, token):
"""Search API for external use.
"""

# TODO: retry when request failed for each service

auth_resp = auth_service.verify(client_id, token)
Expand All @@ -30,8 +35,8 @@ def search(client_id, token):
if 'limit' in request.form:
try:
limit = min(int(request.form['limit']), 100)
except:
pass # TODO: deal with error here
except ValueError:
pass # TODO: deal with error here

search_resp = search_service.search(query, limit)
return Response(json.dumps(search_resp), mimetype='application/json')
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion searchsvr/service.py → search-service/searchsvr/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
Date: 09/19/2016
"""

from flask import Flask, Response, request, g
import json

from flask import Flask, Response, request, g

from searchsvr.flask_mongo import MongoConnection

mongo_connection = MongoConnection()

application = Flask(__name__)

application.config['MONGO_HOSTS'] = 'mongodb://{}@{},{}/whatsnews'.format(
'ureadonly:u1s2e3r', 'aws-us-east-1-portal.9.dblayer.com:15345',
'aws-us-east-1-portal.6.dblayer.com:15345'
Expand Down
Empty file.
File renamed without changes.

0 comments on commit 8a75472

Please sign in to comment.