Skip to content

Commit

Permalink
s/apiv0/apiv1/g
Browse files Browse the repository at this point in the history
  • Loading branch information
timstaley committed Dec 9, 2015
1 parent fcf4299 commit eeb5d5d
Show file tree
Hide file tree
Showing 21 changed files with 120 additions and 118 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
.. _apiv0_endpoints:
.. _apiv1_endpoints:

Endpoints
---------
The ``apiv0`` endpoints are listed below.
The ``apiv1`` endpoints are listed below.

Most endpoints return a JSON-encoded dictionary;
the 'Result' values documented below refer to the contents of the ``result``
entry in the JSON-dict. See :ref:`returned-content` for details.


.. autoflask:: voeventdb.server.restapi.app:app
:blueprints: apiv0
:blueprints: apiv1

34 changes: 17 additions & 17 deletions docs/source/apiv0/howto.rst → docs/source/apiv1/howto.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. _apiv0_howto:
.. _apiv1_howto:

Querying the REST API
=====================
Expand All @@ -23,11 +23,11 @@ Finding and using endpoints

The base URLs which represent different queries are known as endpoints -
full listings for voeventdb can be found on the
:ref:`apiv0_endpoints` page.
:ref:`apiv1_endpoints` page.
Some useful places to start are the
`root <endpoints.html#get--apiv0->`_ endpoint, which provides a concise listing
`root <endpoints.html#get--apiv1->`_ endpoint, which provides a concise listing
of the endpoints available, and the
`stream count <endpoints.html#get--apiv0-stream_count>`_ endpoint, which
`stream count <endpoints.html#get--apiv1-stream_count>`_ endpoint, which
serves as a sort of 'contents' page for the database.


