from __future__ import absolute_import, print_function, unicode_literals
from builtins import dict, str

__all__ = ['get_statements']

import requests

from indra import get_config
from indra.statements import stmts_from_json


def get_statements(subject=None, object=None, agents=None, stmt_type=None):
    agent_strs = ['agent=%s' % agent_str for agent_str in agents]
    params = {}
    for param_key, param_val in [('subject', subject), ('object', object),
                                 ('type', stmt_type)]:
        if param_val is not None:
            params[param_key] = param_val
    resp = submit_request(*agent_strs, **params)
    stmts_json = resp.json()
    return stmts_from_json(stmts_json)


def submit_request(*args, **kwargs):
    query_str = '?' + '&'.join(['%s=%s' % (k, v) for k, v in kwargs.items()]
                               + list(args))
    url = get_config('INDRA_DB_REST_URL', failure_ok=False)
    api_key = get_config('INDRADB_REST_API_KEY', failure_ok=False)
    resp = requests.get(url + '/statements/' + query_str,
                        headers={'x-api-key': api_key})
    return resp
@@ -297,16 +297,1901 @@
 =None):%0A
+    %22%22%22Get statements from INDRA's database using the web api.%0A%0A    This tool is intended for those that wish to use the cumulative database%0A    of pre-assembled INDRA Statements compiled from all our input databases and%0A    from reading all of the available medical literature, but who do not have%0A    direct access to the entire database.%0A%0A    Such access will require you have both a URL (%60INDRA_DB_REST_URL%60) and%0A    possibly an API key (%60INDRADB_REST_API_KEY%60), both of which may be placed in%0A    your config file or as environment variables.%0A%0A    If you do not have these, but would like to access the database rest api,%0A    you may contact the developers to request a URL and key.%0A%0A    Parameters%0A    ----------%0A    subject, object : str%0A        Optionally specify the subject and/or object of the statements in%0A        you wish to get from the database. By default, the namespace is assumed%0A        to be HGNC gene names, however you may specify another namespace by%0A        including %60@%3Cnamespace%3E%60 at the end of the name string. For example, if%0A        you want to specify an agent by chebi, you could use %60CHEBI:6801@CHEBI%60,%0A        or if you wanted to use the HGNC id, you could use %606871@HGNC%60.%0A    agents : list%5Bstr%5D%0A        A list of agents, specified in the same manner as subject and object,%0A        but without specifying their grammatical position.%0A    stmt_type : str%0A        Specify the types of interactions you are interested in, as indicated%0A        by the sub-classes of INDRA's Statements. This argument is *not* case%0A        sensitive.%0A%0A    Returns%0A    -------%0A    stmts : list%5B:pyclass:%60indra.statements.Statement%60%5D%0A        A list of INDRA Statement instances. Note that if a supporting or%0A        supported Statement was not included in your query, it will simply be%0A        instantiated as an %60Unresolved%60 statement, with %60uuid%60 of the statement.%0A    %22%22%22%0A
     agen
@@ -2248,16 +2248,16 @@
 agents%5D%0A
-
     para
@@ -2481,16 +2481,17 @@
  resp = 
+_
 submit_r
@@ -2594,16 +2594,17 @@
 )%0A%0A%0Adef 
+_
 submit_r
@@ -2628,16 +2628,82 @@
 wargs):%0A
+    %22%22%22Low level function to make the request to the rest API.%22%22%22%0A
     quer

Add doc strings.