# Path: messagebird/serde.py
# def json_serialize(obj):
#     try:
#         return json.dumps(obj, ensure_ascii=False).encode('utf-8')
#     except TypeError:
#         return json.dumps(obj, default=lambda o: o.__dict__, ensure_ascii=False).encode('utf-8')


import requests
from enum import Enum
from messagebird.serde import json_serialize
from urllib.parse import urljoin
class ResponseFormat(Enum):
    text = 1
    binary = 2


class HttpClient:
    """Used for sending simple HTTP requests."""

    def __init__(self, endpoint, access_key, user_agent):
        self.__supported_status_codes = [200, 201, 204, 401, 404, 405, 422]

        self.endpoint = endpoint
        self.access_key = access_key
        self.user_agent = user_agent

    def request(self, path, method='GET', params=None, format=ResponseFormat.text):
        """Builds a request and gets a response."""
        if params is None:
            params = {}
        url = urljoin(self.endpoint, path)
        headers = {
            'Accept': 'application/json',
            'Authorization': 'AccessKey ' + self.access_key,
            'User-Agent': self.user_agent,
            'Content-Type': 'application/json; charset=UTF-8'
        }

        method_switcher = {
            'DELETE': lambda: requests.delete(url, verify=True, headers=headers, data=json_serialize(params)),
            'GET': lambda: requests.get(url, verify=True, headers=headers, params=params),

# Path: messagebird/serde.py
# def json_serialize(obj):
#     try:
#         return json.dumps(obj, ensure_ascii=False).encode('utf-8')
#     except TypeError:
#         return json.dumps(obj, default=lambda o: o.__dict__, ensure_ascii=False).encode('utf-8')


# Path: messagebird/http_client.py
import requests
from enum import Enum
from messagebird.serde import json_serialize
from urllib.parse import urljoin

class ResponseFormat(Enum):
    text = 1
    binary = 2


class HttpClient:
    """Used for sending simple HTTP requests."""

    def __init__(self, endpoint, access_key, user_agent):
        self.__supported_status_codes = [200, 201, 204, 401, 404, 405, 422]

        self.endpoint = endpoint
        self.access_key = access_key
        self.user_agent = user_agent

    def request(self, path, method='GET', params=None, format=ResponseFormat.text):
        """Builds a request and gets a response."""
        if params is None:
            params = {}
        url = urljoin(self.endpoint, path)
        headers = {
            'Accept': 'application/json',
            'Authorization': 'AccessKey ' + self.access_key,
            'User-Agent': self.user_agent,
            'Content-Type': 'application/json; charset=UTF-8'
        }

        method_switcher = {
            'DELETE': lambda: requests.delete(url, verify=True, headers=headers, data=json_serialize(params)),
            'GET': lambda: requests.get(url, verify=True, headers=headers, params=params),

            'PATCH': lambda: requests.patch(url, verify=True, headers=headers, data=json_serialize(params)),