This repository has been archived by the owner on Sep 28, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from brandicted/develop
release 0.2.2
- Loading branch information
Showing
20 changed files
with
373 additions
and
173 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
include README.md | ||
include VERSION | ||
include VERSION | ||
recursive-include ramses/scaffolds * |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.2.1 | ||
0.2.2 |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,134 +1,16 @@ | ||
Getting started | ||
=============== | ||
|
||
**1. Create a Pyramid "starter" project** in a virtualenv directory (see the `pyramid documentation <http://docs.pylonsproject.org/docs/pyramid/en/latest/narr/project.html>`_ if you've never done that before) | ||
1. Create your project in a virtualenv directory (see the `pyramid documentation <http://docs.pylonsproject.org/docs/pyramid/en/latest/narr/project.html>`_ if you've never done that before) | ||
|
||
.. code-block:: shell | ||
$ mkvirtualenv MyProject | ||
$ virtualenv my_project | ||
$ source my_project/bin/activate | ||
$ cd my_project | ||
$ pip install ramses | ||
$ pcreate -s starter MyProject | ||
$ cd MyProject | ||
$ pip install -e . | ||
$ pcreate -s ramses_starter my_project | ||
$ pserve local.ini | ||
Install the database backend of your choice, e.g. sqla or mongodb | ||
.. code-block:: shell | ||
$ pip install nefertari-<engine> | ||
**2. Add a few settings** to development.ini, inside the ``[app:main]`` section | ||
|
||
.. code-block:: ini | ||
# Elasticsearh settings | ||
elasticsearch.hosts = localhost:9200 | ||
elasticsearch.sniff = false | ||
elasticsearch.index_name = myproject | ||
elasticsearch.index.disable = false | ||
# path to your RAML file | ||
ramses.raml_schema = api.raml | ||
# disable authentication | ||
ramses.auth = false | ||
# Set '<nefertari_engine>' (e.g. nefertari_sqla or nefertari_mongodb) | ||
nefertari.engine = <nefertari_engine> | ||
.. code-block:: ini | ||
# For sqla: | ||
sqlalchemy.url = postgresql://localhost:5432/myproject | ||
.. code-block:: ini | ||
# For mongo: | ||
mongodb.host = localhost | ||
mongodb.port = 27017 | ||
mongodb.db = myproject | ||
**3. Replace the file** `myproject/__init__.py` | ||
|
||
.. code-block:: python | ||
from pyramid.config import Configurator | ||
def main(global_config, **settings): | ||
config = Configurator(settings=settings) | ||
config.include('ramses') | ||
return config.make_wsgi_app() | ||
**4. Create the file** `api.raml` | ||
|
||
.. code-block:: yaml | ||
#%RAML 0.8 | ||
--- | ||
title: Ramses | ||
documentation: | ||
- title: Example REST API | ||
content: | | ||
Welcome to the Ramses example API. | ||
baseUri: http://{host}:{port}/{version} | ||
version: v1 | ||
mediaType: application/json | ||
protocols: [HTTP] | ||
/myitems: | ||
displayName: Collection of items | ||
get: | ||
description: Get all item | ||
post: | ||
description: Create a new item | ||
body: | ||
application/json: | ||
schema: !include items.json | ||
/{id}: | ||
displayName: Collection-item | ||
get: | ||
description: Get a particular item | ||
delete: | ||
description: Delete a particular item | ||
patch: | ||
description: Update a particular item | ||
**5. Create the file** `items.json` | ||
|
||
.. code-block:: json | ||
{ | ||
"type": "object", | ||
"title": "Item schema", | ||
"$schema": "http://json-schema.org/draft-03/schema", | ||
"properties": { | ||
"id": { | ||
"required": true, | ||
"type": "id_field", | ||
"args": { | ||
"primary_key": true | ||
} | ||
}, | ||
"name": { | ||
"required": true, | ||
"type": "string" | ||
}, | ||
"description": { | ||
"required": false, | ||
"type": "text" | ||
} | ||
} | ||
} | ||
**6. Run your app** | ||
|
||
.. code-block:: shell | ||
$ pserve development.ini | ||
2. Tada! Start editing api.raml to modify the API and items.json for the schema. |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from pyramid.scaffolds import PyramidTemplate | ||
import binascii | ||
import os | ||
from os import urandom, chdir | ||
import subprocess | ||
|
||
|
||
class RamsesStarterTemplate(PyramidTemplate): | ||
_template_dir = 'ramses_starter' | ||
summary = 'Ramses starter' | ||
|
||
def pre(self, command, output_dir, vars): | ||
dbengine_choices = {'1':'sqla', '2':'mongodb'} | ||
vars['engine'] = dbengine_choices[raw_input(""" | ||
Which DB backend would you like to use: 1)'sqla' or 2)'mongodb'?: | ||
""")] | ||
vars['random_string'] = binascii.hexlify(os.urandom(20)) | ||
if vars['package'] == 'site': | ||
raise ValueError(""" | ||
"Site" is a reserved keyword in Python. | ||
Please use a different project name. """) | ||
|
||
def post(self, command, output_dir, vars): | ||
os.chdir(str(output_dir)) | ||
subprocess.call('pip install -r requirements.txt', shell=True) | ||
subprocess.call('pip install nefertari-{}'.format(vars['engine']), shell=True) | ||
msg = """Goodbye boilerplate! Welcome to Ramses.""" | ||
self.out(msg) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from pyramid.config import Configurator | ||
|
||
|
||
def main(global_config, **settings): | ||
config = Configurator(settings=settings) | ||
config.include('ramses') | ||
return config.make_wsgi_app() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
venv | ||
.DS_Store | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
local.ini | ||
mock/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
## Installation | ||
``` | ||
$ pip install -r requirements.txt | ||
## Run | ||
``` | ||
$ pserve local.ini | ||
``` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#%RAML 0.8 | ||
--- | ||
title: {{package}} API | ||
documentation: | ||
- title: {{package}} REST API | ||
content: | | ||
Welcome to the {{package}} API. | ||
baseUri: http://{host}:{port}/{version} | ||
version: v1 | ||
mediaType: application/json | ||
protocols: [HTTP] | ||
|
||
/items: | ||
displayName: Collection of items | ||
get: | ||
description: Get all item | ||
post: | ||
description: Create a new item | ||
body: | ||
application/json: | ||
schema: !include items.json | ||
|
||
/{id}: | ||
displayName: Collection-item | ||
get: | ||
description: Get a particular item | ||
delete: | ||
description: Delete a particular item | ||
patch: | ||
description: Update a particular item |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"type": "object", | ||
"title": "Item schema", | ||
"$schema": "http://json-schema.org/draft-03/schema", | ||
"properties": { | ||
"id": { | ||
"required": true, | ||
"type": "id_field", | ||
"args": { | ||
"primary_key": true | ||
} | ||
}, | ||
"name": { | ||
"required": true, | ||
"type": "string" | ||
}, | ||
"description": { | ||
"required": false, | ||
"type": "text" | ||
} | ||
} | ||
} |
Oops, something went wrong.