python-amcards 1.3.2__tar.gz → 1.3.4__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.1
2
2
  Name: python-amcards
3
- Version: 1.3.2
3
+ Version: 1.3.4
4
4
  Summary: A wrapper for the AMcards API.
5
5
  Home-page: https://github.com/simonesestili/python-amcards
6
6
  Author: Simone Sestili
@@ -78,13 +78,27 @@ def get_missing_required_shipping_address_fields(shipping_address: dict) -> list
78
78
  return missings
79
79
 
80
80
  def is_valid_date(date: str) -> bool:
81
- if not isinstance(date, str): return False
82
- if len(date) != 10: return False
83
- if date.count('-') != 2 or date[4] != '-' or date[7] != '-': return False
84
- for part in date.split('-'):
85
- if not part.isdigit():
86
- return False
87
- return True
81
+ if not isinstance(date, str):
82
+ return False
83
+ try:
84
+ datetime.datetime.strptime(date, '%Y-%m-%d')
85
+ return True
86
+ except:
87
+ return False
88
+
89
+ def is_valid_birthdate(date: str) -> bool:
90
+ if not isinstance(date, str):
91
+ return False
92
+ try:
93
+ datetime.datetime.strptime(date, '%Y-%m-%d')
94
+ return True
95
+ except:
96
+ pass
97
+ try:
98
+ datetime.datetime.strptime(date, '%m-%d')
99
+ return True
100
+ except:
101
+ return False
88
102
 
89
103
  def is_valid_phone(phone: str) -> bool:
90
104
  if not isinstance(phone, str): return False
@@ -119,7 +119,9 @@ class AMcardsClient:
119
119
 
120
120
  res = requests.get(url=f'{DOMAIN}/.api/v1/credittransaction/', headers=self._HEADERS, params=params)
121
121
  if not res.ok:
122
- raise exceptions.AuthenticationError('Access token provided to client is unauthorized')
122
+ if res.status_code == 401:
123
+ raise exceptions.AuthenticationError('Access token provided to client is unauthorized')
124
+ raise exceptions.AMcardsException(f'Something went wrong when fetching credit transactions. AMcards Status Code: {res.status_code}, AMcards Body: {res.text}.')
123
125
 
124
126
  credit_transactions_json = res.json().get('objects', [])
125
127
  return [CreditTransaction._from_json(credit_transaction_json) for credit_transaction_json in credit_transactions_json]
@@ -143,7 +145,9 @@ class AMcardsClient:
143
145
 
144
146
  res = requests.get(url=f'{DOMAIN}/.api/v1/credittransaction/', headers=self._HEADERS, params=params)
145
147
  if not res.ok:
146
- raise exceptions.AuthenticationError('Access token provided to client is unauthorized')
148
+ if res.status_code == 401:
149
+ raise exceptions.AuthenticationError('Access token provided to client is unauthorized')
150
+ raise exceptions.AMcardsException(f'Something went wrong when fetching credit transaction count. AMcards Status Code: {res.status_code}, AMcards Body: {res.text}.')
147
151
 
148
152
  return res.json()['meta']['total_count']
149
153
 
@@ -161,7 +165,9 @@ class AMcardsClient:
161
165
  """
162
166
  res = requests.get(url=f'{DOMAIN}/.api/v1/template/', headers=self._HEADERS, params={'limit': limit, 'offset': skip})
163
167
  if not res.ok:
164
- raise exceptions.AuthenticationError('Access token provided to client is unauthorized')
168
+ if res.status_code == 401:
169
+ raise exceptions.AuthenticationError('Access token provided to client is unauthorized')
170
+ raise exceptions.AMcardsException(f'Something went wrong when fetching templates. AMcards Status Code: {res.status_code}, AMcards Body: {res.text}.')
165
171
 
166
172
  templates_json = res.json().get('objects', [])
167
173
  return [Template._from_json(template_json) for template_json in templates_json]
@@ -201,7 +207,9 @@ class AMcardsClient:
201
207
  """
202
208
  res = requests.get(url=f'{DOMAIN}/.api/v1/quicksendtemplate/', headers=self._HEADERS, params={'limit': limit, 'offset': skip})
203
209
  if not res.ok:
