Last active
January 15, 2016 22:25
-
-
Save Lull3rSkat3r/3f01a102fcfaf5602c7f to your computer and use it in GitHub Desktop.
A collection of code snippets for the "Words Of Wisdom" API.
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
{ | |
"swagger": "2.0", | |
"info": { | |
"version": "0.0.1", | |
"title": "Words Of Wisdom", | |
"description": "An API for recording and reflecting quotes.", | |
"contact": { | |
"name": "Corey Stubbs", | |
"email": "cstubbs@us.ibm.com", | |
"url": "https://github.com/Lull3rSkat3r" | |
} | |
}, | |
"paths": { | |
"/random": { | |
"get": { | |
"description": "Returns a random quote", | |
"responses": { | |
"200": { | |
"description": "A string containing the quote", | |
"schema": { | |
"type": "string" | |
} | |
} | |
} | |
} | |
}, | |
"/quote": { | |
"post": { | |
"description": "Adds a quote", | |
"parameters": [ | |
{ | |
"name": "body", | |
"in": "body", | |
"description": "The quote to be added to the collection", | |
"required": true, | |
"schema": { | |
"type": "string" | |
} | |
} | |
], | |
"responses": { | |
"201": { | |
"description": "Returns the id of the newly create quote, which can be used to access the quote", | |
"schema": { | |
"type": "integer" | |
} | |
} | |
} | |
} | |
}, | |
"/quote/{id}": { | |
"get": { | |
"description": "Gets the quote", | |
"parameters": [ | |
{ | |
"name": "id", | |
"in": "path", | |
"description": "The quote to be added to the collection", | |
"required": true, | |
"type": "string" | |
} | |
], | |
"responses": { | |
"201": { | |
"description": "Returns the id of the quote, which can be used to access the quote", | |
"schema": { | |
"type": "integer" | |
} | |
} | |
} | |
}, | |
"put": { | |
"description": "Updates the content of quote.", | |
"parameters": [ | |
{ | |
"name": "id", | |
"in": "path", | |
"description": "The quote to be added to the collection", | |
"required": true, | |
"type": "string" | |
}, | |
{ | |
"name": "body", | |
"in": "body", | |
"description": "The new value of the quote", | |
"required": true, | |
"schema": { | |
"type": "string" | |
} | |
} | |
], | |
"responses": { | |
"204": { | |
"description": "The quote has successfully been updated." | |
} | |
} | |
} | |
} | |
} | |
} |
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
swagger: '2.0' | |
info: | |
version: 0.0.1 | |
title: 'Words Of Wisdom' | |
description: An API for recording and reflecting quotes. | |
contact: | |
name: Corey Stubbs | |
email: cstubbs@us.ibm.com | |
url: 'https://github.com/Lull3rSkat3r' | |
paths: | |
/random: | |
get: | |
description: Returns a random quote | |
responses: | |
'200': | |
description: A string containing the quote | |
schema: | |
type: string | |
/quote: | |
post: | |
description: Adds a quote | |
parameters: | |
- name: body | |
in: body | |
description: The quote to be added to the collection | |
required: true | |
schema: | |
type: string | |
responses: | |
'201': | |
description: Returns the id of the newly create quote, which can be used to access the quote | |
schema: | |
type: integer | |
/quote/{id}: | |
get: | |
description: Gets the quote | |
parameters: | |
- name: id | |
in: path | |
description: The quote to be added to the collection | |
required: true | |
type: string | |
responses: | |
'201': | |
description: Returns the id of the quote, which can be used to access the quote | |
schema: | |
type: integer | |
put: | |
description: Updates the content of quote. | |
parameters: | |
- name: id | |
in: path | |
description: The quote to be added to the collection | |
required: true | |
type: string | |
- name: body | |
in: body | |
description: The new value of the quote | |
required: true | |
schema: | |
type: string | |
responses: | |
'204': | |
description: The quote has successfully been updated. |
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
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"collapsed": false | |
}, | |
"source": [ | |
"# Words Of Wisdom - 0.0.1 \n", | |
"An API for recording and reflecting quotes. \n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"import json\n", | |
"from random import randint\n", | |
"\n", | |
"QUOTES = {\n", | |
" 0 : 'Many that live deserve death. And some that die deserve life. Can you give it to them? Then do not be too eager to deal out death in judgement. For even the very wise cannot see all ends. -Gandalf',\n", | |
" 1 : 'Strive not to be a success, but rather to be of value. -Albert Einstein',\n", | |
" 2 : 'Winning isn\\'t everything, but wanting to win is. -Vince Lombardi',\n", | |
" 3 : 'The two most important days in your life are the day you are born and the day you find out why. -Mark Twain'\n", | |
"}\n", | |
"INDEX_COUNTER = {\n", | |
" 'QUOTES' : len(QUOTES)\n", | |
"}\n", | |
"\n", | |
"def add_quote(quote):\n", | |
" quote_index = INDEX_COUNTER['QUOTES'] \n", | |
" QUOTES[quote_index] = quote\n", | |
" INDEX_COUNTER['QUOTES'] = quote_index + 1\n", | |
" return quote_index\n", | |
"\n", | |
"def get_quote(id):\n", | |
" id = int(id)\n", | |
" return QUOTES[id]\n", | |
"\n", | |
"def set_quote(id, quote):\n", | |
" id = int(id)\n", | |
" QUOTES[id] = quote\n", | |
" return QUOTES[id]" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"collapsed": false | |
}, | |
"source": [ | |
"## POST /quote \n", | |
"\n", | |
"Adds a quote \n", | |
"\n", | |
"Body Parameters: \n", | |
"\n", | |
"* body (required) - The quote to be added to the collection\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"# # Test cell for POST /quote\n", | |
"# REQUEST = json.dumps({\n", | |
"# 'body' : 'Developers. Developers. -Steve Ballmer'\n", | |
"# })" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"# POST /quote \n", | |
"request = json.loads(REQUEST)\n", | |
"body = request['body']\n", | |
"print(add_quote(body))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"collapsed": false | |
}, | |
"source": [ | |
"## GET /quote/:id \n", | |
"\n", | |
"Gets the quote \n", | |
"\n", | |
"Path Parameters: \n", | |
"\n", | |
"* id (required) - The quote to be added to the collection\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"# # Test cell for GET /quote/:id\n", | |
"# REQUEST = json.dumps({\n", | |
"# 'path' : {\n", | |
"# 'id' : '0'\n", | |
"# }\n", | |
"# })" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"# GET /quote/:id \n", | |
"request = json.loads(REQUEST)\n", | |
"id = request['path']['id']\n", | |
"print(get_quote(id))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"collapsed": false | |
}, | |
"source": [ | |
"## PUT /quote/:id \n", | |
"\n", | |
"Updates the content of quote. \n", | |
"\n", | |
"Path Parameters: \n", | |
"\n", | |
"* id (required) - The quote to be added to the collection\n", | |
"\n", | |
"\n", | |
"Body Parameters: \n", | |
"\n", | |
"* body (required) - The new value of the quote\n", | |
"\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"# # Test cell for PUT /quote/:id\n", | |
"# REQUEST = json.dumps({\n", | |
"# 'path' : {\n", | |
"# 'id' : '4'\n", | |
"# },\n", | |
"# 'body' : 'Developers. Developers. Developers. Developers. -Steve Ballmer'\n", | |
"# })" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"# PUT /quote/:id \n", | |
"request = json.loads(REQUEST)\n", | |
"body = request['body']\n", | |
"id = request['path']['id']\n", | |
"print(set_quote(id, body))" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"collapsed": false | |
}, | |
"source": [ | |
"## GET /random \n", | |
"\n", | |
"Returns a random quote \n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"# GET /random \n", | |
"random_index = randint(0, len(QUOTES) - 1)\n", | |
"print(get_quote(random_index))" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.4.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment