Initial commit

This commit is contained in:
2023-09-10 13:04:17 -04:00
commit a0498a3774
72 changed files with 1230 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
# Python Invoice Ninja library
#from all_paw_care.invoice_ninja import swagger_client
#from all_paw_care.swagger_client.rest import ApiException
# Invoice Ninja library dependencies
#from __future__ import print_function
#import time
#from pprint import pprint
BASE_URL='https://invoice.allpawcare.com/api/v1'
API_TOKEN='r4AKEz9xRgk2SA7IotAvLrj64f7s0BczLDVjVwmjiPWeyG0fpu2eyib4VKI23QNO'
INVOICE_NINJA_USERNAME = 'billing@allpawcare.com'
INVOICE_NINJA_PASSWORD = """sw'1eMqN6#9fO!3"RY$L"""
INVOICE_NINJA_LOGIN_DICT = {
'email': INVOICE_NINJA_USERNAME,
'pasword': INVOICE_NINJA_PASSWORD
}
#invoice_ninja = swagger_client()

View File

@@ -0,0 +1,94 @@
from all_paw_care.invoice_ninja import API_TOKEN
from all_paw_care.invoice_ninja import BASE_URL
from all_paw_care.invoice_ninja.mappings.client import Client
import requests
class Clients(object):
CLIENTS_URL = '{}/clients'.format(BASE_URL)
HEADERS = {'X-API-TOKEN': API_TOKEN}
def __build_sort_params(self, sort: dict):
sort_params = {'sort': str()}
is_first_entry = True
for option in sort.keys():
if is_first_entry:
sort_params['sort'] += '{}|{}'.format(option, sort[option])
is_first_entry = False
else:
sort_params['sort'] += ' {}|{}'.format(option, sort[option])
return sort_params
def __client_from_dict(self, client: dict):
return Client(client_id=client['id'],
name=client['name'],
address=client['address1'],
city=client['city'],
state=client['state'],
postal_code=client['postal_code'],
phone=client['phone'],
email=client['contacts'][0]['email'],
pets=client['custom_value1'])
def __clients_from_response(self, response: requests.Response):
clients = list()
for client_dict in response.json()['data']:
clients.append(self.__client_from_dict(client_dict))
return clients
def list_client(self, client_id: str = None):
"""
Get client based on client id.
"""
if client_id:
request_url = '{}/{}'.format(self.CLIENTS_URL, client_id)
response = requests.get(url=request_url,
headers=self.HEADERS)
if response.ok:
return self.__client_from_dict(response.json()['data'])
return None
def list_clients(self, include: str = 'activities',
sort: dict = dict(), status: str = 'active',
name: str = None):
"""
Get list of clients.
"""
request_params = dict()
# Add sort parameters to request
if len(sort) > 0:
request_params.update(self.__build_sort_params(sort))
# Add include parameters to request
request_params.update({'include': include})
# Add status parameters to request
request_params.update({'status': status})
# Add name parameters to request
if name:
request_params.update({'name': name})
# Check is request should be sent with parameters
if len(request_params) > 0:
response = requests.get(url=self.CLIENTS_URL,
params=request_params,
headers=self.HEADERS)
else:
response = requests.get(url=self.CLIENTS_URL,
headers=self.HEADERS)
if response.ok:
return self.__clients_from_response(response)
else:
return None

View File

@@ -0,0 +1,15 @@
class Sort(object):
def __init__(self, id: str = None,
name: str = None,
balance: str = None):
self.sort_params = {'sort': str()}
is_first_entry = True
if id:
if is_first_entry:
self.sort_params['sort'] += '{}|{}'.format(option, sort[option])
is_first_entry = False
else:
self.sort_params['sort'] += ' {}|{}'.format(option, sort[option])

View File

@@ -0,0 +1,54 @@
class Client(object):
def __init__(self, client_id: int = None, name: str = None,
address: str = None, city: str = None, state: str = None,
postal_code: str = None, phone: str = None,
email: str = None, pets: str = None):
self.id = client_id
self.name = name
self.address = address
self.city = city
self.state = state
self.postal_code = postal_code
self.phone = phone
self.email = email
self.pets = pets
def __str__(self):
return 'Client({}, {}, {}, {}, {}, {}, {}, {}, {})'.format(
self.id,
self.name,
self.address,
self.city,
self.state,
self.postal_code,
self.phone,
self.email,
self.pets
)
def get_name(self):
return self.name
def get_id(self):
return self.id
def get_address(self):
return self.address
def get_city(self):
return self.city
def get_state(self):
return self.state
def get_postal_code(self):
return self.postal_code
def get_phone(self):
return self.postal_code
def get_email(self):
return self.email