|
2 | 2 |
|
3 | 3 | """Container for all creative management logic used by the Ads API SDK.""" |
4 | 4 |
|
| 5 | +import json |
5 | 6 | from requests.exceptions import HTTPError |
6 | 7 | from twitter_ads import API_VERSION |
7 | 8 | from twitter_ads.cursor import Cursor |
@@ -595,3 +596,39 @@ def all(klass, account, **kwargs): |
595 | 596 | resource = klass.RESOURCE_COLLECTION.format(account_id=account.id) |
596 | 597 | request = Request(account.client, 'get', resource, params=kwargs) |
597 | 598 | return Cursor(None, request) |
| 599 | + |
| 600 | + |
| 601 | +class Card(Resource): |
| 602 | + |
| 603 | + PROPERTIES = {} |
| 604 | + |
| 605 | + RESOURCE_COLLECTION = '/' + API_VERSION + '/accounts/{account_id}/cards' |
| 606 | + |
| 607 | + @classmethod |
| 608 | + def create(klass, account, name, components): |
| 609 | + method = 'post' |
| 610 | + resource = klass.RESOURCE_COLLECTION.format(account_id=account.id) |
| 611 | + headers = {'Content-Type': 'application/json'} |
| 612 | + payload = {'name': name, 'components': components} |
| 613 | + response = Request( |
| 614 | + account.client, method, resource, |
| 615 | + headers=headers, body=json.dumps(payload) |
| 616 | + ).perform() |
| 617 | + return klass(account).from_response(response.body['data']) |
| 618 | + |
| 619 | + def load(klass): |
| 620 | + raise AttributeError("'Card' object has no attribute 'load'") |
| 621 | + |
| 622 | + def reload(klass): |
| 623 | + raise AttributeError("'Card' object has no attribute 'reload'") |
| 624 | + |
| 625 | + |
| 626 | +# card properties |
| 627 | +# read-only |
| 628 | +resource_property(Card, 'card_uri', readonly=True) |
| 629 | +resource_property(Card, 'created_at', readonly=True, transform=TRANSFORM.TIME) |
| 630 | +resource_property(Card, 'deleted', readonly=True, transform=TRANSFORM.BOOL) |
| 631 | +resource_property(Card, 'updated_at', readonly=True, transform=TRANSFORM.TIME) |
| 632 | +# these are writable, but not in the sense that they can be set on an object and then saved |
| 633 | +resource_property(Card, 'name', readonly=True) |
| 634 | +resource_property(Card, 'components', readonly=True, transform=TRANSFORM.LIST) |
0 commit comments