From 0bc6905e79392519b1e2cd8616555c8b3a36bf2d Mon Sep 17 00:00:00 2001 From: Rick Ross Date: Mon, 4 Mar 2024 10:30:18 -0800 Subject: [PATCH] Added get_all() to the business and campaign classes --- lib_af_api/business.py | 34 ++++++++++++++++++++++++++++++++++ lib_af_api/campaign.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/lib_af_api/business.py b/lib_af_api/business.py index ce519c7..e31fdb4 100644 --- a/lib_af_api/business.py +++ b/lib_af_api/business.py @@ -21,6 +21,40 @@ class Business(): self.jwt = jwt + def get_all(self, args = None): + """ + get_all Get the businesses + + :param args: Dict of args to add as URL params + """ + + # Set the headers for the request + headers = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + 'Authorization': f'Bearer {self.jwt}' + } + + if not isinstance(args, dict): + args = {} + + # Run the GET + response = requests.get( + f'{self.base_url}/api/v1/businesses', + params=args, + headers=headers, + timeout=300 + ) + + # Good response. Return Events + if response.ok: + return response.json() + + # Log error and return null + logging.error("[AFBUSINESS GET ALL] [%s]", response.text) + return None + + def get(self, business_key): """ get Get the business diff --git a/lib_af_api/campaign.py b/lib_af_api/campaign.py index 0738ce8..39e6c7e 100644 --- a/lib_af_api/campaign.py +++ b/lib_af_api/campaign.py @@ -21,6 +21,40 @@ class Campaign(): self.jwt = jwt + def get_all(self, args = None): + """ + get_all Get the campaigns + + :param args: Dict of args to add as URL params + """ + + # Set the headers for the request + headers = { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + 'Authorization': f'Bearer {self.jwt}' + } + + if not isinstance(args, dict): + args = {} + + # Run the GET + response = requests.get( + f'{self.base_url}/api/v1/campaigns', + params=args, + headers=headers, + timeout=300 + ) + + # Good response. Return Events + if response.ok: + return response.json() + + # Log error and return null + logging.error("[AFCAMPAIGN GET ALL] [%s]", response.text) + return None + + def get(self, campaign_key): """ get Get the campaign