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

Allow a search parameter on getCards() #8

Open
wants to merge 6 commits into
base: dev
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
## 1.0.2

* Added search parameter

## 1.0.1

* Refactor tests
* Export data models

## 1.0.0

* All endpoints implemented 🎉
* Make some fields nullable in card.dart

## 0.3.0

* Add `getCard()` functions

## 0.2.0
Expand Down
37 changes: 22 additions & 15 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.6.1"
version: "2.9.0"
boolean_selector:
dependency: transitive
description:
Expand All @@ -21,7 +21,7 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.1"
charcode:
dependency: transitive
description:
Expand All @@ -35,14 +35,14 @@ packages:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
cupertino_icons:
dependency: "direct main"
description:
Expand All @@ -56,7 +56,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.1"
flutter:
dependency: "direct main"
description: flutter
Expand Down Expand Up @@ -87,21 +87,28 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
version: "0.12.12"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.5"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.8.0"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.2"
pedantic:
dependency: transitive
description:
Expand All @@ -115,7 +122,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.1"
version: "1.0.2"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -127,7 +134,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.9.0"
stack_trace:
dependency: transitive
description:
Expand All @@ -148,21 +155,21 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
version: "0.4.12"
typed_data:
dependency: transitive
description:
Expand All @@ -176,7 +183,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.2"
sdks:
dart: ">=2.13.0 <3.0.0"
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=1.17.0"
11 changes: 8 additions & 3 deletions lib/src/pokemon_tcg.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:isolate';

import 'package:http/http.dart' as http;
import 'package:pokemon_tcg/src/models/card.dart';
Expand All @@ -21,28 +22,32 @@ class PokemonTcgApi {
static const _baseUrl = 'https://api.pokemontcg.io/v2';
static const _setsUrl = '$_baseUrl/sets';

/// Gets a paginated list of all pokemon cards.
/// Gets a paginated list of all pokemon cards by default, with an optional search parameter.
Future<List<PokemonCard>> getCards({
int page = 0,
String query = '',
}) async {
http.Response response;
if (page == 0) {
response = await client.get(
Uri.parse('$_baseUrl/cards'),
Uri.parse('$_baseUrl/cards?q=$query'),
headers: {
'x-api-key': apiKey,
},
);
} else {
response = await client.get(
Uri.parse('$_baseUrl/cards?page=$page'),
Uri.parse('$_baseUrl/cards?q=$query&page=$page'),
headers: {
'x-api-key': apiKey,
},
);
}

JsonMap json = jsonDecode(response.body);
if (json.containsKey("error")) {
throw RemoteError('Invalid search parameter', json['error']['message']);
}
final cards = <PokemonCard>[];
List<dynamic> cardsJson = json['data'];
cardsJson.forEach((element) {
Expand Down
37 changes: 22 additions & 15 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ packages:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.1"
version: "1.7.2"
args:
dependency: transitive
description:
Expand All @@ -28,7 +28,7 @@ packages:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.6.1"
version: "2.9.0"
boolean_selector:
dependency: transitive
description:
Expand Down Expand Up @@ -63,7 +63,7 @@ packages:
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.1"
charcode:
dependency: transitive
description:
Expand All @@ -84,7 +84,7 @@ packages:
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
code_builder:
dependency: transitive
description:
Expand All @@ -98,7 +98,7 @@ packages:
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
version: "1.16.0"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -126,7 +126,7 @@ packages:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.3.1"
file:
dependency: transitive
description:
Expand Down Expand Up @@ -185,14 +185,21 @@ packages:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.10"
version: "0.12.12"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.5"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
version: "1.8.0"
mockito:
dependency: "direct dev"
description:
Expand All @@ -213,7 +220,7 @@ packages:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
version: "1.8.2"
pedantic:
dependency: transitive
description:
Expand Down Expand Up @@ -246,7 +253,7 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
version: "1.9.0"
stack_trace:
dependency: transitive
description:
Expand All @@ -267,21 +274,21 @@ packages:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.1.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
version: "1.2.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
version: "0.4.12"
typed_data:
dependency: transitive
description:
Expand All @@ -295,7 +302,7 @@ packages:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.0"
version: "2.1.2"
watcher:
dependency: transitive
description:
Expand All @@ -311,5 +318,5 @@ packages:
source: hosted
version: "3.1.0"
sdks:
dart: ">=2.13.0 <3.0.0"
dart: ">=2.17.0-0 <3.0.0"
flutter: ">=1.17.0"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: pokemon_tcg
description: A Dart SDK for the Pokemon TCG Developers API. An API key is required to use.
version: 1.0.1
version: 1.0.2
homepage: https://github.com/PokemonTCG/pokemon-tcg-sdk-dart
issue_tracker: https://github.com/PokemonTCG/pokemon-tcg-sdk-dart/issues

Expand Down