diff --git a/diff.txt b/diff.txt new file mode 100644 index 0000000..c80f938 --- /dev/null +++ b/diff.txt @@ -0,0 +1,122 @@ +diff --git a/invoice_ninja/__init__.py b/invoice_ninja/__init__.py +index e24c1be..ae1c40c 100644 +--- a/invoice_ninja/__init__.py ++++ b/invoice_ninja/__init__.py +@@ -1 +1,24 @@ +-from invoice_ninja.invoice_ninja import InvoiceNinja ++from invoice_ninja.endpoints.clients import Clients ++ ++class InvoiceNinja(object): ++ def __init__(self, endpoint_url: str = 'https://invoicing.co', ++ api_token: str = str()): ++ self._endpoint_url = endpoint_url ++ self._api_token = api_token ++ ++ @property ++ def endpoint_url(self): ++ return self._endpoint_url ++ ++ @endpoint_url.setter ++ def endpoint_url(self, endpoint_url: str): ++ self._endpoint_url = endpoint_url ++ ++ @property ++ def api_token(self): ++ return self._api_token ++ ++ @api_token.setter ++ def api_token(self, api_token: str): ++ self._api_token = api_token ++ +diff --git a/invoice_ninja/endpoints/clients.py b/invoice_ninja/endpoints/clients.py +index 7d71fff..cacde09 100644 +--- a/invoice_ninja/endpoints/clients.py ++++ b/invoice_ninja/endpoints/clients.py +@@ -5,11 +5,7 @@ import requests + + class Clients(BaseEndpoint): + uri = '/api/v1/clients' +- +- def __init__(self, base_url: str = str(), api_token: str = str()): +- super().__init__(base_url, api_token) +- self.url = super()._get_url_for('clients') +- ++ + def __build_sort_params(self, sort: dict): + sort_params = {'sort': str()} + is_first_entry = True +diff --git a/invoice_ninja/invoice_ninja.py b/invoice_ninja/invoice_ninja.py +deleted file mode 100644 +index 761941e..0000000 +--- a/invoice_ninja/invoice_ninja.py ++++ /dev/null +@@ -1,69 +0,0 @@ +-import requests +- +-class InvoiceNinja(object): +- API_V1 = 'api/v1' +- +- def __init__(self, +- endpoint_url: str = 'https://invoicing.co', +- api_token: str = str()): +- self.endpoint_url = '{}/{}'.format(endpoint_url, self.API_V1) +- self.api_token = api_token +- self.headers = dict() +- +- def set_url(self, url: str): +- self.endpoint_url = url +- +- def get_url(self): +- return self.endpoint_url +- +- def set_token(self, token: str): +- self.api_token = token +- +- def get_token(self): +- return self.api_token +- +- def get_headers(self): +- """Get HTTP headers for request.""" +- +- return self.headers +- +- def add_headers(self, headers: dict): +- """Add HTTP headers to request.""" +- +- self.headers.update(headers) +- +- def build_headers(self): +- """Build Invoice Ninja API headers for request. +- +- A header dictionary with the API token is returned by default. +- """ +- +- headers = { +- 'X-API-TOKEN': self.api_token, +- 'X-Requested-With': 'XMLHttpRequest'} +- +- return self.headers.update(headers) +- +- def send(self, uri: str, payload: dict, method: str = 'get'): +- url = '{}/{}'.format(self.endpoint_url, uri) +- +- if method == 'get': +- return requests.get(url, params=payload) +- +- if method == 'post': +- return requests.post(url, params=payload) +- +- +- def ping(self): +- ''' +- Ping Invoice Ninja instance. +- ''' +- server_response = requests.get(url=self._get_url_for(), +- headers=self.build_headers()) +- +- if server_response.ok: +- return True +- +- else: +- return False +- diff --git a/invoice_ninja/__init__.py b/invoice_ninja/__init__.py index e24c1be..ae1c40c 100644 --- a/invoice_ninja/__init__.py +++ b/invoice_ninja/__init__.py @@ -1 +1,24 @@ -from invoice_ninja.invoice_ninja import InvoiceNinja +from invoice_ninja.endpoints.clients import Clients + +class InvoiceNinja(object): + def __init__(self, endpoint_url: str = 'https://invoicing.co', + api_token: str = str()): + self._endpoint_url = endpoint_url + self._api_token = api_token + + @property + def endpoint_url(self): + return self._endpoint_url + + @endpoint_url.setter + def endpoint_url(self, endpoint_url: str): + self._endpoint_url = endpoint_url + + @property + def api_token(self): + return self._api_token + + @api_token.setter + def api_token(self, api_token: str): + self._api_token = api_token + diff --git a/invoice_ninja/endpoints/clients.py b/invoice_ninja/endpoints/clients.py index 7d71fff..cacde09 100644 --- a/invoice_ninja/endpoints/clients.py +++ b/invoice_ninja/endpoints/clients.py @@ -5,11 +5,7 @@ import requests class Clients(BaseEndpoint): uri = '/api/v1/clients' - - def __init__(self, base_url: str = str(), api_token: str = str()): - super().__init__(base_url, api_token) - self.url = super()._get_url_for('clients') - + def __build_sort_params(self, sort: dict): sort_params = {'sort': str()} is_first_entry = True diff --git a/invoice_ninja/endpoints/ping.py b/invoice_ninja/endpoints/ping.py new file mode 100644 index 0000000..a6b2e1b --- /dev/null +++ b/invoice_ninja/endpoints/ping.py @@ -0,0 +1,10 @@ +from invoice_ninja.endpoints.base_endpoint import BaseEndpoint + +import requests + +class Ping(BaseEndpoint): + uri = '/api/v1/ping' + + def ping(self): + pass + diff --git a/invoice_ninja/http_client.py b/invoice_ninja/http_client.py new file mode 100644 index 0000000..839f905 --- /dev/null +++ b/invoice_ninja/http_client.py @@ -0,0 +1,57 @@ +import requests + +class HTTPClient(object): + """HTTP client for Invoice Ninja REST API.""" + + def __init__(self, endpoint_url: str = 'https://invoicing.co', + api_token: str = str()): + self._endpoint_url = 'https://invoicing.co' + self._api_token = str() + self._headers = dict() + + @property + def endpoint_url(self): + return self._endpoint_url + + @endpoint_url.setter + def endpoint_url(self, endpoint_url: str): + self._endpoint_url = endpoint_url + + @property + def api_token(self): + return self._api_token + + @api_token.setter + def api_token(self, api_token: str): + self._api_token = api_token + + def add_headers(self, headers: dict): + """Add HTTP headers to request.""" + + self._headers.update(headers) + + def build_headers(self): + """Build Invoice Ninja API headers for request. + + A header dictionary with the API token is returned by default. + """ + + headers = { + 'X-API-TOKEN': _api_token, + 'X-Requested-With': 'XMLHttpRequest'} + + return self._headers.update(headers) + + def send(self, uri: str, + payload: dict, + method: str = 'get'): + """Send request to Invoice Ninja REST API.""" + + url = '{}/{}'.format(endpoint_url, uri) + + if method == 'get': + return requests.get(url, params=payload) + + elif method == 'post': + return requests.post(url, params=payload) + diff --git a/invoice_ninja/http_client/http_client.py b/invoice_ninja/http_client/http_client.py new file mode 100644 index 0000000..bbc51af --- /dev/null +++ b/invoice_ninja/http_client/http_client.py @@ -0,0 +1,57 @@ +import requests + +class HTTPClient(object): + """HTTP client for Invoice Ninja REST API.""" + + def __init__(self, endpoint_url: str = 'https://invoicing.co', + api_token: str = str()): + self_endpoint_url = 'https://invoicing.co' + self._api_token = str() + self._headers = dict() + + @property + def endpoint_url(self): + return self._endpoint_url + + @endpoint_url.setter + def endpoint_url(self, endpoint_url: str): + self._endpoint_url = endpoint_url + + @property + def api_token(self): + return self._api_token + + @api_token.setter + def api_token(self, api_token: str): + self._api_token = api_token + + def add_headers(self, headers: dict): + """Add HTTP headers to request.""" + + self._headers.update(headers) + + def build_headers(self): + """Build Invoice Ninja API headers for request. + + A header dictionary with the API token is returned by default. + """ + + headers = { + 'X-API-TOKEN': _api_token, + 'X-Requested-With': 'XMLHttpRequest'} + + return self._headers.update(headers) + + def send(self, uri: str, + payload: dict, + method: str = 'get'): + """Send request to Invoice Ninja REST API.""" + + url = '{}/{}'.format(endpoint_url, uri) + + if method == 'get': + return requests.get(url, params=payload) + + elif method == 'post': + return requests.post(url, params=payload) + diff --git a/invoice_ninja/invoice_ninja.py b/invoice_ninja/invoice_ninja.py deleted file mode 100644 index 761941e..0000000 --- a/invoice_ninja/invoice_ninja.py +++ /dev/null @@ -1,69 +0,0 @@ -import requests - -class InvoiceNinja(object): - API_V1 = 'api/v1' - - def __init__(self, - endpoint_url: str = 'https://invoicing.co', - api_token: str = str()): - self.endpoint_url = '{}/{}'.format(endpoint_url, self.API_V1) - self.api_token = api_token - self.headers = dict() - - def set_url(self, url: str): - self.endpoint_url = url - - def get_url(self): - return self.endpoint_url - - def set_token(self, token: str): - self.api_token = token - - def get_token(self): - return self.api_token - - def get_headers(self): - """Get HTTP headers for request.""" - - return self.headers - - def add_headers(self, headers: dict): - """Add HTTP headers to request.""" - - self.headers.update(headers) - - def build_headers(self): - """Build Invoice Ninja API headers for request. - - A header dictionary with the API token is returned by default. - """ - - headers = { - 'X-API-TOKEN': self.api_token, - 'X-Requested-With': 'XMLHttpRequest'} - - return self.headers.update(headers) - - def send(self, uri: str, payload: dict, method: str = 'get'): - url = '{}/{}'.format(self.endpoint_url, uri) - - if method == 'get': - return requests.get(url, params=payload) - - if method == 'post': - return requests.post(url, params=payload) - - - def ping(self): - ''' - Ping Invoice Ninja instance. - ''' - server_response = requests.get(url=self._get_url_for(), - headers=self.build_headers()) - - if server_response.ok: - return True - - else: - return False -