python-amcards 1.6.2__tar.gz → 1.7.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-amcards
3
- Version: 1.6.2
3
+ Version: 1.7.1
4
4
  Summary: A wrapper for the AMcards API.
5
5
  Home-page: https://github.com/simonesestili/python-amcards
6
6
  Author: Simone Sestili
@@ -1124,7 +1124,7 @@ class AMcardsClient:
1124
1124
  'birth_date': '2003-12-25', # OPTIONAL
1125
1125
  'anniversary_date': '2022-10-31', # OPTIONAL
1126
1126
  'third_party_contact_id': 'crmid1453131', # OPTIONAL
1127
- 'address_line_2': 'Apt 2' # OPTIONAL
1127
+ 'address_line_2': 'Apt 2', # OPTIONAL
1128
1128
  'extra_data': { # OPTIONAL
1129
1129
  'carMake': 'Honda', # OPTIONAL
1130
1130
  } # OPTIONAL
@@ -1136,43 +1136,44 @@ class AMcardsClient:
1136
1136
 
1137
1137
  :raises CampaignMultiSendError: When something goes wrong when attempting to send a drip campaign.
1138
1138
  :raises AuthenticationError: When the client's ``access_token`` is invalid.
1139
- :raises ShippingAddressError: When ``contacts`` is missing some `required` keys.
1140
- :raises DateFormatError: When one of the dates provided is not in ``"YYYY-MM-DD"`` format.
1141
- :raises PhoneFormatError: When the ``phone_number`` is not a digit string of length 10.
1139
+ :raises ShippingAddressError: When none of the provided contacts are valid after validation. Contacts missing required fields or with invalid optional fields are skipped.
1142
1140
  :raises InsufficientCreditsError: When the client's user has insufficient credits in their balance.
1143
1141
 
1144
1142
  """
1143
+ contacts_to_send = []
1144
+
1145
1145
  # Validate contacts
1146
- for idx, contact in enumerate(contacts):
1146
+ for contact in contacts:
1147
1147
  missings = helpers.get_missing_required_shipping_address_fields(contact)
1148
- if missings:
1149
- error_message = f'Missing the following required shipping address fields at contacts[{idx}]: ' + ', '.join(missings)
1150
- raise exceptions.ShippingAddressError(error_message)
1148
+ if not missings:
1149
+ contacts_to_send.append(contact)
1151
1150
 
1152
1151
  # Sanitize contacts
1153
- contacts = [helpers.sanitize_contact_for_campaign_multi_send(contact) for contact in contacts]
1152
+ contacts_to_send = [helpers.sanitize_contact_for_campaign_multi_send(contact) for contact in contacts_to_send]
1154
1153
 
1155
- for idx, contact in enumerate(contacts):
1154
+ valid_contacts = []
1155
+ for contact in contacts_to_send:
1156
1156
  # Validate birth_date
1157
1157
  if 'birth_date' in contact and not helpers.is_valid_birthdate(contact['birth_date']):
1158
- error_message = f'Invalid birth_date format of "{contact["birth_date"]}" for contact at contacts[{idx}], please specify date as "YYYY-MM-DD", or omit it'
1159
- raise exceptions.DateFormatError(error_message)
1158
+ continue
1160
1159
  # Validate anniversary_date
1161
1160
  if 'anniversary_date' in contact and not helpers.is_valid_date(contact['anniversary_date']):
1162
- error_message = f'Invalid anniversary_date format of "{contact["anniversary_date"]}" for contact at contacts[{idx}], please specify date as "YYYY-MM-DD", or omit it'
1163
- raise exceptions.DateFormatError(error_message)
1161
+ continue
1164
1162
  # Validate phone_number
1165
1163
  if 'phone_number' in contact and not helpers.is_valid_phone(contact['phone_number']):
1166
- error_message = f'Invalid phone_number format of "{contact["phone_number"]}" for contact at contacts[{idx}], please specify phone as a 10 number string with no special formatting (ex. 15556667777), or omit it'
1167
- raise exceptions.PhoneFormatError(error_message)
1164
+ continue
1168
1165
  if 'extra_data' in contact:
1169
1166
  contact['extra_data'] = helpers.sanitize_extra_data(contact['extra_data'])
1167
+ valid_contacts.append(contact)
1168
+
1169
+ if not valid_contacts:
1170
+ raise exceptions.ShippingAddressError('No valid contacts to send')
1170
1171
 
1171
1172
  # Build request json payload
1172
1173
  body = {
1173
1174
  'campaign_id': campaign_id,
1174
1175
  'initiator': initiator,
1175
- 'contacts': contacts,
1176
+ 'contacts': valid_contacts,
1176
1177
  }
1177
1178
 
1178
1179
  res = requests.post(f'{DOMAIN}/campaigns/open-campaign-multi-form/', json=body, headers=self._HEADERS)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-amcards
3
- Version: 1.6.2
3
+ Version: 1.7.1
4
4
  Summary: A wrapper for the AMcards API.
5
5
  Home-page: https://github.com/simonesestili/python-amcards
6
6
  Author: Simone Sestili
@@ -7,7 +7,7 @@ def README():
7
7
 
8
8
  setup(
9
9
  name='python-amcards',
10
- version='1.6.2',
10
+ version='1.7.1',
11
11
  description='A wrapper for the AMcards API.',
12
12
  long_description=README(),
13
13
  long_description_content_type='text/x-rst',
File without changes
File without changes