# Path: pytaxize/refactor.py
# class Refactor:
#     def __init__(self, url, payload={}, request="get"):
#         self.url = url
#         self.payload = payload
#         self.request = request
# 
#     def return_requests(self, **kwargs):
#         if self.request == "get":
#             return requests.get(self.url, params=self.payload, **kwargs)
#         else:
#             return requests.post(self.url, params=self.payload, **kwargs)
# 
#     def xml(self, **kwargs):
#         if self.request == "get":
#             out = requests.get(self.url, params=self.payload, **kwargs)
#             out.raise_for_status()
#             xmlparser = etree.XMLParser()
#             tt = etree.fromstring(out.content, xmlparser)
#             try:
#                 # If entrez api 'X-RateLimit-Remaining' header is 1 or below, pause for a second to allow rate limit to reset
#                 if (int(out.headers['X-RateLimit-Remaining'])<=1):
#                     time.sleep(1)
#             except:
#                 pass 
#             return tt
#         else:
#             out = requests.post(self.url, params=self.payload, **kwargs)
#             out.raise_for_status()
#             xmlparser = etree.XMLParser()
#             tt = etree.fromstring(out.content, xmlparser)
#             return tt
# 
#     def json(self, **kwargs):
#         if self.request == "get":
#             out = requests.get(self.url, params=self.payload, **kwargs)
#             out.raise_for_status()
#             return out.json()
#         else:
#             out = requests.post(self.url, params=self.payload, **kwargs)
#             out.raise_for_status()
#             return out.json()
# 
#     def raw(self, **kwargs):
#         if self.request == "get":
#             out = requests.get(self.url, params=self.payload, **kwargs)
#             out.raise_for_status()
#             return out.text
#         else:
#             out = requests.post(self.url, params=self.payload, **kwargs)
#             out.raise_for_status()
#             return out.text


import sys
import requests
import json
    import doctest
from pytaxize.refactor import Refactor


class NoResultException(Exception):
    pass


def parse(names):
    """
    Uses the Global Names Index to parse scientific names

    :param names: List of scientific names.
    
    Usage::

        from pytaxize import gn
        gn.gni.parse(names = ['Cyanistes caeruleus','Helianthus annuus'])
    """
    url = "http://gni.globalnames.org/parsers.json"
    names = "|".join(names)
    params = {"names": names}

# Path: pytaxize/refactor.py
# class Refactor:
#     def __init__(self, url, payload={}, request="get"):
#         self.url = url
#         self.payload = payload
#         self.request = request
# 
#     def return_requests(self, **kwargs):
#         if self.request == "get":
#             return requests.get(self.url, params=self.payload, **kwargs)
#         else:
#             return requests.post(self.url, params=self.payload, **kwargs)
# 
#     def xml(self, **kwargs):
#         if self.request == "get":
#             out = requests.get(self.url, params=self.payload, **kwargs)
#             out.raise_for_status()
#             xmlparser = etree.XMLParser()
#             tt = etree.fromstring(out.content, xmlparser)
#             try:
#                 # If entrez api 'X-RateLimit-Remaining' header is 1 or below, pause for a second to allow rate limit to reset
#                 if (int(out.headers['X-RateLimit-Remaining'])<=1):
#                     time.sleep(1)
#             except:
#                 pass 
#             return tt
#         else:
#             out = requests.post(self.url, params=self.payload, **kwargs)
#             out.raise_for_status()
#             xmlparser = etree.XMLParser()
#             tt = etree.fromstring(out.content, xmlparser)
#             return tt
# 
#     def json(self, **kwargs):
#         if self.request == "get":
#             out = requests.get(self.url, params=self.payload, **kwargs)
#             out.raise_for_status()
#             return out.json()
#         else:
#             out = requests.post(self.url, params=self.payload, **kwargs)
#             out.raise_for_status()
#             return out.json()
# 
#     def raw(self, **kwargs):
#         if self.request == "get":
#             out = requests.get(self.url, params=self.payload, **kwargs)
#             out.raise_for_status()
#             return out.text
#         else:
#             out = requests.post(self.url, params=self.payload, **kwargs)
#             out.raise_for_status()
#             return out.text


# Path: pytaxize/gn/gni.py
import sys
import requests
import json
    import doctest
from pytaxize.refactor import Refactor



class NoResultException(Exception):
    pass


def parse(names):
    """
    Uses the Global Names Index to parse scientific names

    :param names: List of scientific names.
    
    Usage::

        from pytaxize import gn
        gn.gni.parse(names = ['Cyanistes caeruleus','Helianthus annuus'])
    """
    url = "http://gni.globalnames.org/parsers.json"
    names = "|".join(names)
    params = {"names": names}

    out = Refactor(url, payload=params, request="get").json()