Skip to content

Commit

Permalink
Merge pull request #26 from bensternthal/1054365-Move-to-RTD
Browse files Browse the repository at this point in the history
Fix Bug 1054365: Basket Client Initial Move To RTD
  • Loading branch information
bensternthal committed Aug 23, 2014
2 parents 8e9beb9 + ef2b5b6 commit 3ed2f4e
Show file tree
Hide file tree
Showing 13 changed files with 578 additions and 164 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@
*.egg-info
.coverage
dist
docs/_build
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -6,15 +6,15 @@ before_script:
- flake8 basket
script: coverage run setup.py test
install:
- pip install -r test-requirements.txt --use-mirrors
- pip install -r requirements/dev.txt --use-mirrors
after_success:
# Report coverage results to coveralls.io
- pip install coveralls --use-mirrors
- coveralls
notifications:
irc:
channels:
- "irc.mozilla.org#newsletter"
- "irc.mozilla.org#basket"
on_success: change
on_failure: always
use_notice: true
164 changes: 7 additions & 157 deletions README.rst
Expand Up @@ -3,174 +3,24 @@ Basket Client
=============

This is a client for Mozilla's email subscription service,
basket_. Basket is not a real subscription service, but it talks to a
basket. Basket is not a real subscription service, but it talks to a
real one and we don't really care who/what it is.

There are multiple API methods. View the basket documentation_ for details.

.. image:: https://travis-ci.org/mozilla/basket-client.png
:target: https://travis-ci.org/mozilla/basket-client
.. image:: https://coveralls.io/repos/mozilla/basket-client/badge.png?branch=master
:target: https://coveralls.io/r/mozilla/basket-client
.. image:: https://pypip.in/v/basket-client/badge.png
:target: https://crate.io/packages/basket-client

.. _basket: https://github.com/mozilla/basket

Installation
============

.. code:: bash
$ pip install basket-client
Usage
=====

Do you want to subscribe people to Mozilla's newsletters?
All you need to do is:

.. code:: python
import basket
basket.subscribe('<email>', '<newsletter>', <kwargs>)
You can pass additional fields as keyword arguments, such as format
and country. For a list of available fields and newsletters, see the
basket documentation_.

.. _documentation: https://github.com/mozilla/basket/#readme

Are you checking to see if a user was successfully subscribed? You can
use the ``lookup_user`` method like so:

.. code:: python
import basket
basket.lookup_user(email='<email>', api_key='<api_key>')
And it will return full details about the user. <api_key> is a special
token that grants you admin access to the data. Check with `the mozilla.org
developers`_ to get it.

.. _the mozilla.org developers: mailto:dev-mozilla-org@lists.mozilla.org

On most errors, BasketException will be raised. The ``code`` attribute on
the exception object will contain a numeric code indicating the problem,
and the ``desc`` attribute will have a short English description of it.
(Use the ``code`` attribute to determine which error happened, but you
can use ``desc`` in log messages etc.)

Example::

from basket import errors, some_basket_call

try:
rc = some_basket_call(args)
except BasketError as e:
if e.code == errors.BASKET_INVALID_EMAIL:
print "That email address was not valid"
else:
log.exception("Some basket error (%s)" % e.desc)

The error codes are defined in ``basket.errors``. New ones can be added anytime,
but to start with, the errors are::

BASKET_NETWORK_FAILURE
BASKET_INVALID_EMAIL
BASKET_UNKNOWN_EMAIL
BASKET_UNKNOWN_TOKEN
BASKET_USAGE_ERROR
BASKET_EMAIL_PROVIDER_AUTH_FAILURE
BASKET_AUTH_ERROR
BASKET_SSL_REQUIRED
BASKET_INVALID_NEWSLETTER
BASKET_INVALID_LANGUAGE
BASKET_EMAIL_NOT_CHANGED
BASKET_CHANGE_REQUEST_NOT_FOUND

# If you get this, report it as a bug so we can add a more specific
# error code.
BASKET_UNKNOWN_ERROR


Settings
========
Docs
----

BASKET_URL
| URL to basket server, e.g. ``https://basket.mozilla.org``
| Default: ``http://localhost:8000``
Documentation can be found at http://basket-client.rtfd.org/

The URL must not end with ``/``. Basket-client will add ``/`` if needed.

