Skip to content

Commit

Permalink
Initial, incomplete, terribly basic code! :D
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Kelly committed Nov 29, 2011
0 parents commit 2f8953b
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 0 deletions.
27 changes: 27 additions & 0 deletions LICENSE
@@ -0,0 +1,27 @@
Copyright (c) 2011, Mozilla.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

3. Neither the name of jingo nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 2 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,2 @@
include LICENSE
include README.rstx
19 changes: 19 additions & 0 deletions README.rst
@@ -0,0 +1,19 @@
Basket-Client
-------------

Basket-Client is a small library for subscribing users to mailing lists through `Basket<https://github.com/mozilla/basket>`.

Usage
=====

from basket import subscribe

subscribe('user@example.com', ['basket-email-list-id'])

See `the Basket documentation<https://github.com/mozilla/basket/tree/master/apps/news>` for more information.

Settings
========

BASKET_URL
URL to basket server, e.g. `basket.mozilla.com`
1 change: 1 addition & 0 deletions basket/__init__.py
@@ -0,0 +1 @@
from base import subscribe
38 changes: 38 additions & 0 deletions basket/base.py
@@ -0,0 +1,38 @@
import json

from django.conf import settings

import requests


class BasketException(Exception):
pass


def subscribe(email, newsletters, **kwargs):
kwargs.update(email=email, newsletters=newsletters)
return _post('subscribe', kwargs)

def _url(path):
return 'https://%s/news/%s/' % (settings.BASKET_URL, path)


def _post(path, data):
return _parse_response(requests.post(_url(path), data=data))


def _get(path, data):
return _parse_response(requests.get(_url(path), data=data))


def _parse_response(response):
if response.error:
raise BasketException('Error connecting to %s: %s. Ensure that '
'BASKET_URL is configured correctly in your '
'settings file.' % (response.url, response.error))

response_json = json.loads(response.content)
if response_json.get('desc', None):
raise BasketException(response_json['desc'])

return response_json
27 changes: 27 additions & 0 deletions setup.py
@@ -0,0 +1,27 @@
from setuptools import setup, find_packages


setup(
name='basket',
version='0.1.0',
description='A thin, practical wrapper around terminal formatting, positioning, and more',
long_description=open('README.rst').read(),
author='Erik Rose',
author_email='erikrose@grinchcentral.com',
license='GPL',
packages=find_packages(exclude=['ez_setup']),
tests_require=['Nose'],
url='https://github.com/erikrose/blessings',
include_package_data=True,
classifiers=[
'Intended Audience :: Developers',
'Natural Language :: English',
'Environment :: Console',
'Operating System :: POSIX',
'Topic :: Software Development :: Libraries',
'Topic :: Software Development :: User Interfaces',
'Topic :: Terminals'
],
keywords=['terminal', 'tty', 'curses', 'formatting', 'color'],
**extra_setup
)

0 comments on commit 2f8953b

Please sign in to comment.