Move mtgsdk from project to pip dependencies.

This commit is contained in:
luxick
2017-07-26 00:09:28 +02:00
parent 2b1f3b940f
commit 154745dd94
11 changed files with 1 additions and 383 deletions

View File

@@ -1,20 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of mtgsdk.
# https://github.com/MagicTheGathering/mtg-sdk-python
# Licensed under the MIT license:
# http://www.opensource.org/licenses/MIT-license
# Copyright (c) 2016, Andrew Backes <backes.andrew@gmail.com>
from mtgsdk.config import __version__, __pypi_packagename__, __github_username__, __github_reponame__, __endpoint__
from mtgsdk.card import Card
from mtgsdk.set import Set
from mtgsdk.supertype import Supertype
from mtgsdk.subtype import Subtype
from mtgsdk.type import Type
from mtgsdk.changelog import Changelog
from mtgsdk.restclient import RestClient
from mtgsdk.restclient import MtgException
from mtgsdk.querybuilder import QueryBuilder

View File

@@ -1,67 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of mtgsdk.
# https://github.com/MagicTheGathering/mtg-sdk-python
# Licensed under the MIT license:
# http://www.opensource.org/licenses/MIT-license
# Copyright (c) 2016, Andrew Backes <backes.andrew@gmail.com>
from mtgsdk.querybuilder import QueryBuilder
class Card(object):
RESOURCE = 'cards'
def __init__(self, response_dict={}):
self.name = response_dict.get('name')
self.layout = response_dict.get('layout')
self.mana_cost = response_dict.get('manaCost')
self.cmc = response_dict.get('cmc')
self.colors = response_dict.get('colors')
self.names = response_dict.get('names')
self.type = response_dict.get('type')
self.supertypes = response_dict.get('supertypes')
self.subtypes = response_dict.get('subtypes')
self.types = response_dict.get('types')
self.rarity = response_dict.get('rarity')
self.text = response_dict.get('text')
self.flavor = response_dict.get('flavor')
self.artist = response_dict.get('artist')
self.number = response_dict.get('number')
self.power = response_dict.get('power')
self.toughness = response_dict.get('toughness')
self.loyalty = response_dict.get('loyalty')
self.multiverse_id = response_dict.get('multiverseid')
self.variations = response_dict.get('variations')
self.watermark = response_dict.get('watermark')
self.border = response_dict.get('border')
self.timeshifted = response_dict.get('timeshifted')
self.hand = response_dict.get('hand')
self.life = response_dict.get('life')
self.release_date = response_dict.get('releaseDate')
self.starter = response_dict.get('starter')
self.printings = response_dict.get('printings')
self.original_text = response_dict.get('originalText')
self.original_type = response_dict.get('originalType')
self.source = response_dict.get('source')
self.image_url = response_dict.get('imageUrl')
self.set = response_dict.get('set')
self.set_name = response_dict.get('setName')
self.id = response_dict.get('id')
self.legalities = response_dict.get('legalities')
self.rulings = response_dict.get('rulings')
self.foreign_names = response_dict.get('foreignNames')
@staticmethod
def find(id):
return QueryBuilder(Card).find(id)
@staticmethod
def where(**kwargs):
return QueryBuilder(Card).where(**kwargs)
@staticmethod
def all():
return QueryBuilder(Card).all()

View File

@@ -1,25 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of mtgsdk.
# https://github.com/MagicTheGathering/mtg-sdk-python
# Licensed under the MIT license:
# http://www.opensource.org/licenses/MIT-license
# Copyright (c) 2016, Andrew Backes <backes.andrew@gmail.com>
from mtgsdk.querybuilder import QueryBuilder
class Changelog(object):
RESOURCE = 'changelogs'
def __init__(self, response_dict={}):
self.id = response_dict.get('id')
self.version = response_dict.get('version')
self.details = response_dict.get('details')
self.release_date = response_dict.get('releaseDate')
@staticmethod
def all():
return QueryBuilder(Changelog).all()

View File

@@ -1,15 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of mtgsdk.
# https://github.com/MagicTheGathering/mtg-sdk-python
# Licensed under the MIT license:
# http://www.opensource.org/licenses/MIT-license
# Copyright (c) 2016, Andrew Backes <backes.andrew@gmail.com>
__version__ = "1.2.0"
__pypi_packagename__ = "mtgsdk"
__github_username__ = "MagicTheGathering"
__github_reponame__ = "mtg-sdk-python"
__endpoint__ = "https://api.magicthegathering.io/v1"

View File

