Skip to content

Commit

Permalink
Simplified fluent interface - v2
Browse files Browse the repository at this point in the history
  • Loading branch information
adback03 committed Mar 5, 2018
1 parent 0f0a60c commit 3cbc8a7
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 12 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Import (Card and Set will be most used)
set
set_code
retreat_cost
converted_retreat_cost
text
types
attacks
Expand All @@ -73,6 +74,7 @@ Import (Card and Set will be most used)
standard_legal
expanded_legal
release_date
updated_at
symbol_url
logo_url

Expand All @@ -84,23 +86,23 @@ Import (Card and Set will be most used)

#### Filter Cards via query parameters

cards = Card.where(set='generations').where(supertype='pokemon').all()
cards = Card.where(set='generations', supertype='pokemon')

#### Find all cards (will take awhile)

cards = Card.all()

#### Get all cards, but only a specific page of data

cards = Card.where(page=5).where(pageSize=100).all()
cards = Card.where(page=5, pageSize=100)

#### Find a set by code

set = Set.find('base1')

#### Filter sets via query parameters

sets = Set.where(standardLegal=true).all()
sets = Set.where(standardLegal=true)

#### Get all Sets

Expand All @@ -125,3 +127,9 @@ Import (Card and Set will be most used)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request

## Developing

### Running Tests

python -m unittest discover -s tests/
1 change: 1 addition & 0 deletions pokemontcgsdk/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def __init__(self, response_dict={}):
self.set = response_dict.get('set')
self.set_code = response_dict.get('setCode')
self.retreat_cost = response_dict.get('retreatCost')
self.converted_retreat_cost = response_dict.get('convertedRetreatCost')
self.text = response_dict.get('text')
self.attacks = response_dict.get('attacks')
self.weaknesses = response_dict.get('weaknesses')
Expand Down
2 changes: 1 addition & 1 deletion pokemontcgsdk/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# http://www.opensource.org/licenses/MIT-license
# Copyright (c) 2016, Andrew Backes <[email protected]>

__version__ = "1.4.1"
__version__ = "2.0.0"
__pypi_packagename__ = "pokemontcgsdk"
__github_username__ = "PokemonTCG"
__github_reponame__ = "pokemon-tcg-sdk-python"
Expand Down
4 changes: 2 additions & 2 deletions pokemontcgsdk/querybuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ def where(self, **kwargs):
Args:
**kwargs: Arbitrary keyword arguments.
Returns:
QueryBuilder: Instance of the QueryBuilder
list of object: List of resource objects
"""
for key, value in kwargs.items():
self.params[key] = value

return self
return self.all()

def all(self):
"""Get all resources, automatically paging through data
Expand Down
1 change: 1 addition & 0 deletions pokemontcgsdk/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self, response_dict={}):
self.release_date = response_dict.get('releaseDate')
self.symbol_url = response_dict.get('symbolUrl')
self.logo_url = response_dict.get('logoUrl')
self.updated_at = response_dict.get('updatedAt')

@staticmethod
def find(id):
Expand Down
9 changes: 4 additions & 5 deletions tests/test_card.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_find_returns_card(self):
self.assertEqual('Once during your turn (before your attack), you may heal 20 damage from each of your Pokémon.',card.ability['text'])
self.assertEqual('130', card.hp)
self.assertEqual(['Colorless', 'Colorless'], card.retreat_cost)
self.assertEqual(2, card.converted_retreat_cost)
self.assertEqual('54', card.number)
self.assertEqual('TOKIYA', card.artist)
self.assertEqual('Rare Holo', card.rarity)
Expand All @@ -44,18 +45,16 @@ def test_find_returns_card(self):

def test_all_with_params_return_cards(self):
with vcr.use_cassette('fixtures/mega_pokemon.yaml'):
cards = Card.where(supertype='pokemon') \
.where(subtype='mega') \
.all()
cards = Card.where(supertype='pokemon', subtype='mega')
self.assertTrue(len(cards) >= 70)

def test_all_with_page_returns_cards(self):
with vcr.use_cassette('fixtures/all_first_page.yaml'):
cards = Card.where(page=1).all()
cards = Card.where(page=1)
self.assertEqual(100, len(cards))

def test_all_with_page_and_page_size_returns_card(self):
with vcr.use_cassette('fixtures/all_first_page_one_card.yaml'):
cards = Card.where(page=1).where(pageSize=1).all()
cards = Card.where(page=1, pageSize=1)
self.assertEqual(1, len(cards))

2 changes: 1 addition & 1 deletion tests/test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_find_returns_set(self):

def test_where_filters_on_name(self):
with vcr.use_cassette('fixtures/filtered_sets.yaml'):
sets = Set.where(name='steam').all()
sets = Set.where(name='steam')

self.assertEqual(1, len(sets))
self.assertEqual('xy11', sets[0].code)
Expand Down

0 comments on commit 3cbc8a7

Please sign in to comment.