Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GET helper function, add custom columns to create profile #1055

Merged
merged 5 commits into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions parsons/mobilecommons/mobilecommons.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,18 @@ def _mc_get_request(
response_dict = self._parse_get_request(endpoint=endpoint, params=page_params)
# Check to see if page was empty if num parameter is available
if page_indicator == "num":
empty_page = int(response_dict["response"][first_data_key]["num"]) > 0
empty_page = int(response_dict["response"][first_data_key]["num"]) == 0

if not empty_page:
# Extract data
response_table = Table(response_dict["response"][first_data_key][second_data_key])
response_data = response_dict["response"][first_data_key][second_data_key]
# When only one row of data it is returned as dict instead of list, which
# cannot be put into table
if isinstance(response_data, dict):
response_data = [response_data]

response_table = Table(response_data)

# Append to final table
final_table.concat(response_table)
final_table.materialize()
Expand Down Expand Up @@ -347,6 +354,9 @@ def get_profiles(
custom_cols = "true" if include_custom_columns else "false"
subscriptions = "true" if include_subscriptions else "false"

if phones:
phones = ",".join(phones)

params = {
"phone_number": phones,
"from": _format_date(first_date),
Expand Down Expand Up @@ -376,9 +386,10 @@ def create_profile(
city=None,
state=None,
opt_in_path_id=None,
custom_column_values=None,
):
"""
A function for creating a single MobileCommons profile
A function for creating or updating a single MobileCommons profile

`Args:`
phone: str
Expand All @@ -400,9 +411,12 @@ def create_profile(
opt_in_path_id: str
ID of the opt-in path to send new profile through. This will determine the welcome
text they receive.
custom_column_values: dict
Dictionary with custom column names as keys and custom column values
as dictionary values

`Returns:`
ID of created profile
ID of created/updated profile
"""

params = {
Expand All @@ -418,5 +432,8 @@ def create_profile(
**self.default_params,
}

if custom_column_values:
params = params.merge(custom_column_values)

response = self._mc_post_request("profile_update", params=params)
return response["profile"]["id"]
Loading