pokemon_tcg_sdk 3.0.0 → 4.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.editorconfig +3 -0
- data/.github/workflows/test.yml +35 -0
- data/.gitignore +23 -24
- data/CODE_OF_CONDUCT.md +48 -48
- data/Gemfile +4 -4
- data/LICENSE.txt +21 -21
- data/README.md +184 -159
- data/Rakefile +20 -10
- data/lib/pokemon_tcg_sdk.rb +38 -31
- data/lib/pokemon_tcg_sdk/ability.rb +14 -10
- data/lib/pokemon_tcg_sdk/ancient_trait.rb +13 -10
- data/lib/pokemon_tcg_sdk/attack.rb +16 -10
- data/lib/pokemon_tcg_sdk/card.rb +69 -42
- data/lib/pokemon_tcg_sdk/card_images.rb +13 -0
- data/lib/pokemon_tcg_sdk/configuration.rb +8 -8
- data/lib/pokemon_tcg_sdk/legalities.rb +14 -0
- data/lib/pokemon_tcg_sdk/query_builder.rb +63 -67
- data/lib/pokemon_tcg_sdk/rarity.rb +12 -0
- data/lib/pokemon_tcg_sdk/resistance.rb +14 -0
- data/lib/pokemon_tcg_sdk/rest_client.rb +46 -31
- data/lib/pokemon_tcg_sdk/set.rb +50 -40
- data/lib/pokemon_tcg_sdk/set_images.rb +13 -0
- data/lib/pokemon_tcg_sdk/subtype.rb +11 -11
- data/lib/pokemon_tcg_sdk/supertype.rb +11 -11
- data/lib/pokemon_tcg_sdk/tcgplayer.rb +44 -0
- data/lib/pokemon_tcg_sdk/type.rb +11 -11
- data/lib/pokemon_tcg_sdk/version.rb +3 -3
- data/lib/pokemon_tcg_sdk/weakness.rb +13 -0
- data/pokemon_tcg_sdk.gemspec +32 -33
- metadata +34 -48
- data/.travis.yml +0 -15
- data/lib/pokemon_tcg_sdk/representers/ability_representer.rb +0 -11
- data/lib/pokemon_tcg_sdk/representers/ancient_trait_representer.rb +0 -10
- data/lib/pokemon_tcg_sdk/representers/attack_representer.rb +0 -13
- data/lib/pokemon_tcg_sdk/representers/card_representer.rb +0 -41
- data/lib/pokemon_tcg_sdk/representers/set_representer.rb +0 -19
- data/lib/pokemon_tcg_sdk/representers/type_value_representer.rb +0 -10
- data/lib/pokemon_tcg_sdk/type_value.rb +0 -10
data/Rakefile
CHANGED
@@ -1,11 +1,21 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require 'rake/testtask'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
t.libs << "
|
9
|
-
t.
|
10
|
-
t.
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rake/testtask'
|
3
|
+
require_relative 'lib/pokemon_tcg_sdk'
|
4
|
+
|
5
|
+
task :default => :test
|
6
|
+
|
7
|
+
Rake::TestTask.new do |t|
|
8
|
+
t.libs << "lib"
|
9
|
+
t.libs << "test"
|
10
|
+
t.test_files = FileList['test/*_test.rb']
|
11
|
+
t.verbose = true
|
12
|
+
end
|
13
|
+
|
14
|
+
Pokemon.configure do |config|
|
15
|
+
config.api_key = ENV['POKEMON_API_KEY']
|
16
|
+
end
|
17
|
+
|
18
|
+
task :card do
|
19
|
+
card = Pokemon::Card.find('xy1-1')
|
20
|
+
puts card.tcgplayer.updated_at
|
11
21
|
end
|
data/lib/pokemon_tcg_sdk.rb
CHANGED
@@ -1,32 +1,39 @@
|
|
1
|
-
require "pokemon_tcg_sdk/version"
|
2
|
-
require "pokemon_tcg_sdk/card"
|
3
|
-
require "pokemon_tcg_sdk/configuration"
|
4
|
-
require "pokemon_tcg_sdk/query_builder"
|
5
|
-
require "pokemon_tcg_sdk/rest_client"
|
6
|
-
require "pokemon_tcg_sdk/ability"
|
7
|
-
require "pokemon_tcg_sdk/attack"
|
8
|
-
require "pokemon_tcg_sdk/
|
9
|
-
require "pokemon_tcg_sdk/
|
10
|
-
require "pokemon_tcg_sdk/
|
11
|
-
require "pokemon_tcg_sdk/
|
12
|
-
require "pokemon_tcg_sdk/
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
1
|
+
require "pokemon_tcg_sdk/version"
|
2
|
+
require "pokemon_tcg_sdk/card"
|
3
|
+
require "pokemon_tcg_sdk/configuration"
|
4
|
+
require "pokemon_tcg_sdk/query_builder"
|
5
|
+
require "pokemon_tcg_sdk/rest_client"
|
6
|
+
require "pokemon_tcg_sdk/ability"
|
7
|
+
require "pokemon_tcg_sdk/attack"
|
8
|
+
require "pokemon_tcg_sdk/type"
|
9
|
+
require "pokemon_tcg_sdk/subtype"
|
10
|
+
require "pokemon_tcg_sdk/supertype"
|
11
|
+
require "pokemon_tcg_sdk/set"
|
12
|
+
require "pokemon_tcg_sdk/weakness"
|
13
|
+
require "pokemon_tcg_sdk/resistance"
|
14
|
+
require "pokemon_tcg_sdk/legalities"
|
15
|
+
require "pokemon_tcg_sdk/card_images"
|
16
|
+
require "pokemon_tcg_sdk/set_images"
|
17
|
+
require "pokemon_tcg_sdk/tcgplayer"
|
18
|
+
require "pokemon_tcg_sdk/ancient_trait"
|
19
|
+
require "pokemon_tcg_sdk/rarity"
|
20
|
+
|
21
|
+
module Pokemon
|
22
|
+
API_URL = 'https://api.pokemontcg.io'
|
23
|
+
|
24
|
+
class << self
|
25
|
+
attr_writer :configuration
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.configuration
|
29
|
+
@configuration ||= Configuration.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.configure
|
33
|
+
yield(configuration)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.reset
|
37
|
+
@configuration = Configuration.new
|
38
|
+
end
|
32
39
|
end
|
@@ -1,10 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
module Pokemon
|
2
|
+
class Ability
|
3
|
+
attr_accessor :name, :text, :type
|
4
|
+
|
5
|
+
def self.from_json(json)
|
6
|
+
ability = Ability.new
|
7
|
+
ability.name = json['name']
|
8
|
+
ability.text = json['text']
|
9
|
+
ability.type = json['type']
|
10
|
+
|
11
|
+
ability
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,10 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
module Pokemon
|
2
|
+
class AncientTrait
|
3
|
+
attr_accessor :name, :text
|
4
|
+
|
5
|
+
def self.from_json(json)
|
6
|
+
trait = AncientTrait.new
|
7
|
+
trait.name = json['name']
|
8
|
+
trait.text = json['text']
|
9
|
+
|
10
|
+
trait
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,10 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
module Pokemon
|
2
|
+
class Attack
|
3
|
+
attr_accessor :cost, :name, :text, :damage, :converted_energy_cost
|
4
|
+
|
5
|
+
def self.from_json(json)
|
6
|
+
attack = Attack.new
|
7
|
+
attack.cost = json['cost']
|
8
|
+
attack.name = json['name']
|
9
|
+
attack.text = json['text']
|
10
|
+
attack.damage = json['damage']
|
11
|
+
attack.converted_energy_cost = json['convertedEnergyCost']
|
12
|
+
|
13
|
+
attack
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/pokemon_tcg_sdk/card.rb
CHANGED
@@ -1,43 +1,70 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
module Pokemon
|
4
|
-
class Card
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module Pokemon
|
4
|
+
class Card
|
5
|
+
attr_accessor :id, :name, :supertype, :subtypes, :level, :hp, :types, :evolves_from, :evolves_to, :rules, :ancient_trait,
|
6
|
+
:abilities, :attacks, :weaknesses, :resistances, :retreat_cost, :converted_retreat_cost, :set, :number, :artist, :rarity, :national_pokedex_numbers,
|
7
|
+
:legalities, :tcgplayer, :images, :flavor_text
|
8
|
+
|
9
|
+
def self.from_json(json)
|
10
|
+
card = Card.new
|
11
|
+
card.id = json['id']
|
12
|
+
card.name = json['name']
|
13
|
+
card.supertype = json['supertype']
|
14
|
+
card.subtypes = json['subtypes']
|
15
|
+
card.level = json['level']
|
16
|
+
card.hp = json['hp']
|
17
|
+
card.types = json['types']
|
18
|
+
card.evolves_from = json['evolvesFrom']
|
19
|
+
card.evolves_to = json['evolvesTo']
|
20
|
+
card.rules = json['rules']
|
21
|
+
card.ancient_trait = AncientTrait.from_json(json['ancientTrait']) if !json['ancientTrait'].nil?
|
22
|
+
card.abilities = json['abilities'].map {|ability_json| Ability.from_json(ability_json)} if !json['abilities'].nil?
|
23
|
+
card.attacks = json['attacks'].map {|attack_json| Attack.from_json(attack_json)} if !json['attacks'].nil?
|
24
|
+
card.weaknesses = json['weaknesses'].map {|weakness_json| Weakness.from_json(weakness_json)} if !json['weaknesses'].nil?
|
25
|
+
card.resistances = json['resistances'].map {|resistance_json| Resistance.from_json(resistance_json)} if !json['resistances'].nil?
|
26
|
+
card.retreat_cost = json['retreatCost']
|
27
|
+
card.converted_retreat_cost = json['convertedRetreatCost']
|
28
|
+
card.set = Set.from_json(json['set']) if !json['set'].nil?
|
29
|
+
card.number = json['number']
|
30
|
+
card.artist = json['artist']
|
31
|
+
card.rarity = json['rarity']
|
32
|
+
card.flavor_text = json['flavorText']
|
33
|
+
card.national_pokedex_numbers = json['nationalPokedexNumbers']
|
34
|
+
card.legalities = Legalities.from_json(json['legalities']) if !json['legalities'].nil?
|
35
|
+
card.tcgplayer = Tcgplayer.from_json(json['tcgplayer']) if !json['tcgplayer'].nil?
|
36
|
+
card.images = CardImages.from_json(json['images']) if !json['images'].nil?
|
37
|
+
card
|
38
|
+
end
|
39
|
+
|
40
|
+
# Get the resource string
|
41
|
+
#
|
42
|
+
# @return [String] The API resource string
|
43
|
+
def self.Resource
|
44
|
+
"cards"
|
45
|
+
end
|
46
|
+
|
47
|
+
# Find a single card by the card id
|
48
|
+
#
|
49
|
+
# @param id [String] the card id
|
50
|
+
# @return [Card] the Card object response
|
51
|
+
def self.find(id)
|
52
|
+
QueryBuilder.new(Card).find(ERB::Util.url_encode(id))
|
53
|
+
end
|
54
|
+
|
55
|
+
# Get all cards from a query by paging through data
|
56
|
+
#
|
57
|
+
# @return [Array<Card>] Array of Card objects
|
58
|
+
def self.all
|
59
|
+
QueryBuilder.new(Card).all
|
60
|
+
end
|
61
|
+
|
62
|
+
# Adds a parameter to the hash of query parameters
|
63
|
+
#
|
64
|
+
# @param args [Hash] the query parameter
|
65
|
+
# @return [Array<Card>] Array of Card objects
|
66
|
+
def self.where(args)
|
67
|
+
QueryBuilder.new(Card).where(args)
|
68
|
+
end
|
69
|
+
end
|
43
70
|
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module Pokemon
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
8
|
-
end
|
1
|
+
module Pokemon
|
2
|
+
# Placeholder for future configuration options
|
3
|
+
class Configuration
|
4
|
+
attr_accessor :api_key
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
end
|
8
|
+
end
|
9
9
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Pokemon
|
2
|
+
class Legalities
|
3
|
+
attr_accessor :expanded, :standard, :unlimited
|
4
|
+
|
5
|
+
def self.from_json(json)
|
6
|
+
legality = Legalities.new
|
7
|
+
legality.expanded = json['expanded']
|
8
|
+
legality.standard = json['standard']
|
9
|
+
legality.unlimited = json['unlimited']
|
10
|
+
|
11
|
+
legality
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,68 +1,64 @@
|
|
1
|
-
require_relative 'rest_client'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
#
|
16
|
-
# @
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
#
|
24
|
-
#
|
25
|
-
# @
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
return list
|
66
|
-
end
|
67
|
-
end
|
1
|
+
require_relative 'rest_client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Pokemon
|
5
|
+
class QueryBuilder
|
6
|
+
include RestClient
|
7
|
+
attr_accessor :type, :query
|
8
|
+
|
9
|
+
def initialize(type)
|
10
|
+
@type = type
|
11
|
+
@query = {}
|
12
|
+
end
|
13
|
+
|
14
|
+
# Adds a parameter to the hash of query parameters
|
15
|
+
#
|
16
|
+
# @param args [Hash] the query parameter
|
17
|
+
# @return [QueryBuilder] the QueryBuilder
|
18
|
+
def where(args)
|
19
|
+
@query.merge!(args)
|
20
|
+
self.all
|
21
|
+
end
|
22
|
+
|
23
|
+
# Find a single resource by the resource id
|
24
|
+
#
|
25
|
+
# @param id [String] the resource id
|
26
|
+
# @return [Object] the Type object response
|
27
|
+
def find(id)
|
28
|
+
response = RestClient.get("#{@type.Resource}/#{id}")
|
29
|
+
@type.from_json response['data']
|
30
|
+
end
|
31
|
+
|
32
|
+
# Get all resources from a query by paging through data
|
33
|
+
#
|
34
|
+
# @return [Array<Object>] Array of resources
|
35
|
+
def all
|
36
|
+
list = []
|
37
|
+
page = 1
|
38
|
+
fetch_all = true
|
39
|
+
|
40
|
+
if @query.has_key?(:page)
|
41
|
+
page = @query[:page]
|
42
|
+
fetch_all = false
|
43
|
+
end
|
44
|
+
|
45
|
+
while true
|
46
|
+
response = RestClient.get(@type.Resource, @query)
|
47
|
+
data = response['data']
|
48
|
+
if !data.nil? && data.any?
|
49
|
+
data.each {|item| list << @type.from_json(item)}
|
50
|
+
|
51
|
+
if !fetch_all
|
52
|
+
break
|
53
|
+
else
|
54
|
+
@query.merge!(page: page += 1)
|
55
|
+
end
|
56
|
+
else
|
57
|
+
break
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
return list
|
62
|
+
end
|
63
|
+
end
|
68
64
|
end
|