|
| 1 | +# -*- encoding: utf-8 -*- |
| 2 | +# |
| 3 | +# Copyright © 2013 Woorea Solutions, S.L |
| 4 | +# |
| 5 | +# Author: Luis Gervaso <luis@woorea.es> |
| 6 | +# |
| 7 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 8 | +# not use this file except in compliance with the License. You may obtain |
| 9 | +# a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 16 | +# License for the specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | +import datetime |
| 19 | + |
| 20 | +import flask |
| 21 | + |
| 22 | +from billingstack.openstack.common import log |
| 23 | +from billingstack.openstack.common import timeutils |
| 24 | + |
| 25 | +from billingstack import storage |
| 26 | + |
| 27 | + |
| 28 | +LOG = log.getLogger(__name__) |
| 29 | + |
| 30 | + |
| 31 | +blueprint = flask.Blueprint('v1', __name__, |
| 32 | + template_folder='templates', |
| 33 | + static_folder='static') |
| 34 | + |
| 35 | + |
| 36 | +def request_wants_html(): |
| 37 | + best = flask.request.accept_mimetypes \ |
| 38 | + .best_match(['application/json', 'text/html']) |
| 39 | + return best == 'text/html' and \ |
| 40 | + flask.request.accept_mimetypes[best] > \ |
| 41 | + flask.request.accept_mimetypes['application/json'] |
| 42 | + |
| 43 | + |
| 44 | +def _get_metaquery(args): |
| 45 | + return dict((k, v) |
| 46 | + for (k, v) in args.iteritems() |
| 47 | + if k.startswith('metadata.')) |
| 48 | + |
| 49 | +## APIs for working with meters. |
| 50 | + |
| 51 | + |
| 52 | +@blueprint.route('/merchants') |
| 53 | +def merchants_list(): |
| 54 | + """Return a list of merchants. |
| 55 | + """ |
| 56 | + rq = flask.request |
| 57 | + merchants = rq.storage_conn.merchants_list() |
| 58 | + return flask.jsonify(meters=list(merchants)) |
| 59 | + |
| 60 | + |
| 61 | +@blueprint.route('/merchants/<merchant_id>') |
| 62 | +def show_merchant(merchant_id): |
| 63 | + """Return a merchant by ID |
| 64 | +
|
| 65 | + :param merchant_id: The ID of the resource. |
| 66 | + """ |
| 67 | + rq = flask.request |
| 68 | + merchant = rq.storage_conn.merchants_get() |
| 69 | + return flask.jsonify(merchant) |
| 70 | + |
0 commit comments