@@ -1,100 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of mtgsdk.
# https://github.com/MagicTheGathering/mtg-sdk-python
# Licensed under the MIT license:
# http://www.opensource.org/licenses/MIT-license
# Copyright (c) 2016, Andrew Backes <backes.andrew@gmail.com>
from mtgsdk.restclient import RestClient
from mtgsdk.config import __endpoint__
class QueryBuilder(object):
def __init__(self, type):
self.params = {}
self.type = type
def find(self, id):
"""Get a resource by its id
Args:
id (string): Resource id
Returns:
object: Instance of the resource type
"""
url = "{}/{}/{}".format(__endpoint__, self.type.RESOURCE, id)
response = RestClient.get(url)[self.type.RESOURCE[:-1]]
return self.type(response)
def find_many(self, url, type, resource):
"""Get a list of resources
Args:
url (string): URL to invoke
type (class): Class type
resource (string): The REST Resource
Returns:
list of object: List of resource instances
"""
list = []
response = RestClient.get(url)[resource]
if len(response) > 0:
for item in response:
list.append(type(item))
return list
def where(self, **kwargs):
"""Adds a parameter to the dictionary of query parameters
Args:
**kwargs: Arbitrary keyword arguments.
Returns:
QueryBuilder: Instance of the QueryBuilder
"""
for key, value in kwargs.items():
self.params[key] = value
return self
def all(self):
"""Get all resources, automatically paging through data
Returns:
list of object: List of resource objects
"""
list = []
page = 1
fetch_all = True
url = "{}/{}".format(__endpoint__, self.type.RESOURCE)
if 'page' in self.params:
page = self.params['page']
fetch_all = False
while True:
response = RestClient.get(url, self.params)[self.type.RESOURCE]
if len(response) > 0:
for item in response:
list.append(self.type(item))
if not fetch_all:
break
else:
page += 1
self.where(page=page)
else:
break
return list
def array(self):
"""Get all resources and return the result as an array
Returns:
array of str: Array of resources
"""
url = "{}/{}".format(__endpoint__, self.type.RESOURCE)
return RestClient.get(url, self.params)[self.type.RESOURCE]

View File

@@ -1,49 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of mtgsdk.
# https://github.com/MagicTheGathering/mtg-sdk-python
# Licensed under the MIT license:
# http://www.opensource.org/licenses/MIT-license
# Copyright (c) 2016, Andrew Backes <backes.andrew@gmail.com>
import json
from urllib.request import Request, urlopen
from urllib.error import HTTPError, URLError
from urllib.parse import urlencode
class RestClient(object):
@staticmethod
def get(url, params={}):
"""Invoke an HTTP GET request on a url
Args:
url (string): URL endpoint to request
params (dict): Dictionary of url parameters
Returns:
dict: JSON response as a dictionary
"""
request_url = url
if len(params) > 0:
request_url = "{}?{}".format(url, urlencode(params))
try:
req = Request(request_url, headers={'User-Agent': 'Mozilla/5.0'})
response = json.loads(urlopen(req).read().decode("utf-8"))
return response
except HTTPError as err:
raise MtgException(err.read())
except URLError as err:
raise MtgException(str(err.reason))
class MtgException(Exception):
def __init__(self, description):
self.description = description
def __str__(self):
return self.description

View File

@@ -1,49 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of mtgsdk.
# https://github.com/MagicTheGathering/mtg-sdk-python
# Licensed under the MIT license:
# http://www.opensource.org/licenses/MIT-license
# Copyright (c) 2016, Andrew Backes <backes.andrew@gmail.com>
from mtgsdk.querybuilder import QueryBuilder
from mtgsdk.config import __endpoint__
from mtgsdk.card import Card
class Set(object):
RESOURCE = 'sets'
def __init__(self, response_dict={}):
self.code = response_dict.get('code')
self.name = response_dict.get('name')
self.type = response_dict.get('type')
self.border = response_dict.get('border')
self.mkm_id = response_dict.get('mkm_id')
self.mkm_name = response_dict.get('mkm_name')
self.release_date = response_dict.get('releaseDate')
self.gatherer_code = response_dict.get('gathererCode')
self.magic_cards_info_code = response_dict.get('magicCardsInfoCode')
self.booster = response_dict.get('booster')
self.old_code = response_dict.get('oldCode')
self.block = response_dict.get('block')
self.online_only = response_dict.get('onlineOnly')
@staticmethod
def find(id):
return QueryBuilder(Set).find(id)
@staticmethod
def where(**kwargs):
return QueryBuilder(Set).where(**kwargs)
@staticmethod
def all():
return QueryBuilder(Set).all()
@staticmethod
def generate_booster(code):
url = "{}/{}/{}/booster".format(__endpoint__, Set.RESOURCE, code)
return QueryBuilder(Set).find_many(url, Card, Card.RESOURCE)

View File

@@ -1,19 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of mtgsdk.
# https://github.com/MagicTheGathering/mtg-sdk-python
# Licensed under the MIT license:
# http://www.opensource.org/licenses/MIT-license
# Copyright (c) 2016, Andrew Backes <backes.andrew@gmail.com>
from mtgsdk.querybuilder import QueryBuilder
class Subtype(object):
RESOURCE = 'subtypes'
@staticmethod
def all():
return QueryBuilder(Subtype).array()

View File

@@ -1,19 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of mtgsdk.
# https://github.com/MagicTheGathering/mtg-sdk-python
# Licensed under the MIT license:
# http://www.opensource.org/licenses/MIT-license
# Copyright (c) 2016, Andrew Backes <backes.andrew@gmail.com>
from mtgsdk.querybuilder import QueryBuilder
class Supertype(object):
RESOURCE = 'supertypes'
@staticmethod
def all():
return QueryBuilder(Supertype).array()

View File

@@ -1,19 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This file is part of mtgsdk.
# https://github.com/MagicTheGathering/mtg-sdk-python
# Licensed under the MIT license:
# http://www.opensource.org/licenses/MIT-license
# Copyright (c) 2016, Andrew Backes <backes.andrew@gmail.com>
from mtgsdk.querybuilder import QueryBuilder
class Type(object):
RESOURCE = 'types'
@staticmethod
def all():
return QueryBuilder(Type).array()

View File

@@ -37,5 +37,5 @@ setup(
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'License :: OSI Approved :: MIT License',
], install_requires=['gi', 'pillow', 'six']
], install_requires=['gi', 'pillow', 'six', 'mtgsdk']
)