aboutsummaryrefslogtreecommitdiffstats
path: root/brevisurl/backends/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'brevisurl/backends/base.py')
-rw-r--r--brevisurl/backends/base.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/brevisurl/backends/base.py b/brevisurl/backends/base.py
new file mode 100644
index 0000000..3fc053a
--- /dev/null
+++ b/brevisurl/backends/base.py
@@ -0,0 +1,41 @@
+from abc import ABCMeta
+
+
+class BaseBrevisUrlBackend(object):
+ """Base class for brevisurl backend implementations. Subclasses must at least overwrite shorten_url()."""
+
+ __metaclass__ = ABCMeta
+
+
+ def __init__(self, fail_silently=False, **kwargs):
+ self.fail_silently = fail_silently
+ self.class_path = '{0}.{1}'.format(self.__module__, self.__class__.__name__)
+
+ def open(self):
+ """Open a network connection.
+
+ This method can be overwritten by backend implementations to
+ open a network connection.
+
+ It's up to the backend implementation to track the status of
+ a network connection if it's needed by the backend.
+
+ The default implementation does nothing.
+
+ """
+ pass
+
+ def close(self):
+ """Close a network connection."""
+ pass
+
+ def shorten_url(self, original_url):
+ """Shortens url into more compact form.
+
+ :param original_url: url that will be shortened
+ :type original_url: string
+ :returns: shortened url from original url
+ :rtype: brevisurl.models.ShortUrl
+
+ """
+ raise NotImplementedError \ No newline at end of file