# Path: invoiced/util.py
# def build_objects(_class, objects):
# def convert_to_object(_class, values):
# def uri_encode(params):
# def _url_encode(value):
# def _flatten_params(params, parent_key=None):
# def _flatten_params_array(value, calculated_key):


from inflection import (pluralize, underscore)
from invoiced import util
import json
import re

class CreatableObject(InvoicedObject):

    def create(self, idempotency_key=None, **params):
        opts = {'idempotency_key': idempotency_key}
        response = self._client.request('POST', self.endpoint(), params, opts)

        return util.convert_to_object(self, response['body'])


class DeletableObject(InvoicedObject):

    def delete(self):
        response = self._client.request('DELETE', self.endpoint())

        if response['code'] == 204:
            self.refresh_from({'id': self.id})
        elif response['code'] == 200:
            # update the local values with the response
            self.refresh_from(response['body'])

        return response['code'] == 204 or response['code'] == 200


class ListableObject(InvoicedObject):

    def list(self, **opts):
        response = self._client.request('GET', self.endpoint(), opts)

        # build objects

# Path: invoiced/util.py
# def build_objects(_class, objects):
# def convert_to_object(_class, values):
# def uri_encode(params):
# def _url_encode(value):
# def _flatten_params(params, parent_key=None):
# def _flatten_params_array(value, calculated_key):


# Path: invoiced/operations.py
from inflection import (pluralize, underscore)
from invoiced import util
import json
import re


class CreatableObject(InvoicedObject):

    def create(self, idempotency_key=None, **params):
        opts = {'idempotency_key': idempotency_key}
        response = self._client.request('POST', self.endpoint(), params, opts)

        return util.convert_to_object(self, response['body'])


class DeletableObject(InvoicedObject):

    def delete(self):
        response = self._client.request('DELETE', self.endpoint())

        if response['code'] == 204:
            self.refresh_from({'id': self.id})
        elif response['code'] == 200:
            # update the local values with the response
            self.refresh_from(response['body'])

        return response['code'] == 204 or response['code'] == 200


class ListableObject(InvoicedObject):

    def list(self, **opts):
        response = self._client.request('GET', self.endpoint(), opts)

        # build objects

        objects = util.build_objects(self, response['body'])