Expand All @@ -40,37 +40,37 @@ By default, most endpoints return data on *all* VOEvents
currently stored in the database. [#notalldata]_
To narrow down your query to a specific subset of the VOEvents,
you can apply a selection of the available filters listed on the
:ref:`apiv0_filters` page.
:ref:`apiv1_filters` page.
Filters are applied by adding key-value pairs as part of the
`query-string`_ in your HTTP request.

For example, to return a count of the
packets stored since the start of November 2015, which have been assigned the
'observation' role, you can form an HTTP address like:

http://voeventdb.4pisky.org/apiv0/count?authored_since=2015-11&role=observation
http://voeventdb.4pisky.org/apiv1/count?authored_since=2015-11&role=observation

Though typically you would let your scripting library do the job of stitching
together the various parts. See the :ref:`apiv0_filters` page for more details.
together the various parts. See the :ref:`apiv1_filters` page for more details.

.. note::

You can apply any filter (or combination of filters) to any endpoint, so
(for example)

http://voeventdb.4pisky.org/apiv0/stream_count?authored_since=2015-11&role=observation
http://voeventdb.4pisky.org/apiv1/stream_count?authored_since=2015-11&role=observation

is also a valid query-URL (where we have replaced the ``/apiv0/count``
endpoint with ``/apiv0/stream_count``).
is also a valid query-URL (where we have replaced the ``/apiv1/count``
endpoint with ``/apiv1/stream_count``).





.. [#notalldata] The exceptions are the
`synopsis <endpoints.html#get--apiv0-synopsis->`_
`synopsis <endpoints.html#get--apiv1-synopsis->`_
and
`XML <endpoints.html#get--apiv0-xml->`_
`XML <endpoints.html#get--apiv1-xml->`_
endpoints, which are intended to retrieve data pertaining to a single
VOEvent.
Expand All @@ -85,9 +85,9 @@ URL-Encoding
-------------

Note that if you are accessing the
`packet-detail <endpoints.html#get--apiv0-full->`_
`packet-detail <endpoints.html#get--apiv1-full->`_
or
`XML <endpoints.html#get--apiv0-xml->`_
`XML <endpoints.html#get--apiv1-xml->`_
endpoints, or specifying a query-filter value which contains the ``#``
character, then you will need to use `URL-encoding <URL-encode_>`_ (because otherwise the
query-value is indistinguishable from an incorrectly-formed URL). It's simple to
Expand All @@ -113,20 +113,20 @@ of data. You can use pagination-keys in the same manner as
query-keys (i.e. in the query-string) to control this:


.. autoclass:: voeventdb.server.restapi.v0.definitions.PaginationKeys
.. autoclass:: voeventdb.server.restapi.v1.definitions.PaginationKeys
:members:
:undoc-members:

.. _ordervalues:

.. autoclass:: voeventdb.server.restapi.v0.definitions.OrderValues
.. autoclass:: voeventdb.server.restapi.v1.definitions.OrderValues
:members:
:undoc-members:

.. _returned-content:

Returned content
----------------
.. autoclass:: voeventdb.server.restapi.v0.viewbase.ResultKeys
.. autoclass:: voeventdb.server.restapi.v1.viewbase.ResultKeys
:members:
:undoc-members:
4 changes: 2 additions & 2 deletions docs/source/apiv0/index.rst → docs/source/apiv1/index.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.. _apiv0_ref:
.. _apiv1_ref:

REST API v0 (``apiv0``) reference
REST API v1 (``apiv1``) reference
##################################


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.. _apiv0_filters:
.. _apiv1_filters:

Query filters
---------------------------
Expand All @@ -12,7 +12,7 @@ These filters can be applied by providing key-value pairs as part of the
.. _query string: https://en.wikipedia.org/wiki/Query_string


.. automodule:: voeventdb.server.restapi.v0.filters
.. automodule:: voeventdb.server.restapi.v1.filters
:members:
:undoc-members:
:member-order: bysource
Expand Down
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def get_routes(app, endpoint=None):
# OK, let's get ugly!
# sphinx.contrib.autohttp has no way to hyperlink the endpoint headings.
# So instead, we add hyperlinks in the docstrings of the APIV0 endpoints:
apiv0_rules = [r for r in sorted(app.url_map.iter_rules())
if r.endpoint.startswith('apiv0')]
apiv1_rules = [r for r in sorted(app.url_map.iter_rules())
if r.endpoint.startswith('apiv1')]
import textwrap


Expand All @@ -149,7 +149,7 @@ def add_hyperlink_to_docstring(rule, app):


hyperlinked_endpoints = set()
for r in apiv0_rules:
for r in apiv1_rules:
if r.endpoint not in hyperlinked_endpoints:
add_hyperlink_to_docstring(r, app)
hyperlinked_endpoints.add(r.endpoint)
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Contents:
:maxdepth: 2

overview/index
apiv0/index
apiv1/index



Expand Down
2 changes: 1 addition & 1 deletion docs/source/overview/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ or jump straight to the relevant

If you would like to access the REST API directly, our copy of voeventdb
is hosted and documented at http://voeventdb.4pisky.org/. You can find
reference information on how to form your http-queries :ref:`here <apiv0_ref>`.
reference information on how to form your http-queries :ref:`here <apiv1_ref>`.

If you want to run a local copy of voeventdb, or contribute to voeventdb's
development, see :ref:`installation`.
12 changes: 6 additions & 6 deletions notebooks/voeventdb_requests_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@
},
"outputs": [],
"source": [
"apiv0_url = root_url + '/apiv0'\n",
"authored_month_url = apiv0_url + '/authored_month_count'\n",
"count_url = apiv0_url + '/count'\n",
"full_detail_url = apiv0_url + '/full'\n",
"streamcount_url = apiv0_url + '/stream_count'\n",
"ivorn_url = apiv0_url + '/ivorn'"
"apiv1_url = root_url + '/apiv1'\n",
"authored_month_url = apiv1_url + '/authored_month_count'\n",
"count_url = apiv1_url + '/count'\n",
"full_detail_url = apiv1_url + '/full'\n",
"streamcount_url = apiv1_url + '/stream_count'\n",
"ivorn_url = apiv1_url + '/ivorn'"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions voeventdb/server/restapi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
from flask import Flask, send_from_directory

from voeventdb.server.database import session_registry
from voeventdb.server.restapi.v0.views import apiv0
import voeventdb.server.restapi.v0.filters
from voeventdb.server.restapi.v0.jsonencoder import IsodatetimeJSONEncoder
from voeventdb.server.restapi.v1.views import apiv1
import voeventdb.server.restapi.v1.filters
from voeventdb.server.restapi.v1.jsonencoder import IsodatetimeJSONEncoder
from voeventdb.server.database.config import testdb_corpus_url

app = Flask(__name__)
app.config.from_object('voeventdb.server.restapi.default_config')
app.register_blueprint(apiv0)
app.register_blueprint(apiv1)


# restless_manager.init_app(app, session=session_registry)
Expand Down
20 changes: 10 additions & 10 deletions voeventdb/server/restapi/inspection_utils.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Add filters to registry:
import inspect
from voeventdb.server.restapi.v0.filter_base import filter_registry, QueryFilter
from voeventdb.server.restapi.v1.filter_base import filter_registry, QueryFilter
from voeventdb.server.restapi.app import app
import voeventdb.server.restapi.v0.views as v0views
from voeventdb.server.restapi.v0.views import QueryView, ListQueryView
import voeventdb.server.restapi.v0.filters as v0filters
import voeventdb.server.restapi.v1.views as v0views
from voeventdb.server.restapi.v1.views import QueryView, ListQueryView
import voeventdb.server.restapi.v1.filters as v0filters



def apiv0_endpoints():
# Grab all app endpoints, filter to apiv0
apiv0_rules = [r for r in app.url_map.iter_rules()
if r.endpoint.startswith('apiv0')]
def apiv1_endpoints():
# Grab all app endpoints, filter to apiv1
apiv1_rules = [r for r in app.url_map.iter_rules()
if r.endpoint.startswith('apiv1')]
# Filter duplicate listings for path-routed endpoints (xml_view, synopsis)
apiv0_rules = [r for r in apiv0_rules if
apiv1_rules = [r for r in apiv1_rules if
'<' not in str(r)]
return {str(r.endpoint)[6:]: str(r) for r in apiv0_rules}
return {str(r.endpoint)[6:]: str(r) for r in apiv1_rules}


def listqueryview_subclasses():
Expand Down
2 changes: 0 additions & 2 deletions voeventdb/server/restapi/v0/__init__.py

This file was deleted.

2 changes: 2 additions & 0 deletions voeventdb/server/restapi/v1/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from __future__ import absolute_import
from voeventdb.server.restapi.v1.viewbase import ResultKeys, PaginationKeys
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, ivorn):
<a href="http://meyerweb.com/eric/tools/dencoder/">URL-encoded</a>.
IVORN listings can be found at <a href="{1}">{1}</a>.
""".format(ivorn,url_for('apiv0.ivorn'))
""".format(ivorn,url_for('apiv1.ivorn'))


class IvornNotSupplied(Exception):
Expand All @@ -39,4 +39,4 @@ def __init__(self):
<a href="http://meyerweb.com/eric/tools/dencoder/">URL-encoded</a>
IVORN to the URL. IVORN listings can be found at
<a href="{0}">{0}</a>.
""".format(url_for('apiv0.ivorn'))
""".format(url_for('apiv1.ivorn'))
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class PaginationKeys:

class ResultKeys:
"""
Most :ref:`endpoints <apiv0_endpoints>` return a JSON-encoded dictionary.
Most :ref:`endpoints <apiv1_endpoints>` return a JSON-encoded dictionary.
[#ApartFromXml]_
At the top level, the dictionary will contain some or all of the following
Expand All @@ -120,7 +120,7 @@ class ResultKeys:
The key-strings can be imported and used in autocomplete-friendly
fashion, for example::
from voeventdb.server.restapi.v0 import ResultKeys as rkeys
from voeventdb.server.restapi.v1 import ResultKeys as rkeys
print rkeys.querystring
"""
endpoint = 'endpoint'
Expand All @@ -146,7 +146,7 @@ class ResultKeys:
The data returned by your query, either in dictionary
or list format according to the endpoint.
See :ref:`endpoint listings <apiv0_endpoints>` for detail.
See :ref:`endpoint listings <apiv1_endpoints>` for detail.
"""

url = 'url'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import
from voeventdb.server.restapi.v0.apierror import InvalidQueryString
from voeventdb.server.restapi.v0.definitions import PaginationKeys
from voeventdb.server.restapi.v1.apierror import InvalidQueryString
from voeventdb.server.restapi.v1.definitions import PaginationKeys

"""
Define the underlying machinery we'll use to implement query filters.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from __future__ import absolute_import
from voeventdb.server.database.models import Voevent, Cite, Coord
from voeventdb.server.database.query import coord_cone_search_clause
import voeventdb.server.restapi.v0.apierror as apierror
from voeventdb.server.restapi.v0.filter_base import (
import voeventdb.server.restapi.v1.apierror as apierror
from voeventdb.server.restapi.v1.filter_base import (
add_to_filter_registry, QueryFilter)
import iso8601
from sqlalchemy import (or_, and_, exists,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
)

from voeventdb.server.database.models import Voevent
from voeventdb.server.restapi.v0.filter_base import apply_filters
from voeventdb.server.restapi.v0.definitions import (
from voeventdb.server.restapi.v1.filter_base import apply_filters
from voeventdb.server.restapi.v1.definitions import (
OrderValues,
order_by_string_to_col_map,
PaginationKeys,
ResultKeys,
)
from voeventdb.server.restapi.v0.apierror import InvalidQueryString
from voeventdb.server.restapi.v1.apierror import InvalidQueryString

from sqlalchemy import asc, desc

Expand Down

0 comments on commit eeb5d5d

Please sign in to comment.