BASKET_API_KEY
The API Key granted to you by `the mozilla.org developers`_ so that you can
use the ``lookup_user`` method with an email address.

BASKET_TIMEOUT
| The number of seconds basket client should wait before giving up on the request.
| Default: ``10``
If you're using Django_ you can simply add these settings to your
``settings.py`` file. Otherwise basket-client will look for these
values in an environment variable of the same name.

.. _Django: https://www.djangoproject.com/

Tests
=====

To run tests:

.. code:: bash
$ python setup.py test
Change Log
==========

v0.3.10
License
-------

* Set api key on subscribe call when sync=Y

v0.3.9
------

* Add numeric error codes.

v0.3.8
------

* Add the ``start_email_change`` and ``confirm_email_change`` functions.

v0.3.7
------

* Add the ``lookup_user`` function.
* Add the ``BASKET_API_KEY`` setting.
* Add the ``BASKET_TIMEOUT`` setting.

v0.3.6
------

* Add the ``confirm`` function.

v0.3.5
------

* Add tests

v0.3.4
------

* Fix issue with calling ``subscribe`` with an iterable of newsletters.
* Add ``request`` function to those exposed by the ``basket``` module.

v0.3.3
------

* Add get_newsletters API method for information on currently available newsletters.
* Handle Timeout exceptions from requests.
This software is licensed under the MPL http://www.mozilla.org/MPL/. For more
information, read the file ``LICENSE``.
130 changes: 130 additions & 0 deletions docs/Makefile
@@ -0,0 +1,130 @@
# Makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build

# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
PAPEROPT_letter = -D latex_paper_size=letter
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .

.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest

help:
@echo "Please use \`make <target>' where <target> is one of"
@echo " html to make standalone HTML files"
@echo " dirhtml to make HTML files named index.html in directories"
@echo " singlehtml to make a single large HTML file"
@echo " pickle to make pickle files"
@echo " json to make JSON files"
@echo " htmlhelp to make HTML files and a HTML help project"
@echo " qthelp to make HTML files and a qthelp project"
@echo " devhelp to make HTML files and a Devhelp project"
@echo " epub to make an epub"
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
@echo " latexpdf to make LaTeX files and run them through pdflatex"
@echo " text to make text files"
@echo " man to make manual pages"
@echo " changes to make an overview of all changed/added/deprecated items"
@echo " linkcheck to check all external links for integrity"
@echo " doctest to run all doctests embedded in the documentation (if enabled)"

clean:
-rm -rf $(BUILDDIR)/*

html:
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."

dirhtml:
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."

singlehtml:
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."

pickle:
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."

json:
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."

htmlhelp:
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."

qthelp:
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/playdoh.qhcp"
@echo "To view the help file:"
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/playdoh.qhc"

devhelp:
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
@echo "To view the help file:"
@echo "# mkdir -p $$HOME/.local/share/devhelp/playdoh"
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/playdoh"
@echo "# devhelp"

epub:
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."

latex:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."

latexpdf:
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
make -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."

text:
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."

man:
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."

changes:
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."

linkcheck:
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."

doctest:
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."
Empty file added docs/_static/.gitkeep
Empty file.
Empty file added docs/_templates/.gitkeep
Empty file.
55 changes: 55 additions & 0 deletions docs/change_log.rst
@@ -0,0 +1,55 @@
.. This Source Code Form is subject to the terms of the Mozilla Public
.. License, v. 2.0. If a copy of the MPL was not distributed with this
.. file, You can obtain one at http://mozilla.org/MPL/2.0/.
.. _change-log:

======================
Change Log
======================


v0.3.10
-------

* Set api key on subscribe call when sync=Y

v0.3.9
------

* Add numeric error codes.

v0.3.8
------

* Add the ``start_email_change`` and ``confirm_email_change`` functions.

v0.3.7
------

* Add the ``lookup_user`` function.
* Add the ``BASKET_API_KEY`` setting.
* Add the ``BASKET_TIMEOUT`` setting.

v0.3.6
------

* Add the ``confirm`` function.

v0.3.5
------

* Add tests

v0.3.4
------

* Fix issue with calling ``subscribe`` with an iterable of newsletters.
* Add ``request`` function to those exposed by the ``basket``` module.

v0.3.3
------

* Add get_newsletters API method for information on currently available newsletters.
* Handle Timeout exceptions from requests.

0 comments on commit 3ed2f4e

Please sign in to comment.