import requests

from gtransport import _get_transport_client


class GTransportSession(requests.Session):
    def __init__(self):
        super(GTransportSession, self).__init__()
        self.parent = super(GTransportSession, self)

    def get(self, url, params=None, **kwargs):
        kwargs.setdefault('allow_redirects', True)
        return _get_transport_client().send(
            'get', url, provider=self.parent, params=params, **kwargs
        )

    def put(self, url, data=None, **kwargs):
        """Convenience method to make an HTTP PUT call"""
        return _get_transport_client().send(
            'put', url, provider=self.parent, data=data, **kwargs
        )

    def post(self, url, data=None, json=None, **kwargs):
        """Convenience method to make an HTTP POST call"""
        return _get_transport_client().send(
            'post', url, provider=self.parent, data=data, json=json, **kwargs
        )

    def patch(self, url, data=None, **kwargs):
        """Convenience method to make an HTTP PATCH call"""
        return _get_transport_client().send(
            'patch', url, provider=self.parent, data=data, **kwargs
        )

    def delete(self, url, **kwargs):
        """Convenience method to make an HTTP DELETE call"""
        return _get_transport_client().send(
            'delete', url, provider=self.parent, **kwargs
        )

    def request(self, method, url, data=None, json=None, **kwargs):
        """
        A generic function to make an HTTP call
        """
        return _get_transport_client().send(
            method, url, provider=self.parent, data=data, json=json, **kwargs
        )
