# -*- coding: utf-8 -*-

"""
biothings_explorer.mapping_parser
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This module contains code which parses the mapping file between
biothings schema and biothings API fields
"""
import requests


class BioThingsCaller():
    """call biothings APIs"""
    def __init__(self):
        self.url_pattern = {'mygene.info': "http://mygene.info/v3/query",
                            'myvariant.info': 'http://myvariant.info/v1/query',
                            "mychem.info": "http://mychem.info/v1/query"}

    def construct_query_param(self, input_fields, output_fields, value):
        params = 'q={input}:{value}&fields={output}'
        return params.replace('{input}', input_fields).replace('{output}',output_fields).replace('{value}', value)

    def call_api(self, api, _input, _output, value):
        params = self.construct_query_param(_input, _output, value)
        return requests.get(self.url_pattern[api], params=params).json()

@@ -295,19 +295,32 @@
 t__(self
+, batch=False
 ):%0A
-
         
@@ -538,16 +538,43 @@
 /query%22%7D
+%0A        self.batch = batch
 %0A%0A    de
@@ -640,32 +640,36 @@
 value):%0A        
+get_
 params = 'q=%7Binp
@@ -697,16 +697,140 @@
 utput%7D'%0A
+        post_params = 'q=%7Bvalue%7D&scopes=%7Binput%7D&fields=%7Boutput%7D'%0A        params = post_params if self.batch else get_params%0A
         
@@ -1058,16 +1058,47 @@
  value)%0A
+        if not self.batch:%0A    
         
@@ -1162,8 +1162,257 @@
 .json()%0A
+        else:%0A            headers = %7B'content-type': 'application/x-www-form-urlencoded'%7D%0A            return requests.post(self.url_pattern%5Bapi%5D,%0A                                 data=params,%0A                                 headers=headers).json()%0A

handle post API query