# Path: dyndnsc/updater/base.py
# class UpdateProtocol(Subject, DynamicCliMixin):
#     """Base class for all update protocols that use a simple http GET protocol."""
# 
#     theip = None
#     __hostname = None  # private place to store the property 'hostname'
#     configuration_key = None
# 
#     @property
#     def hostname(self):
#         """
#         Return the hostname managed by this updater.
# 
#         May be implemented or overwritten in updater subclasses.
#         """
#         return self.__hostname
# 
#     @hostname.setter
#     def hostname(self, value):
#         """
#         Set the hostname managed by this updater.
# 
#         May be implemented or overwritten in updater subclasses.
#         """
#         self.__hostname = value
# 
#     @staticmethod
#     def configuration_key_prefix():
#         """
#         Return a human readable string classifying this class as an updater.
# 
#         Should not be be implemented or overwritten in updater subclasses.
#         """
#         return "updater"
# 
#     def update(self, ip):
#         """
#         Update the hostname on the remote service.
# 
#         Abstract method, must be implemented in subclass.
#         """
#         raise NotImplementedError("Please implement in subclass")
# 
# Path: dyndnsc/common/constants.py
# REQUEST_HEADERS_DEFAULT = {
#     # dyndns2 standard requires that we set our own user agent:
#     "User-Agent": "python-dyndnsc/%s" % __version__,
# }


from logging import getLogger
from .base import UpdateProtocol
from ..common import constants
import requests

LOG = getLogger(__name__)


class UpdateProtocolDyndns2(UpdateProtocol):
    """Updater for services compatible with the dyndns2 protocol."""

    configuration_key = "dyndns2"

    def __init__(self, hostname, userid, password, url, *args, **kwargs):
        """
        Initialize.

        :param hostname: the fully qualified hostname to be managed
        :param userid: the userid for identification
        :param password: the password for authentication
        :param url: the API URL for updating the DNS entry
        """
        self.hostname = hostname
        self.__userid = userid
        self.__password = password
        self._updateurl = url

        super(UpdateProtocolDyndns2, self).__init__()

    def update(self, ip):
        """Update the IP on the remote service."""
        timeout = 60
        LOG.debug("Updating '%s' to '%s' at service '%s'", self.hostname, ip, self._updateurl)
        params = {"myip": ip, "hostname": self.hostname}

# Path: dyndnsc/updater/base.py
# class UpdateProtocol(Subject, DynamicCliMixin):
#     """Base class for all update protocols that use a simple http GET protocol."""
# 
#     theip = None
#     __hostname = None  # private place to store the property 'hostname'
#     configuration_key = None
# 
#     @property
#     def hostname(self):
#         """
#         Return the hostname managed by this updater.
# 
#         May be implemented or overwritten in updater subclasses.
#         """
#         return self.__hostname
# 
#     @hostname.setter
#     def hostname(self, value):
#         """
#         Set the hostname managed by this updater.
# 
#         May be implemented or overwritten in updater subclasses.
#         """
#         self.__hostname = value
# 
#     @staticmethod
#     def configuration_key_prefix():
#         """
#         Return a human readable string classifying this class as an updater.
# 
#         Should not be be implemented or overwritten in updater subclasses.
#         """
#         return "updater"
# 
#     def update(self, ip):
#         """
#         Update the hostname on the remote service.
# 
#         Abstract method, must be implemented in subclass.
#         """
#         raise NotImplementedError("Please implement in subclass")
# 
# Path: dyndnsc/common/constants.py
# REQUEST_HEADERS_DEFAULT = {
#     # dyndns2 standard requires that we set our own user agent:
#     "User-Agent": "python-dyndnsc/%s" % __version__,
# }


# Path: dyndnsc/updater/dyndns2.py
from logging import getLogger
from .base import UpdateProtocol
from ..common import constants
import requests


LOG = getLogger(__name__)


class UpdateProtocolDyndns2(UpdateProtocol):
    """Updater for services compatible with the dyndns2 protocol."""

    configuration_key = "dyndns2"

    def __init__(self, hostname, userid, password, url, *args, **kwargs):
        """
        Initialize.

        :param hostname: the fully qualified hostname to be managed
        :param userid: the userid for identification
        :param password: the password for authentication
        :param url: the API URL for updating the DNS entry
        """
        self.hostname = hostname
        self.__userid = userid
        self.__password = password
        self._updateurl = url

        super(UpdateProtocolDyndns2, self).__init__()

    def update(self, ip):
        """Update the IP on the remote service."""
        timeout = 60
        LOG.debug("Updating '%s' to '%s' at service '%s'", self.hostname, ip, self._updateurl)
        params = {"myip": ip, "hostname": self.hostname}

        req = requests.get(self._updateurl, params=params, headers=constants.REQUEST_HEADERS_DEFAULT,