From 3e5a44b2ce58c10e5511bbf378c3411177f8a8ff Mon Sep 17 00:00:00 2001 From: Muhammad Asjad Date: Mon, 14 Apr 2014 17:27:47 +0500 Subject: [PATCH] updated readme, misc updates --- blockstack_search/search/README.md | 64 +++++++++++++++++++++++++ blockstack_search/search/onename_api.py | 19 ++++++-- 2 files changed, 78 insertions(+), 5 deletions(-) diff --git a/blockstack_search/search/README.md b/blockstack_search/search/README.md index d179005e6..4bb4d641d 100644 --- a/blockstack_search/search/README.md +++ b/blockstack_search/search/README.md @@ -53,3 +53,67 @@ the current version we're using is *0.90.2*. Download from: > python scopesearch/create_search_index.py --create_company_index We'll simplify these steps in an upcoming release. We assume that both MongoDB and Elastic Search is running on the server. + +----------------------------------------------------------------------------------------------------- + +Notes: 14, April, 2014: + +Project dependecies: + +requirements.txt files has been updated and contains all the project requriements. + +Notes: +before installing pylimbmc make sure libmemcache is installed: + + + brew install libmemcached + pip install pylibmc + +---------------------------------------------- + +Create Index: python create_search_index.py --create_index + + +Note: Make sure mongodb and elastic search are running before creating index + + +---------------------------------------------- +API usage: +---------------------------------------------- + +1) Generate Developer key: + + +syntax: /v1/gen_developer_key/ + +Example: curl -i http://localhost:5003/v1/gen_developer_key/asjad + + +---------------------------------------------- +2) Search API +---------------------------------------------- + +syntax: /v1/people-search//?keywords='' +e.g: +http://localhost:5003/v1/people-search/asjad/a0fe2f40415f7451c4ba2eae7da963d5?keywords=ryan + + +http://localhost:5003/v1/people-search/asjad/a0fe2f40415f7451c4ba2eae7da963d5?keywords=1G6pazv8zjWKBWouXVgHHvgmRmSm7JmH3S +keywords can accept username, twitter handle and btc + +* Experimental *: +http://localhost:5003/v1/people-search/asjad/a0fe2f40415f7451c4ba2eae7da963d5?twitter = muneeb +http://localhost:5003/v1/people-search/asjad/a0fe2f40415f7451c4ba2eae7da963d5?btc = muneeb + +---------------------------------------------- +3) Profile API +---------------------------------------------- + +Syntax: /v1/people/id= +e.g +curl -i http://localhost:5003/v1/people/id=muneeb + + +//----------------------------------------------------------------------------------------------------- + + diff --git a/blockstack_search/search/onename_api.py b/blockstack_search/search/onename_api.py index fe680c5b5..2a315fb2e 100644 --- a/blockstack_search/search/onename_api.py +++ b/blockstack_search/search/onename_api.py @@ -11,7 +11,7 @@ from flask import request, jsonify, Flask from search_api import get_people -from flask import make_response +from flask import make_response,Response import json from bson import json_util from helpers import * @@ -73,7 +73,14 @@ def search_people(developer_id,access_token): #--------------------------------------------- @app.route('/v1/people/id=', methods = ['GET']) def get_onename_profile(onename_id): - return json.dumps(query_people_database(onename_id)) + + profile = query_people_database(onename_id) + + if profile is not None: + return json.dumps(profile) + + else: + return make_response(jsonify( { 'error': 'profile not found' } ), 401) #----------------------untested--not working---------------------- @app.route('/v1/people/url=', methods = ['GET']) @@ -89,13 +96,15 @@ def query_people_database(onename_id,limit_results=DEFAULT_LIMIT): nodes = db.nodes onename_profile = nodes.find_one({"name": 'u/' + onename_id}) - #onename_profile = nodes.find({'value': {"$elemMatch": {"website":"http://muneebali.com"} }}) + if onename_profile is None: + return None - profile_details = json.loads(onename_profile['value']) + else: + profile_details = json.loads(onename_profile['value']) #TODO: add error handling - return onename_profile + return profile_details #custom error handling to return JSON error msgs #----------------------------------------------