Skip to content

Commit

Permalink
Update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
MaT1g3R committed May 15, 2017
1 parent 0b20f83 commit 57b1379
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
\.idea/

setup\.py

setup\.cfg
48 changes: 47 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,47 @@
Python-Trivia-API
# Python Trivia API
## Install
```
pip install pytrivia
```

## Requirements
```
requests
```

## Example usage
```Python
from pytrivia import Category, Diffculty, Type, Trivia
my_api = Trivia(True)
response = my_api.request(2, Category.Books, Diffculty.Hard, Type.True_False)
print(reqponse)
```

## Full method signature
```Python
def request(self, num_questions: int, category: Category = None,
diffculty: Diffculty = None, type_: Type = None):
"""
Send an api request to https://opentdb.com/
Limitations:
Only 1 Category can be requested per API Call.
To get questions from any category, don't specify a category.
A Maximum of 50 Questions can be retrieved per call.
:param num_questions: the number of questions,
must be between 1 and 50 (inclusive)
:param category: the category of the question. None for any category
:param diffculty: the diffculty of the question. None for any diffculty
:param type_: the type of the question. None for any type
:return: the api call response
:rtype: dict
:raises: ValueError when the num_questions parameter is less than 1
or greater than 50
"""
```
7 changes: 5 additions & 2 deletions pytrivia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ class Trivia:
def __init__(self, with_token: bool):
"""
Initialize an instance of the Trivia class
:param with_token: whether if the instance uses a session token
:param with_token: If True then the instance will uses a session token
"""
self.token = _get_token() if with_token else None

def request(self, num_questions: int, category: Category = None,
diffculty: Diffculty = None, type_: Type = None):
"""
Send a api
Send an api request to https://opentdb.com/
Limitations:
Only 1 Category can be requested per API Call.
To get questions from any category, don't specify a category.
Expand All @@ -76,6 +76,9 @@ def request(self, num_questions: int, category: Category = None,
:return: the api call response
:rtype: dict
:raises: ValueError when the num_questions parameter is less than 1
or greater than 50
"""
if num_questions < 1 or num_questions > 50:
raise ValueError
Expand Down

0 comments on commit 57b1379

Please sign in to comment.