204
- raise exceptions.AuthenticationError('Access token provided to client is unauthorized')
210
+ if res.status_code == 401:
211
+ raise exceptions.AuthenticationError('Access token provided to client is unauthorized')
212
+ raise exceptions.AMcardsException(f'Something went wrong when fetching quicksends. AMcards Status Code: {res.status_code}, AMcards Body: {res.text}.')
205
213
 
206
214
  templates_json = res.json().get('objects', [])
207
215
  return [Template._from_json(template_json) for template_json in templates_json]
@@ -241,7 +249,9 @@ class AMcardsClient:
241
249
  """
242
250
  res = requests.get(url=f'{DOMAIN}/.api/v1/campaign/', headers=self._HEADERS, params={'limit': limit, 'offset': skip})
243
251
  if not res.ok:
244
- raise exceptions.AuthenticationError('Access token provided to client is unauthorized')
252
+ if res.status_code == 401:
253
+ raise exceptions.AuthenticationError('Access token provided to client is unauthorized')
254
+ raise exceptions.AMcardsException(f'Something went wrong when fetching campaigns. AMcards Status Code: {res.status_code}, AMcards Body: {res.text}.')
245
255
 
246
256
  campaigns_json = res.json().get('objects', [])
247
257
  return [Campaign._from_json(campaign_json) for campaign_json in campaigns_json]
@@ -289,7 +299,9 @@ class AMcardsClient:
289
299
 
290
300
  res = requests.get(url=f'{DOMAIN}/.api/v1/card/', headers=self._HEADERS, params=params)
291
301
  if not res.ok:
292
- raise exceptions.AuthenticationError('Access token provided to client is unauthorized')
302
+ if res.status_code == 401:
303
+ raise exceptions.AuthenticationError('Access token provided to client is unauthorized')
304
+ raise exceptions.AMcardsException(f'Something went wrong when fetching cards. AMcards Status Code: {res.status_code}, AMcards Body: {res.text}.')
293
305
 
294
306
  cards_json = res.json().get('objects', [])
295
307
  return [Card._from_json(card_json) for card_json in cards_json]
@@ -334,7 +346,9 @@ class AMcardsClient:
334
346
 
335
347
  res = requests.get(url=f'{DOMAIN}/.api/v1/card/', headers=self._HEADERS, params=params)
336
348
  if not res.ok:
337
- raise exceptions.AuthenticationError('Access token provided to client is unauthorized')
349
+ if res.status_code == 401:
350
+ raise exceptions.AuthenticationError('Access token provided to client is unauthorized')
351
+ raise exceptions.AMcardsException(f'Something went wrong when fetching card count. AMcards Status Code: {res.status_code}, AMcards Body: {res.text}.')
338
352
 
339
353
  return res.json()['meta']['total_count']
340
354
 
@@ -841,7 +855,7 @@ class AMcardsClient:
841
855
  return_address = {f'return_{key}': value for key, value in return_address.items()}
842
856
 
843
857
  # Validate birth_date
844
- if 'birth_date' in shipping_address and not helpers.is_valid_date(shipping_address['birth_date']):
858
+ if 'birth_date' in shipping_address and not helpers.is_valid_birthdate(shipping_address['birth_date']):
845
859
  error_message = 'Invalid birth_date format, please specify date as "YYYY-MM-DD", or omit it'
846
860
  raise exceptions.DateFormatError(error_message)
847
861
  # Validate anniversary_date
@@ -996,7 +1010,7 @@ class AMcardsClient:
996
1010
  return_address = {f'return_{key}': value for key, value in return_address.items()}
997
1011
 
998
1012
  # Validate birth_date
999
- if 'birth_date' in shipping_address and not helpers.is_valid_date(shipping_address['birth_date']):
1013
+ if 'birth_date' in shipping_address and not helpers.is_valid_birthdate(shipping_address['birth_date']):
1000
1014
  error_message = 'Invalid birth_date format, please specify date as "YYYY-MM-DD", or omit it'
1001
1015
  raise exceptions.DateFormatError(error_message)
1002
1016
  # Validate anniversary_date
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-amcards
3
- Version: 1.3.2
3
+ Version: 1.3.4
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.3.2',
10
+ version='1.3.4',
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