diff --git a/__init__.py b/__init__.py index 2cf4ddf..e69de29 100644 --- a/__init__.py +++ b/__init__.py @@ -1,3 +0,0 @@ -from .classes.migration import Migrate - -print("Hello World!") \ No newline at end of file diff --git a/classes/migration.py b/classes/migration.py index 360f209..7aca2e6 100644 --- a/classes/migration.py +++ b/classes/migration.py @@ -1,6 +1,6 @@ # imports import requests -from auth import Auth +from .auth import Auth class Migrate(): """ Migrate data to HubSpot """ @@ -35,28 +35,29 @@ def get_data(self, params): return data - def post_data(self, data): + def post_data(self, data, path): """ Post data to path Arguments: data {dict} -- Data to post to path """ - response = requests.post(self.path, json=data, headers=self.headers) + url = f"{self.base_path}/{path}" + response = requests.post(url, json=data, headers=self.headers) if response.status_code in self.status_codes: - print(f"Successfully posted data to {self.path} 🎉") + print(f"Successfully posted data to {url} 🎉") else: - print(f"Error posting data to {self.path}: {response.status_code} - {response.text} ❌") + print(f"Error posting data to {url}: {response.status_code} - {response.text} ❌") return response - def patch_data(self, data, id=None): + def patch_data(self, data, path, id=None): """ Patch data to path Arguments: data {dict} -- Data to patch to path id {str} -- ID of the data to patch """ - url = f"{self.path}/{id}" + url = f"{path}/{id}" response = requests.patch(url, json=data, headers=self.headers) if response.status_code in self.status_codes: print(f"Successfully put data to {url} 🎉") @@ -65,13 +66,13 @@ def patch_data(self, data, id=None): return response - def delete_data(self, id=None): + def delete_data(self, path, id=None): """ Delete data from path Arguments: id {str} -- ID of the data to delete """ - url = f"{self.path}/{id}" + url = f"{path}/{id}" response = requests.delete(url, headers=self.headers) if response.status_code in self.status_codes: print(f"Successfully deleted data from {url} with ID: {id} 🎉") diff --git a/client.py b/client.py new file mode 100644 index 0000000..9956546 --- /dev/null +++ b/client.py @@ -0,0 +1,61 @@ +from .classes.migration import Migrate + +class MigrationClient: + def __init__(self, config, hubspot): + self.migrate = Migrate(dict, config, hubspot) + + + # Migrate contacts + def migrate_contact(self, data): + """ Migrate contact to HubSpot + + Arguments: + data {dict} -- Data to migrate to HubSpot + """ + return self.migrate.post_data(data, 'contacts') + + def update_contact(self, data, contact_id): + """ Update contact in HubSpot + + Areguments: + data {dict} -- Data to update in HubSpot + contact_id {str} -- ID of the contact to update + """ + return self.migrate.put_data(data, contact_id, 'contacts') + + def delete_contact(self, contact_id): + """ Delete contact in HubSpot + + Arguments: + contact_id {str} -- ID of the contact to delete + """ + return self.migrate.delete_data(contact_id, 'contacts') + + + # Migrate companies + def migrate_company(self, data): + """ Migrate company to HubSpot + + Arguments: + data {dict} -- Data to migrate to HubSpot + """ + return self.migrate.post_data(data, 'companies') + + def update_company(self, data, company_id): + """ Update company in HubSpot + + Areguments: + data {dict} -- Data to update in HubSpot + company_id {str} -- ID of the company to update + """ + return self.migrate.put_data(data, company_id, 'companies') + + def delete_company(self, company_id): + """ Delete company in HubSpot + + Arguments: + company_id {str} -- ID of the company to delete + """ + return self.migrate.delete_data(company_id, 'companies') + +