Created
December 21, 2018 21:25
-
-
Save kola-er/21cea93be9a46c3acb25106a460ca866 to your computer and use it in GitHub Desktop.
Eventbrite Migrator Custom Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from __future__ import unicode_literals | |
| import requests | |
| from migration_tools.auth_tools import AuthMigrator | |
| from migration_tools.zap_tools.migrator import ZapMigrator | |
| class EventbriteAuthMigrator(AuthMigrator): | |
| def exchange_auth_fields(self, new_auth): | |
| # Write custom code | |
| class EventbriteZapMigrator(ZapMigrator): | |
| def __init__(self): | |
| super(EventbriteZapMigrator, self).__init__() | |
| self.auth_migrator = EventbriteAuthMigrator(self.old_api, self.new_api, self.auth_migrator.app_name) | |
| def update_node_pre_changes(self, node, **kwargs): | |
| if node.is_root and node.authentication: | |
| resp = requests.get( | |
| 'https://www.eventbriteapi.com/v3/users/me/organizations/', | |
| headers={ | |
| 'Authorization': 'Bearer {}'.format( | |
| node.authentication.auth_fields['access_token'] | |
| ), | |
| 'Content-Type': 'application/json', | |
| }, | |
| ) | |
| try: | |
| node.params['organization'] = resp.json()['organizations'][0]['id'] | |
| except (IndexError, KeyError, Exception): | |
| if kwargs.get('root_paused_by_migration'): | |
| template_context = { | |
| 'node': node.dict(), | |
| 'root_node': {'id': node.id, 'fancy_title': node.fancy_title}, | |
| 'error_message': ( | |
| "your account doesn't have any organizations, " | |
| 'which Zapier needs to make requests on your behalf. ' | |
| 'To fix this, re-authorize your Eventbrite account with Zapier before trying again' | |
| ), | |
| } | |
| node.customuser.send_email( | |
| 'migration_tools/zap_paused', | |
| template_context=template_context, | |
| force=True, | |
| ) | |
| return node |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment