mirror of
https://github.com/alexgo-io/stacks-puppet-node.git
synced 2026-01-12 22:43:42 +08:00
reorganize api repo
This commit is contained in:
@@ -5,23 +5,26 @@
|
||||
~~~~~
|
||||
"""
|
||||
|
||||
from flask import Flask
|
||||
from flask import Flask, Blueprint
|
||||
|
||||
# Create app
|
||||
app = Flask(__name__)
|
||||
|
||||
app.config.from_object('api.settings')
|
||||
|
||||
import errors
|
||||
import decorators
|
||||
import views
|
||||
# Import functions
|
||||
import errors, decorators, views
|
||||
|
||||
# Add in blueprints
|
||||
from .docs import docs
|
||||
from .v1 import v1
|
||||
from .auth import v1auth
|
||||
from .profile import v1profile
|
||||
from .proofs import v1proofs
|
||||
from .search import v1search
|
||||
|
||||
blueprints = [
|
||||
docs, v1, v1proofs
|
||||
docs,
|
||||
v1auth, v1profile, v1proofs, v1search
|
||||
]
|
||||
|
||||
for blueprint in blueprints:
|
||||
|
||||
@@ -7,9 +7,6 @@
|
||||
|
||||
from flask import Blueprint
|
||||
|
||||
v1 = Blueprint('v1', __name__, url_prefix='/v1')
|
||||
v1auth = Blueprint('v1auth', __name__, url_prefix='/v1')
|
||||
|
||||
import search
|
||||
import profile
|
||||
import auth
|
||||
import misc
|
||||
import views
|
||||
@@ -1,17 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Onename API
|
||||
Copyright 2014 Halfmoon Labs, Inc.
|
||||
~~~~~
|
||||
"""
|
||||
|
||||
from flask import request, jsonify
|
||||
|
||||
from . import v1
|
||||
from . import v1auth
|
||||
from ..rate_limit import save_user
|
||||
from ..decorators import parameters_required
|
||||
|
||||
@v1.route('/gen_developer_key/', methods=['GET'])
|
||||
@v1auth.route('/gen_developer_key/', methods=['GET'])
|
||||
@parameters_required(parameters=['developer_id'])
|
||||
def create_account():
|
||||
""" creates a new dev. account
|
||||
13
api/profile/__init__.py
Normal file
13
api/profile/__init__.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Onename API
|
||||
Copyright 2014 Halfmoon Labs, Inc.
|
||||
~~~~~
|
||||
"""
|
||||
|
||||
from flask import Blueprint
|
||||
|
||||
v1profile = Blueprint('v1profile', __name__, url_prefix='/v1')
|
||||
|
||||
import views
|
||||
from profile import *
|
||||
@@ -1,6 +1,6 @@
|
||||
import os, json, requests, traceback
|
||||
|
||||
from .errors import APIError, ProfileNotFoundError, BadProfileError, \
|
||||
from ..errors import APIError, ProfileNotFoundError, BadProfileError, \
|
||||
UsernameTakenError
|
||||
|
||||
def get_blockchain_profile(username):
|
||||
@@ -1,16 +1,15 @@
|
||||
import os, json
|
||||
from flask import jsonify
|
||||
|
||||
from . import v1
|
||||
from . import v1profile
|
||||
from .profile import get_blockchain_profile, get_profile_verifications
|
||||
from .samples import ryanshea
|
||||
from ..errors import APIError, ProfileNotFoundError, BadProfileError, \
|
||||
UsernameTakenError
|
||||
from ..crossdomain import crossdomain
|
||||
from ..decorators import access_token_required
|
||||
from ..samples import ryanshea
|
||||
|
||||
from ..profile import get_blockchain_profile, get_profile_verifications
|
||||
|
||||
@v1.route('/openname/<username>')
|
||||
@v1profile.route('/openname/<username>')
|
||||
@access_token_required
|
||||
@crossdomain(origin='*')
|
||||
def api_user(username):
|
||||
@@ -1,4 +1,4 @@
|
||||
import json
|
||||
import json, traceback
|
||||
from flask import jsonify, request
|
||||
|
||||
from . import v1proofs
|
||||
@@ -6,22 +6,33 @@ from .proofs import profile_to_verifications
|
||||
from ..errors import APIError
|
||||
from ..decorators import parameters_required, access_token_required
|
||||
from ..crossdomain import crossdomain
|
||||
from ..profile import get_blockchain_profile
|
||||
|
||||
@v1proofs.route('/verifications', methods=['POST'])
|
||||
@parameters_required(parameters=["profile", "openname"])
|
||||
@parameters_required(parameters=["openname"])
|
||||
@crossdomain(origin='*')
|
||||
def verify_profile():
|
||||
if not request.data:
|
||||
if not (request.data or request.form):
|
||||
raise APIError('A payload must be included', status_code=400)
|
||||
|
||||
try:
|
||||
data = json.loads(request.data)
|
||||
except ValueError:
|
||||
raise APIError('Data must be in JSON format', status_code=400)
|
||||
if request.data:
|
||||
try:
|
||||
data = json.loads(request.data)
|
||||
except ValueError:
|
||||
raise APIError('Data must be in JSON format', status_code=400)
|
||||
elif request.form:
|
||||
try:
|
||||
data = dict(request.form)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
raise APIError('Invalid form data', status_code=400)
|
||||
|
||||
profile = data["profile"]
|
||||
openname = data["openname"]
|
||||
openname = str(data["openname"][0])
|
||||
if "profile" in data:
|
||||
profile = data["profile"]
|
||||
else:
|
||||
profile = get_blockchain_profile(openname)
|
||||
|
||||
verifications = profile_to_verifications(profile, openname)
|
||||
|
||||
return jsonify({ "verifications": verifications }), 200
|
||||
return jsonify({ "profile": profile, "verifications": verifications }), 200
|
||||
|
||||
12
api/search/__init__.py
Normal file
12
api/search/__init__.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Onename API
|
||||
Copyright 2014 Halfmoon Labs, Inc.
|
||||
~~~~~
|
||||
"""
|
||||
|
||||
from flask import Blueprint
|
||||
|
||||
v1search = Blueprint('v1search', __name__, url_prefix='/v1')
|
||||
|
||||
import views
|
||||
@@ -9,12 +9,12 @@ import os, json, requests
|
||||
from flask import render_template, send_from_directory, Response, url_for, \
|
||||
request, jsonify, make_response
|
||||
|
||||
from . import v1
|
||||
from . import v1search
|
||||
from ..errors import APIError
|
||||
from ..decorators import access_token_required, parameters_required
|
||||
from ..crossdomain import crossdomain
|
||||
|
||||
@v1.route('/search', methods=['GET'])
|
||||
@v1search.route('/search', methods=['GET'])
|
||||
@access_token_required
|
||||
@parameters_required(parameters=['query'])
|
||||
@crossdomain(origin='*')
|
||||
@@ -8,18 +8,18 @@
|
||||
<a href="/docs" class="list-group-item" ng-class="{active: activetab == '/docs'}">
|
||||
Getting Started
|
||||
</a>
|
||||
<a href="/docs/auth" class="list-group-item" ng-class="{active: activetab == '/docs/auth'}">
|
||||
<!--<a href="/docs/auth" class="list-group-item" ng-class="{active: activetab == '/docs/auth'}">
|
||||
Authentication
|
||||
</a>
|
||||
</a>-->
|
||||
<a href="/docs/opennames" class="list-group-item" ng-class="{active: activetab == '/docs/opennames'}">
|
||||
Openname Lookups
|
||||
</a>
|
||||
<a href="/docs/search" class="list-group-item" ng-class="{active: activetab == '/docs/search'}">
|
||||
Search
|
||||
</a>
|
||||
<a href="/docs/verifications" class="list-group-item" ng-class="{active: activetab == '/docs/verifications'}">
|
||||
Verifications
|
||||
</a>
|
||||
<a href="/docs/search" class="list-group-item" ng-class="{active: activetab == '/docs/search'}">
|
||||
Search
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Onename API
|
||||
Copyright 2014 Halfmoon Labs, Inc.
|
||||
~~~~~
|
||||
"""
|
||||
|
||||
from flask import jsonify
|
||||
|
||||
from . import v1
|
||||
from ..decorators import parameters_required
|
||||
|
||||
@v1.route('/latestversions', methods=['GET'])
|
||||
def latest_versions():
|
||||
payload = {
|
||||
'onename_api': '1',
|
||||
'ons_specs': '0.3',
|
||||
'ons_directory': '0.1',
|
||||
'ons_server': '0.1'
|
||||
}
|
||||
return jsonify(payload), 200
|
||||
@@ -3,7 +3,6 @@ import json, requests
|
||||
payload = {
|
||||
"profile": {
|
||||
"graph": {
|
||||
"followee_count": 4,
|
||||
"url": "https://s3.amazonaws.com/grph/ryanshea"
|
||||
},
|
||||
"twitter": {
|
||||
@@ -21,7 +20,7 @@ payload = {
|
||||
"website": "http://shea.io",
|
||||
"github": {
|
||||
"proof": {
|
||||
"url": "https://gist.github.com/rxl/9799732"
|
||||
"url": "https://gist.githuåb.com/rxl/9799732"
|
||||
},
|
||||
"username": "rxl"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user