# Path: models/meli_oerp_config.py
# REDIRECT_URI = ''


import pytz
import odoo.addons.decimal_precision as dp
import requests
import json
import logging
import meli
from odoo import models, api, fields
from odoo.tools.translate import _
    from urllib import urlencode
    from urllib.parse import urlencode
from .meli_oerp_config import REDIRECT_URI
from ..melisdk.meli import Meli
from meli.rest import ApiException
from meli.api_client import ApiClient
from datetime import datetime
        except:
            pass;
        return self

    def delete(self, path, params={}):
        try:
            atok = ("access_token" in params and params["access_token"]) or ""
            #_logger.info("MeliApi.delete(%s,%s)  %s" % (path,str(atok),str(body)) )
            self.response = self.resource_delete(resource=path, access_token=atok )
            self.rjson = self.response
        except ApiException as e:
            self.rjson = {
                "error": "%s" % e,
                "status": e.status,
                "cause": e.reason,
                "message": e.body
            }
        except:
            pass;
        return self

    def upload(self, path, files, params={}):
        try:
            atok = ("access_token" in params and params["access_token"]) or ""
            headers = {'Accept': 'application/json', 'Content-type':'multipart/form-data'}
            params = {"access_token":atok}
            #headers = {'Authorization': 'Bearer '+atok}
            headers = {}
            uri = configuration.host+str(path)
            _logger.info(headers)

# Path: models/meli_oerp_config.py
# REDIRECT_URI = ''


# Path: models/meli_util.py
import pytz
import odoo.addons.decimal_precision as dp
import requests
import json
import logging
import meli
from odoo import models, api, fields
from odoo.tools.translate import _
    from urllib import urlencode
    from urllib.parse import urlencode
from .meli_oerp_config import REDIRECT_URI
from ..melisdk.meli import Meli
from meli.rest import ApiException
from meli.api_client import ApiClient
from datetime import datetime

        except:
            pass;
        return self

    def delete(self, path, params={}):
        try:
            atok = ("access_token" in params and params["access_token"]) or ""
            #_logger.info("MeliApi.delete(%s,%s)  %s" % (path,str(atok),str(body)) )
            self.response = self.resource_delete(resource=path, access_token=atok )
            self.rjson = self.response
        except ApiException as e:
            self.rjson = {
                "error": "%s" % e,
                "status": e.status,
                "cause": e.reason,
                "message": e.body
            }
        except:
            pass;
        return self

    def upload(self, path, files, params={}):
        try:
            atok = ("access_token" in params and params["access_token"]) or ""
            headers = {'Accept': 'application/json', 'Content-type':'multipart/form-data'}
            params = {"access_token":atok}
            #headers = {'Authorization': 'Bearer '+atok}
            headers = {}
            uri = configuration.host+str(path)
            _logger.info(headers)

            self.response = requests.post(uri, files=files, params=urlencode(params), headers=headers)