Skip to content

Instantly share code, notes, and snippets.

@cooncesean
Created January 30, 2014 04:16
Show Gist options
  • Save cooncesean/8702552 to your computer and use it in GitHub Desktop.
Save cooncesean/8702552 to your computer and use it in GitHub Desktop.
Synchronizer configuration.
class BaseSynchronizer(object):
"""
Provides a common interface that subclasses will implement based on the
external API that they are dealing with.
"""
def authenticate(self, *args, **kwargs):
" Authenticate against the external service. "
raise NotImplementedError
def push_data(self, crud_option, content_object):
" Push data to an external service. "
raise NotImplementedError
def pull_data(self, user, content_type):
" Pull data from an external service - and update object on our side. "
raise NotImplementedError
from base import BaseSynchronizer
from some_api.client import Client
class ServiceSpecificSynchronizer(BaseSynchronizer):
"""
This Sychronizer class specific deals with a single external service.
There can be many of these and their job is to encapsulate the logic
needed to authenticate and make API calls against the service while
providing a common interface for our code to call.
... this is all just psuedocode ...
"""
client = None
def authenticate(self, token):
" Authenticate against a specific external service. "
self.client = Client(token)
def push_data(self, crud_option, content_object):
" Push data to the specific external service. "
if crud_option == 'create':
self.client.create(content_object)
elif crud_option == 'update':
self.client.update(content_object)
elif crud_option == 'remove':
self.client.remove(content_object)
def pull_data(self, user, content_type):
" Fetch data from the external service for the user and the specified content_type. "
response = self.client.read(user, content_type)
# Update the appropriate content objects on our end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment