python-amcards 1.3.1__tar.gz → 1.3.3__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.1
3
+ Version: 1.3.3
4
4
  Summary: A wrapper for the AMcards API.
5
5
  Home-page: https://github.com/simonesestili/python-amcards
6
6
  Author: Simone Sestili
@@ -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
 
@@ -1,3 +1,4 @@
1
+ import ast
1
2
  from enum import Enum
2
3
  from datetime import datetime
3
4
  from typing import List, Optional
@@ -494,7 +495,7 @@ class Card:
494
495
  @property
495
496
  def extra_data(self) -> dict:
496
497
  """Extra data attached to this card."""
497
- return self._gifts
498
+ return self._extra_data
498
499
 
499
500
  @classmethod
500
501
  def _from_json(cls, json: dict):
@@ -519,7 +520,7 @@ class Card:
519
520
  base_cost=gift['price'],
520
521
  shipping_and_handling_cost=gift['shipping_and_handling'],
521
522
  ) for gift in json['gifts']],
522
- extra_data=json.get('extra_data') or {},
523
+ extra_data=ast.literal_eval(json.get('extra_data') or '{}'),
523
524
  )
524
525
 
525
526
  class MailingStatus(Enum):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-amcards
3
- Version: 1.3.1
3
+ Version: 1.3.3
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.1',
10
+ version='1.3.3',
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