Beispiel #1
0
class HttpResponse(with_metaclass(ABCMeta)):
    """HttpResponse."""
    @abstractproperty
    def status_code(self):
        """Get status code."""
        raise NotImplementedError

    @abstractproperty
    def headers(self):
        """Get headers."""
        raise NotImplementedError

    @abstractproperty
    def text(self):
        """Get request body as text-decoded."""
        raise NotImplementedError

    @abstractproperty
    def content(self):
        """Get request body as binary."""
        raise NotImplementedError

    @abstractproperty
    def json(self):
        """Get request body as json-decoded."""
        raise NotImplementedError

    @abstractmethod
    def iter_content(self, chunk_size=1024, decode_unicode=False):
        """Get request body as iterator content (stream).

        :param int chunk_size:
        :param bool decode_unicode:
        """
        raise NotImplementedError
Beispiel #2
0
class SendMessage(with_metaclass(ABCMeta, Base)):
    """Abstract Base Class of SendMessage."""
    def __init__(self, **kwargs):
        """__init__ method.

        :param kwargs:
        """
        super(SendMessage, self).__init__(**kwargs)

        self.type = None
Beispiel #3
0
class Template(with_metaclass(ABCMeta, Base)):
    """Abstract Base Class of Template."""
    def __init__(self, **kwargs):
        """__init__ method.

        :param kwargs:
        """
        super(Template, self).__init__(**kwargs)

        self.type = None
Beispiel #4
0
class Message(with_metaclass(ABCMeta, Base)):
    """Abstract Base Class of Message."""
    def __init__(self, id=None, **kwargs):
        """__init__ method.

        :param str id: Message ID
        :param kwargs:
        """
        super(Message, self).__init__(**kwargs)

        self.type = None
        self.id = id
Beispiel #5
0
class HttpClient(with_metaclass(ABCMeta)):
    """Abstract Base Classes of HttpClient."""

    DEFAULT_TIMEOUT = 5

    def __init__(self, timeout=DEFAULT_TIMEOUT):
        """__init__ method.

        :param timeout: (optional) How long to wait for the server
            to send data before giving up, as a float,
            or a (connect timeout, readtimeout) float tuple.
            Default is :py:attr:`DEFAULT_TIMEOUT`
        :type timeout: float | tuple(float, float)
        :rtype: T <= :py:class:`HttpResponse`
        :return: HttpResponse instance
        """
        self.timeout = timeout

    @abstractmethod
    def get(self, url, headers=None, params=None, stream=False, timeout=None):
        """GET request.

        :param str url: Request url
        :param dict headers: (optional) Request headers
        :param dict params: (optional) Request query parameter
        :param bool stream: (optional) get content as stream
        :param timeout: (optional), How long to wait for the server
            to send data before giving up, as a float,
            or a (connect timeout, readtimeout) float tuple.
            Default is :py:attr:`self.timeout`
        :type timeout: float | tuple(float, float)
        :rtype: T <= :py:class:`HttpResponse`
        :return: HttpResponse instance
        """
        raise NotImplementedError

    @abstractmethod
    def post(self, url, headers=None, data=None, timeout=None):
        """POST request.

        :param str url: Request url
        :param dict headers: (optional) Request headers
        :param data: (optional) Dictionary, bytes, or file-like object to send in the body
        :param timeout: (optional), How long to wait for the server
            to send data before giving up, as a float,
            or a (connect timeout, readtimeout) float tuple.
            Default is :py:attr:`self.timeout`
        :type timeout: float | tuple(float, float)
        :rtype: T <= :py:class:`HttpResponse`
        :return: HttpResponse instance
        """
        raise NotImplementedError
Beispiel #6
0
class ImagemapAction(with_metaclass(ABCMeta, Base)):
    """ImagemapAction.

    https://devdocs.line.me/en/#imagemap-message
    """

    def __init__(self, **kwargs):
        """__init__ method.

        :param kwargs:
        """
        super(ImagemapAction, self).__init__(**kwargs)

        self.type = None
Beispiel #7
0
class Source(with_metaclass(ABCMeta, Base)):
    """Abstract Base Class of Source."""
    def __init__(self, **kwargs):
        """__init__ method.

        :param kwargs:
        """
        super(Source, self).__init__(**kwargs)
        self.type = None

    @abstractproperty
    def sender_id(self):
        """Helper method.

        If SourceUser, return user_id.
        If SourceGroup, return group_id.
        If SourceRoom, return room_id.

        :rtype: str
        :return:
        """
        raise NotImplementedError
Beispiel #8
0
class Event(with_metaclass(ABCMeta, Base)):
    """Abstract Base Class of Webhook Event.

    https://devdocs.line.me/en/#webhook-event-object
    """
    def __init__(self, timestamp=None, source=None, **kwargs):
        """__init__ method.

        :param long timestamp: Time of the event in milliseconds
        :param source: Source object
        :type source: T <= :py:class:`linebot.models.sources.Source`
        :param kwargs:
        """
        super(Event, self).__init__(**kwargs)

        self.type = None
        self.timestamp = timestamp
        self.source = self.get_or_new_from_json_dict_with_types(
            source, {
                'user': SourceUser,
                'group': SourceGroup,
                'room': SourceRoom,
            })
Beispiel #9
0
class BaseError(with_metaclass(ABCMeta, Exception)):
    """Base Exception class."""
    def __init__(self, message='-'):
        """__init__ method.

        :param str message: Human readable message
        """
        self.message = message

    def __repr__(self):
        """repr.

        :return:
        """
        return str(self)

    def __str__(self):
        """str.

        :rtype: str
        :return:
        """
        return '<{0} [{1}]>'.format(self.__class__.__name__, self.message)