Created
January 30, 2014 04:16
-
-
Save cooncesean/8702552 to your computer and use it in GitHub Desktop.
Synchronizer configuration.
This file contains 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
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 | |
This file contains 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 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