Skip to content

Feature/documentation #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ instance/

# Sphinx documentation
docs/_build/
docs/source

# PyBuilder
target/
Expand Down
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = pizzapi
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
170 changes: 170 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# -*- coding: utf-8 -*-
#
# pizzapi documentation build configuration file, created by
# sphinx-quickstart on Sun Feb 4 22:05:18 2018.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.coverage']

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'

# General information about the project.
project = u'pizzapi'
copyright = u'2018, Arie van Luttikhuizen, Grant Gordon'
author = u'Arie van Luttikhuizen, Grant Gordon'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = u'0.0.2'
# The full version, including alpha/beta/rc tags.
release = u'0.0.2'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'

# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False


# -- Options for HTML output ----------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# This is required for the alabaster theme
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
html_sidebars = {
'**': [
'relations.html', # needs 'show_related': True theme option to display
'searchbox.html',
]
}


# -- Options for HTMLHelp output ------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'pizzapidoc'


# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'pizzapi.tex', u'pizzapi Documentation',
u'Arie van Luttikhuizen, Grant Gordon', 'manual'),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'pizzapi', u'pizzapi Documentation',
[author], 1)
]


# -- Options for Texinfo output -------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'pizzapi', u'pizzapi Documentation',
author, 'pizzapi', 'One line description of project.',
'Miscellaneous'),
]



20 changes: 20 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.. pizzapi documentation master file, created by
sphinx-quickstart on Sun Feb 4 22:05:18 2018.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

Welcome to pizzapi's documentation!
===================================

.. toctree::
:maxdepth: 2
:caption: Contents:



Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
36 changes: 36 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build
set SPHINXPROJ=pizzapi

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%

:end
popd
21 changes: 21 additions & 0 deletions pizzapi/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
from .urls import Urls, COUNTRY_USA

class Address(object):
"""Create an address, for finding stores and placing orders.

The Address object describes a street address in North America (USA or
Canada, for now). Callers can use the Address object's methods to find
the closest or nearby stores from the API.

Attributes:
street (String): Street address
city (String): North American city
region (String): North American region (state, province, territory)
zip (String): North American ZIP code
urls (String): Country-specific URLs
country (String): Country
"""

def __init__(self, street, city, region='', zip='', country=COUNTRY_USA, *args):
self.street = street.strip()
self.city = city.strip()
Expand All @@ -25,6 +40,12 @@ def line2(self):
return '{City}, {Region}, {PostalCode}'.format(**self.data)

def nearby_stores(self, service='Delivery'):
"""Query the API to find nearby stores.

nearby_stores will filter the information we receive from the API
to exclude stores that are not currently online (!['IsOnlineNow']),
and stores that are not currently in service (!['ServiceIsOpen']).
"""
data = request_json(self.urls.find_url(), line1=self.line1, line2=self.line2, type=service)
return [Store(x, self.country) for x in data['Stores']
if x['IsOnlineNow'] and x['ServiceIsOpen'][service]]
Expand Down
8 changes: 8 additions & 0 deletions pizzapi/coupon.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
class Coupon(object):
"""Loose representation of a coupon - no logic.

This is a coupon - you can add it to an Order (order.add_item) and,
if it fits, get some money off your purchase. I think.

This is another thing that's worth exploring - there are some sweet
coupons that would be awful without the coupon.
"""
def __init__(self, code, quantity=1):
self.code = code
self.quantity = quantity
Expand Down
6 changes: 6 additions & 0 deletions pizzapi/customer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
class Customer(object):
"""The Customer orders a pizza.

You need a Customer to create an Order. The proprietors of the API
use this information, presumably for nefarious Pizza Purposes.
"""

def __init__(self, fname='', lname='', email='', phone='', address=None):
self.first_name = fname.strip()
self.last_name = lname.strip()
Expand Down
8 changes: 8 additions & 0 deletions pizzapi/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ def __init__(self, data={}):


class Menu(object):
"""The Menu is our primary interface with the API.

This is far and away the most complicated class - it wraps up most of
the logic that parses the information we get from the API.

Next time I get pizza, there is a lot of work to be done in
documenting this class.
"""
def __init__(self, data={}, country=COUNTRY_USA):
self.variants = data.get('Variants', {})
self.menu_by_code = {}
Expand Down
6 changes: 6 additions & 0 deletions pizzapi/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

# TODO: Add add_coupon and remove_coupon methods
class Order(object):
"""Core interface to the payments API.

The Order is perhaps the second most complicated class - it wraps
up all the logic for actually placing the order, after we've
determined what we want from the Menu.
"""
def __init__(self, store, customer, address, country=COUNTRY_USA):
self.store = store
self.menu = Menu.from_store(store_id=store.id, country=country)
Expand Down
5 changes: 5 additions & 0 deletions pizzapi/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@


class PaymentObject(object):
"""A PaymentObject represents a credit card.

There's some sweet logic in here to make sure that the type of card
you passed is valid.
"""
def __init__(self, number='', expiration='', cvv='', zip=''):
self.name = ''
self.number = str(number).strip()
Expand Down
5 changes: 5 additions & 0 deletions pizzapi/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@


class Store(object):
"""The interface to the Store API

You can use this to find store information about stores near an
address, or to find the closest store to an address.
"""
def __init__(self, data={}, country=COUNTRY_USA):
self.id = str(data.get('StoreID', -1))
self.country = country
Expand Down
20 changes: 18 additions & 2 deletions pizzapi/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,27 @@


def track_by_phone(phone, country=COUNTRY_USA):
"""Query the API to get tracking information.

Not quite sure what this gets you - problem to solve for next time I get pizza.
"""
phone = str(phone).strip()
data = request_xml(Urls(country).track_by_phone(), phone=phone)['soap:Envelope']['soap:Body']
data = request_xml(
Urls(country).track_by_phone(),
phone=phone
)['soap:Envelope']['soap:Body']

response = data['GetTrackerDataResponse']['OrderStatuses']['OrderStatus']

return response


def track_by_order(store_id, order_key, country=COUNTRY_USA):
return request_json(Urls(country).track_by_order(), store_id=store_id, order_key=order_key)
"""Query the API to get tracking information.
"""
return request_json(
Urls(country).track_by_order(),
store_id=store_id,
order_key=order_key
)

Loading