Created
February 26, 2018 06:53
-
-
Save housemeow/918b260024d90be1a032885f786299ba to your computer and use it in GitHub Desktop.
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 Command: | |
def redo(self, **kwargs): | |
abstract | |
def undo(self, **kwargs); | |
abstract | |
class UploadImgurCommand extend Command: | |
def redo(self, **kwargs): | |
image = kwargs['image']; | |
try: | |
return imgurApi.upload(image); | |
catch Exception as ex: | |
throw ex; | |
def undo(self, **kwargs): | |
whatever | |
class InsertToMangoCommand extend Command: | |
def redo(self, **kwargs): | |
image_url = kwargs['image_url'] | |
try: | |
return mongoApi.insert(image_url); | |
catch Exception as ex: | |
throw ex; | |
class YourApplication: | |
def upload_image(self, image): | |
command_classes = [UploadImgurCommand, InsertToMangoCommand]; | |
args = { image: image } | |
command_index = 1 | |
for command_class in command_classes: | |
command = command_class(args); | |
try: | |
args = command.redo(args) | |
catch Exception as ex: | |
whatever |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment