# Path: moira_client/client.py
# class InvalidJSONError(Exception):
#     def __init__(self, content):
#         """
# 
#         :param content: bytes response content
#         """
#         self.content = content
# 
# Path: moira_client/client.py
# class ResponseStructureError(Exception):
#     def __init__(self, msg, content):
#         """
# 
#         :param msg: str error message
#         :param content: dict response content
#         """
#         self.msg = msg
#         self.content = content
# 
# Path: moira_client/models/base.py
# class Base:
#     @property
#     def id(self):
#         return self._id
# 
#     def __repr__(self):
#         return '({} {})'.format(self.__class__.__name__, self.id)
# 
#     def __unicode__(self):
#         return u'({} {})'.format(self.__class__.__name__, self.id)
# 
#     def __eq__(self, other):
#         return self.id == other.id
# 
#     def __ne__(self, other):
#         return self.id != other.id


from ..client import InvalidJSONError
from ..client import ResponseStructureError
from .base import Base
        self.user = kwargs.get('user', None)
        self._id = kwargs.get('id', None)


class ContactManager:
    def __init__(self, client):
        self._client = client

    def add(self, value, contact_type):
        """
        Add new contact

        :param value: str contact value
        :param contact_type: str contact type (one of CONTACT_* constants)
        :return: Contact

        :raises: ResponseStructureError
        """
        data = {
            'value': value,
            'type': contact_type
        }

        contacts = self.fetch_by_current_user()
        for contact in contacts:
            if contact.value == value and contact.type == contact_type:
                return contact

        result = self._client.put(self._full_path(), json=data)
        if 'id' not in result:

# Path: moira_client/client.py
# class InvalidJSONError(Exception):
#     def __init__(self, content):
#         """
# 
#         :param content: bytes response content
#         """
#         self.content = content
# 
# Path: moira_client/client.py
# class ResponseStructureError(Exception):
#     def __init__(self, msg, content):
#         """
# 
#         :param msg: str error message
#         :param content: dict response content
#         """
#         self.msg = msg
#         self.content = content
# 
# Path: moira_client/models/base.py
# class Base:
#     @property
#     def id(self):
#         return self._id
# 
#     def __repr__(self):
#         return '({} {})'.format(self.__class__.__name__, self.id)
# 
#     def __unicode__(self):
#         return u'({} {})'.format(self.__class__.__name__, self.id)
# 
#     def __eq__(self, other):
#         return self.id == other.id
# 
#     def __ne__(self, other):
#         return self.id != other.id


# Path: moira_client/models/contact.py
from ..client import InvalidJSONError
from ..client import ResponseStructureError
from .base import Base

        self.user = kwargs.get('user', None)
        self._id = kwargs.get('id', None)


class ContactManager:
    def __init__(self, client):
        self._client = client

    def add(self, value, contact_type):
        """
        Add new contact

        :param value: str contact value
        :param contact_type: str contact type (one of CONTACT_* constants)
        :return: Contact

        :raises: ResponseStructureError
        """
        data = {
            'value': value,
            'type': contact_type
        }

        contacts = self.fetch_by_current_user()
        for contact in contacts:
            if contact.value == value and contact.type == contact_type:
                return contact

        result = self._client.put(self._full_path(), json=data)
        if 'id' not in result:

            raise ResponseStructureError('No id in response', result)