Skip to content

Commit

Permalink
Hopefully last linting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdelrio committed Sep 27, 2023
1 parent 6d224a7 commit 5aab418
Showing 1 changed file with 47 additions and 39 deletions.
86 changes: 47 additions & 39 deletions parsons/mobilecommons/mobilecommons.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@

MC_URI = "https://secure.mcommons.com/api/"
DATE_FMT = "%Y-%m-%d"
format_date = lambda x: parse_date(x).strftime(DATE_FMT) if x is not None else None


def _format_date(user_entered_date):
if user_entered_date:
formatted_date = parse_date(user_entered_date).strftime(DATE_FMT)
else:
formatted_date = None
return formatted_date


class MobileCommons:
"""
Expand All @@ -42,13 +50,13 @@ def __init__(self, username=None, password=None, company_id=None):
self.client = APIConnector(uri=MC_URI, auth=(self.username, self.password))

def _mc_get_request(
self,
endpoint,
first_data_key,
second_data_key,
params,
elements_to_unpack=None,
limit=None,
self,
endpoint,
first_data_key,
second_data_key,
params,
elements_to_unpack=None,
limit=None,
):
"""
A function for GET requests that handles MobileCommons xml responses and pagination
Expand Down Expand Up @@ -138,7 +146,7 @@ def _mc_get_request(
page += 1
page_params = {"page": str(page), **params}
logger.info(
f"Fetching rows {(page - 1) * page_limit + 1} - {(page)*page_limit} "
f"Fetching rows {(page - 1) * page_limit + 1} - {(page) * page_limit} "
f"of {limit}"
)
# Send get request
Expand Down Expand Up @@ -224,7 +232,7 @@ def _mc_post_request(self, endpoint, params):
raise HTTPError(response_dict["response"]["error"])

def get_broadcasts(
self, first_date=None, last_date=None, status=None, campaign_id=None, limit=None
self, first_date=None, last_date=None, status=None, campaign_id=None, limit=None
):
"""
A function for get broadcasts
Expand All @@ -246,8 +254,8 @@ def get_broadcasts(
"""

params = {
"start_time": format_date(first_date),
"end_time": format_date(last_date),
"start_time": _format_date(first_date),
"end_time": _format_date(last_date),
"campaign_id": campaign_id,
"status": status,
**self.default_params,
Expand All @@ -263,12 +271,12 @@ def get_broadcasts(
)

def get_campaign_subscribers(
self,
campaign_id: int,
first_date: str = None,
last_date: str = None,
opt_in_path_id: int = None,
limit: int = None,
self,
campaign_id: int,
first_date: str = None,
last_date: str = None,
opt_in_path_id: int = None,
limit: int = None,
):
"""
A function for getting subscribers of a specified campaign
Expand All @@ -294,8 +302,8 @@ def get_campaign_subscribers(

params = {
"campaign_id": campaign_id,
"from": format_date(first_date),
"to": format_date(last_date),
"from": _format_date(first_date),
"to": _format_date(last_date),
"opt_in_path_id": opt_in_path_id,
**self.default_params,
}
Expand All @@ -309,13 +317,13 @@ def get_campaign_subscribers(
)

def get_profiles(
self,
phones: list = None,
first_date: str = None,
last_date: str = None,
include_custom_columns: bool = False,
include_subscriptions: bool = False,
limit: int = None,
self,
phones: list = None,
first_date: str = None,
last_date: str = None,
include_custom_columns: bool = False,
include_subscriptions: bool = False,
limit: int = None,
):
"""
A function for getting profiles, which are MobileCommons people records
Expand Down Expand Up @@ -346,8 +354,8 @@ def get_profiles(

params = {
"phone_number": phones,
"from": format_date(first_date),
"to": format_date(last_date),
"from": _format_date(first_date),
"to": _format_date(last_date),
"include_custom_columns": custom_cols,
"include_subscriptions": subscriptions,
**self.default_params,
Expand All @@ -363,16 +371,16 @@ def get_profiles(
)

def create_profile(
self,
phone,
first_name=None,
last_name=None,
zip=None,
addressline1=None,
addressline2=None,
city=None,
state=None,
opt_in_path_id=None,
self,
phone,
first_name=None,
last_name=None,
zip=None,
addressline1=None,
addressline2=None,
city=None,
state=None,
opt_in_path_id=None,
):
"""
A function for creating a single MobileCommons profile
Expand Down

0 comments on commit 5aab418

Please sign in to comment.