Skip to content
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

Fix no limit parameter in issue #2 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ This is an API wrapper for [Marvel](https://developer.marvel.com/docs).
Usage
=====

Usage is as simple as it gets:
Usage is as simple as it gets, LIMIT is not required, 20 is default, 100 is the maximum can be supported:

from marvel import Marvel
m = Marvel(PUBLIC_KEY, PRIVATE_KEY)
m = Marvel(PUBLIC_KEY, PRIVATE_KEY, LIMIT)

Now there are six objects presented namely, `characters`, `comics`, `creators`, `events`, `series` and `stories`
as listed at [Developers](https://developer.marvel.com/documentation/entity_types)
Expand Down
5 changes: 3 additions & 2 deletions marvel/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@


class Base:
def __init__(self, PUBLIC_KEY, PRIVATE_KEY):
def __init__(self, PUBLIC_KEY, PRIVATE_KEY, LIMIT):
"""
Base Class
:param PUBLIC_KEY: str
:param PRIVATE_KEY: str
:param LIMIT: int
"""
self.requester = Requester(PUBLIC_KEY, PRIVATE_KEY)
self.requester = Requester(PUBLIC_KEY, PRIVATE_KEY, LIMIT)
5 changes: 3 additions & 2 deletions marvel/marvel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@


class Marvel(Base):
def __init__(self, PUBLIC_KEY, PRIVATE_KEY):
def __init__(self, PUBLIC_KEY, PRIVATE_KEY, LIMIT=None):
"""
Marvel main class to access different modules and their methods.
:param PUBLIC_KEY: str
:param PRIVATE_KEY: str
:param LIMIT: int
"""
super().__init__(PUBLIC_KEY, PRIVATE_KEY)
super().__init__(PUBLIC_KEY, PRIVATE_KEY, LIMIT)
self.characters = Characters(requester=self.requester)
self.events = Events(requester=self.requester)
self.series = Series(requester=self.requester)
Expand Down
8 changes: 7 additions & 1 deletion marvel/requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class Requester(EndpointManager):
def __init__(self, PUBLIC_KEY, PRIVATE_KEY):
def __init__(self, PUBLIC_KEY, PRIVATE_KEY, LIMIT):
"""
Requester class responsible for making HTTP requests.
:param PUBLIC_KEY: str
Expand All @@ -16,6 +16,7 @@ def __init__(self, PUBLIC_KEY, PRIVATE_KEY):
self.PUBLIC_KEY = PUBLIC_KEY
self.PRIVATE_KEY = PRIVATE_KEY
self.r = object
self.limit = LIMIT

def request(self, endpoint_name, payload=None, sub_endpoint=None, identifier=None, raw=None):
"""
Expand All @@ -34,6 +35,11 @@ def request(self, endpoint_name, payload=None, sub_endpoint=None, identifier=Non
url += "/" + str(identifier)
if sub_endpoint is not None:
url += "/" + sub_endpoint
if self.limit is not None:
assert self.limit <= 100, (
"limit %d higher than the maximum 100 can be supported" % self.limit
)
payload["limit"] = self.limit
query = self.get_query_with_authentication_params(payload)
self.r = requests.get(url, params=query)
if raw:
Expand Down