Scrython/scrython/rulings/rulings_object.py

79 lines
2.5 KiB
Python
Raw Normal View History

import sys
sys.path.append('..')
from scrython.foundation import FoundationObject
2018-01-31 01:36:44 +00:00
class RulingsObject(FoundationObject):
2018-10-22 14:19:38 +00:00
"""
Master class for all rulings objects.
2018-02-21 23:33:58 +00:00
2018-10-25 20:04:36 +00:00
Args:
format (string, optional): Returns data in the specified method. Defaults to JSON.
face (string, optional):
If you're using the `image` format, this will specify if you want the front or back face.
version (string, optional):
If you're using the `image` format, this will specify if you want the small, normal, large, etc version of the image.
pretty (string, optional):
Returns a prettier version of the json object. Note that this may break functionality with Scrython.
2018-02-21 23:33:58 +00:00
2018-10-22 14:19:38 +00:00
"""
2018-01-31 01:36:44 +00:00
2018-10-22 14:19:38 +00:00
def object(self):
2018-10-25 20:04:36 +00:00
"""Returns the type of object it is
(card, error, etc)
Returns:
string
"""
super(RulingsObject, self)._checkForKey('object')
2018-01-31 01:36:44 +00:00
2018-10-22 14:19:38 +00:00
return self.scryfallJson['object']
2018-01-31 01:36:44 +00:00
2018-10-22 14:19:38 +00:00
def has_more(self):
2018-10-25 20:04:36 +00:00
"""True if there is more than one page of results
Returns:
boolean: True if there are more results
"""
super(RulingsObject, self)._checkForKey('has_more')
2018-01-31 01:36:44 +00:00
2018-10-22 14:19:38 +00:00
return self.scryfallJson['has_more']
2018-01-31 01:36:44 +00:00
def data(self, index=None, key=None):
2018-10-25 20:04:36 +00:00
"""The data returned from the query
Acceptable keys:
object (string): The type of object for a given ruling.
source (string): The source of the ruling.
published_at (string): The date when the ruling was published.
comment (string): The effective ruling.
Args:
index (integer, optional): Defaults to None. Access a specific index.
key (string, optional): Defaults to None. Returns the value of the given key. Requires the `index` argument.
Returns:
List: The full list of data.
Dictionary: If given an index
String: If given an index and key.
"""
super(RulingsObject, self)._checkForKey('data')
2018-01-31 01:36:44 +00:00
if index is not None:
if key is not None:
2018-10-25 20:04:36 +00:00
super(RulingsObject, self)._checkForTupleKey('data', index, key)
return self.scryfallJson['data'][index][key]
return self.scryfallJson['data'][index]
2018-10-22 14:19:38 +00:00
return self.scryfallJson['data']
2018-01-31 01:36:44 +00:00
2018-10-22 14:19:38 +00:00
def data_length(self):
2018-10-25 20:04:36 +00:00
"""The length of the `data` list.
Returns:
Integer
"""
super(RulingsObject, self)._checkForKey('data')
2018-01-31 01:36:44 +00:00
2018-10-22 14:19:38 +00:00
return len(self.scryfallJson['data'])