"""prawcore.sessions: Provides prawcore.Session and prawcore.session."""
from .auth import Authorizer
from .rate_limit import RateLimiter
from .exceptions import InvalidInvocation
from .util import authorization_error_class
from requests.status_codes import codes


class Session(object):
    """The low-level connection interface to reddit's API."""

    def __init__(self, authorizer):
        """Preprare the connection to reddit's API.

        :param authorizer: An instance of :class:`Authorizer`.

        """
        if not isinstance(authorizer, Authorizer):
            raise InvalidInvocation('invalid Authorizer: {}'
                                    .format(authorizer))
        self._authorizer = authorizer
        self._rate_limiter = RateLimiter()

    def __enter__(self):
        """Allow this object to be used as a context manager."""
        return self

    def __exit__(self, *_args):
        """Allow this object to be used as a context manager."""
        self.close()

    @property
    def _requestor(self):
        return self._authorizer._authenticator._requestor

    def close(self):
        """Close the session and perform any clean up."""
        self._requestor._http.close()

    def request(self, method, path):
        """Return the json content from the resource at ``path``.

        :param path: The path of the request. This path will be combined with
            the ``oauth_url`` of the Requestor.

        """
        if not self._authorizer.is_valid():
            raise InvalidInvocation('authorizer does not have a valid token')

        headers = {'Authorization': 'bearer {}'
                   .format(self._authorizer.access_token)}
        params = {'raw_json': '1'}
        url = self._requestor.oauth_url + path
        response = self._rate_limiter.call(self._requestor._http.request,
                                           method, url, headers=headers,
                                           params=params)

        if response.status_code in (codes['forbidden'], codes['unauthorized']):
            raise authorization_error_class(response)
        assert response.status_code == codes['ok'], \
            'Unexpected status code: {}'.format(response.status_code)
        return response.json()


def session(authorizer=None):
    """Return a :class:`Session` instance.

    :param authorizer: An instance of :class:`Authorizer`.

    """
    return Session(authorizer=authorizer)

@@ -66,16 +66,109 @@
 ion.%22%22%22%0A
+import logging%0A%0Afrom requests.compat import urljoin%0Afrom requests.status_codes import codes%0A%0A
 from .au
@@ -314,47 +314,45 @@
 ass%0A
-from requests.status_codes import codes
+%0Alog = logging.getLogger(__package__)
 %0A%0A%0Ac
@@ -1333,16 +1333,29 @@
 od, path
+, params=None
 ):%0A     
@@ -1412,24 +1412,87 @@
  %60%60path%60%60.%0A%0A
+        :param method: The request verb. E.g., get, post, put.%0A
         :par
@@ -1604,16 +1604,86 @@
 questor.
+%0A        :param params: The query parameters to send with the request.
 %0A%0A      
@@ -1935,17 +1935,44 @@
 arams = 
-%7B
+params or %7B%7D%0A        params%5B
 'raw_jso
@@ -1977,14 +1977,13 @@
 son'
-: '1'%7D
+%5D = 1
 %0A   
@@ -1993,16 +1993,24 @@
   url = 
+urljoin(
 self._re
@@ -2030,15 +2030,170 @@
 _url
- + path
+, path)%0A%0A        log.debug('Fetching: %7B%7D %7B%7D'.format(method, url))%0A        log.debug('Headers: %7B%7D'.format(headers))%0A        log.debug('Params: %7B%7D'.format(params))%0A
 %0A   
@@ -2395,16 +2395,144 @@
 arams)%0A%0A
+        log.debug('Response: %7B%7D (%7B%7D bytes)'.format(%0A            response.status_code, response.headers.get('content-length')))%0A%0A
         

Add `params` parameter to Session.request.