mtg_sdk 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +24 -24
- data/.travis.yml +9 -9
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +175 -174
- data/Rakefile +10 -10
- data/lib/mtg_sdk.rb +32 -32
- data/lib/mtg_sdk/card.rb +43 -43
- data/lib/mtg_sdk/changelog.rb +24 -24
- data/lib/mtg_sdk/configuration.rb +8 -8
- data/lib/mtg_sdk/foreign_name.rb +10 -10
- data/lib/mtg_sdk/legality.rb +10 -10
- data/lib/mtg_sdk/query_builder.rb +65 -65
- data/lib/mtg_sdk/representers/card_representer.rb +55 -55
- data/lib/mtg_sdk/representers/changelog_representer.rb +12 -12
- data/lib/mtg_sdk/representers/foreign_name_representer.rb +11 -11
- data/lib/mtg_sdk/representers/legality_representer.rb +9 -9
- data/lib/mtg_sdk/representers/ruling_representer.rb +11 -11
- data/lib/mtg_sdk/representers/set_representer.rb +21 -21
- data/lib/mtg_sdk/rest_client.rb +31 -31
- data/lib/mtg_sdk/ruling.rb +10 -10
- data/lib/mtg_sdk/set.rb +61 -53
- data/lib/mtg_sdk/subtype.rb +11 -11
- data/lib/mtg_sdk/supertype.rb +11 -11
- data/lib/mtg_sdk/type.rb +11 -11
- data/lib/mtg_sdk/version.rb +3 -3
- data/mtg_sdk.gemspec +36 -36
- data/test/card_test.rb +80 -66
- data/test/changelog_test.rb +11 -11
- data/test/configuration_test.rb +19 -9
- data/test/responses/no_cards.json +1 -0
- data/test/responses/sample_cards.json +1 -0
- data/test/set_test.rb +51 -41
- data/test/subtype_test.rb +11 -11
- data/test/supertype_test.rb +11 -11
- data/test/test_helper.rb +21 -21
- data/test/type_test.rb +11 -11
- metadata +7 -3
data/Rakefile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
require 'rake/testtask'
|
3
|
-
require_relative 'lib/mtg_sdk'
|
4
|
-
|
5
|
-
task :default => :test
|
6
|
-
|
7
|
-
Rake::TestTask.new do |t|
|
8
|
-
t.libs << "test"
|
9
|
-
t.test_files = FileList['test/*_test.rb']
|
10
|
-
t.verbose = true
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rake/testtask'
|
3
|
+
require_relative 'lib/mtg_sdk'
|
4
|
+
|
5
|
+
task :default => :test
|
6
|
+
|
7
|
+
Rake::TestTask.new do |t|
|
8
|
+
t.libs << "test"
|
9
|
+
t.test_files = FileList['test/*_test.rb']
|
10
|
+
t.verbose = true
|
11
11
|
end
|
data/lib/mtg_sdk.rb
CHANGED
@@ -1,33 +1,33 @@
|
|
1
|
-
require "mtg_sdk/version"
|
2
|
-
require "mtg_sdk/configuration"
|
3
|
-
require "mtg_sdk/card"
|
4
|
-
require "mtg_sdk/legality"
|
5
|
-
require "mtg_sdk/foreign_name"
|
6
|
-
require "mtg_sdk/ruling"
|
7
|
-
require "mtg_sdk/set"
|
8
|
-
require "mtg_sdk/type"
|
9
|
-
require "mtg_sdk/subtype"
|
10
|
-
require "mtg_sdk/supertype"
|
11
|
-
require "mtg_sdk/changelog"
|
12
|
-
require "mtg_sdk/rest_client"
|
13
|
-
require "mtg_sdk/query_builder"
|
14
|
-
|
15
|
-
module MTG
|
16
|
-
API_URL = 'https://api.magicthegathering.io'
|
17
|
-
|
18
|
-
class << self
|
19
|
-
attr_writer :configuration
|
20
|
-
end
|
21
|
-
|
22
|
-
def self.configuration
|
23
|
-
@configuration ||= Configuration.new
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.configure
|
27
|
-
yield(configuration)
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.reset
|
31
|
-
@configuration = Configuration.new
|
32
|
-
end
|
1
|
+
require "mtg_sdk/version"
|
2
|
+
require "mtg_sdk/configuration"
|
3
|
+
require "mtg_sdk/card"
|
4
|
+
require "mtg_sdk/legality"
|
5
|
+
require "mtg_sdk/foreign_name"
|
6
|
+
require "mtg_sdk/ruling"
|
7
|
+
require "mtg_sdk/set"
|
8
|
+
require "mtg_sdk/type"
|
9
|
+
require "mtg_sdk/subtype"
|
10
|
+
require "mtg_sdk/supertype"
|
11
|
+
require "mtg_sdk/changelog"
|
12
|
+
require "mtg_sdk/rest_client"
|
13
|
+
require "mtg_sdk/query_builder"
|
14
|
+
|
15
|
+
module MTG
|
16
|
+
API_URL = 'https://api.magicthegathering.io'
|
17
|
+
|
18
|
+
class << self
|
19
|
+
attr_writer :configuration
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.configuration
|
23
|
+
@configuration ||= Configuration.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.configure
|
27
|
+
yield(configuration)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.reset
|
31
|
+
@configuration = Configuration.new
|
32
|
+
end
|
33
33
|
end
|
data/lib/mtg_sdk/card.rb
CHANGED
@@ -1,44 +1,44 @@
|
|
1
|
-
require_relative 'representers/card_representer'
|
2
|
-
|
3
|
-
module MTG
|
4
|
-
class Card
|
5
|
-
include Roar::JSON
|
6
|
-
include CardRepresenter
|
7
|
-
|
8
|
-
attr_accessor :name, :layout, :names, :mana_cost, :cmc, :colors, :type, :supertypes, :subtypes, :types,
|
9
|
-
:rarity, :text, :flavor, :artist, :number, :power, :toughness, :loyalty, :multiverse_id, :variations,
|
10
|
-
:watermark, :border, :timeshifted, :hand, :life, :reserved, :release_date, :starter,
|
11
|
-
:rulings, :foreign_names, :printings, :original_text, :original_type, :legalities,
|
12
|
-
:source, :image_url, :set, :id, :set_name
|
13
|
-
|
14
|
-
# Get the resource string
|
15
|
-
#
|
16
|
-
# @return [String] The API resource string
|
17
|
-
def self.Resource
|
18
|
-
"cards"
|
19
|
-
end
|
20
|
-
|
21
|
-
# Find a single card by the card multiverse id
|
22
|
-
#
|
23
|
-
# @param id [Integer] the multiverse id
|
24
|
-
# @return [Card] the Card object response
|
25
|
-
def self.find(id)
|
26
|
-
QueryBuilder.new(Card).find(id)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Get all cards from a query by paging through data
|
30
|
-
#
|
31
|
-
# @return [Array<Card>] Array of Card objects
|
32
|
-
def self.all
|
33
|
-
QueryBuilder.new(Card).all
|
34
|
-
end
|
35
|
-
|
36
|
-
# Adds a parameter to the hash of query parameters
|
37
|
-
#
|
38
|
-
# @param args [Hash] the query parameter
|
39
|
-
# @return [QueryBuilder] the QueryBuilder
|
40
|
-
def self.where(args)
|
41
|
-
QueryBuilder.new(Card).where(args)
|
42
|
-
end
|
43
|
-
end
|
1
|
+
require_relative 'representers/card_representer'
|
2
|
+
|
3
|
+
module MTG
|
4
|
+
class Card
|
5
|
+
include Roar::JSON
|
6
|
+
include CardRepresenter
|
7
|
+
|
8
|
+
attr_accessor :name, :layout, :names, :mana_cost, :cmc, :colors, :type, :supertypes, :subtypes, :types,
|
9
|
+
:rarity, :text, :flavor, :artist, :number, :power, :toughness, :loyalty, :multiverse_id, :variations,
|
10
|
+
:watermark, :border, :timeshifted, :hand, :life, :reserved, :release_date, :starter,
|
11
|
+
:rulings, :foreign_names, :printings, :original_text, :original_type, :legalities,
|
12
|
+
:source, :image_url, :set, :id, :set_name
|
13
|
+
|
14
|
+
# Get the resource string
|
15
|
+
#
|
16
|
+
# @return [String] The API resource string
|
17
|
+
def self.Resource
|
18
|
+
"cards"
|
19
|
+
end
|
20
|
+
|
21
|
+
# Find a single card by the card multiverse id
|
22
|
+
#
|
23
|
+
# @param id [Integer] the multiverse id
|
24
|
+
# @return [Card] the Card object response
|
25
|
+
def self.find(id)
|
26
|
+
QueryBuilder.new(Card).find(id)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Get all cards from a query by paging through data
|
30
|
+
#
|
31
|
+
# @return [Array<Card>] Array of Card objects
|
32
|
+
def self.all
|
33
|
+
QueryBuilder.new(Card).all
|
34
|
+
end
|
35
|
+
|
36
|
+
# Adds a parameter to the hash of query parameters
|
37
|
+
#
|
38
|
+
# @param args [Hash] the query parameter
|
39
|
+
# @return [QueryBuilder] the QueryBuilder
|
40
|
+
def self.where(args)
|
41
|
+
QueryBuilder.new(Card).where(args)
|
42
|
+
end
|
43
|
+
end
|
44
44
|
end
|
data/lib/mtg_sdk/changelog.rb
CHANGED
@@ -1,24 +1,24 @@
|
|
1
|
-
require_relative 'representers/changelog_representer'
|
2
|
-
|
3
|
-
module MTG
|
4
|
-
class Changelog
|
5
|
-
include Roar::JSON
|
6
|
-
include ChangelogRepresenter
|
7
|
-
|
8
|
-
attr_accessor :version, :details, :release_date
|
9
|
-
|
10
|
-
# Get the resource string
|
11
|
-
#
|
12
|
-
# @return [string] The API resource string
|
13
|
-
def self.Resource
|
14
|
-
"changelogs"
|
15
|
-
end
|
16
|
-
|
17
|
-
# Get all changelogs
|
18
|
-
#
|
19
|
-
# @return [Array<Changelog>] Array of Changelog objects
|
20
|
-
def self.all
|
21
|
-
QueryBuilder.new(Changelog).all
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
1
|
+
require_relative 'representers/changelog_representer'
|
2
|
+
|
3
|
+
module MTG
|
4
|
+
class Changelog
|
5
|
+
include Roar::JSON
|
6
|
+
include ChangelogRepresenter
|
7
|
+
|
8
|
+
attr_accessor :version, :details, :release_date
|
9
|
+
|
10
|
+
# Get the resource string
|
11
|
+
#
|
12
|
+
# @return [string] The API resource string
|
13
|
+
def self.Resource
|
14
|
+
"changelogs"
|
15
|
+
end
|
16
|
+
|
17
|
+
# Get all changelogs
|
18
|
+
#
|
19
|
+
# @return [Array<Changelog>] Array of Changelog objects
|
20
|
+
def self.all
|
21
|
+
QueryBuilder.new(Changelog).all
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,9 +1,9 @@
|
|
1
|
-
module MTG
|
2
|
-
class Configuration
|
3
|
-
attr_accessor :api_version
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
@api_version = 1
|
7
|
-
end
|
8
|
-
end
|
1
|
+
module MTG
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :api_version
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@api_version = 1
|
7
|
+
end
|
8
|
+
end
|
9
9
|
end
|
data/lib/mtg_sdk/foreign_name.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require_relative 'representers/foreign_name_representer'
|
2
|
-
|
3
|
-
module MTG
|
4
|
-
class ForeignName
|
5
|
-
include Roar::JSON
|
6
|
-
include LegalityRepresenter
|
7
|
-
|
8
|
-
attr_accessor :language, :name, :multiverse_id, :image_url
|
9
|
-
end
|
10
|
-
end
|
1
|
+
require_relative 'representers/foreign_name_representer'
|
2
|
+
|
3
|
+
module MTG
|
4
|
+
class ForeignName
|
5
|
+
include Roar::JSON
|
6
|
+
include LegalityRepresenter
|
7
|
+
|
8
|
+
attr_accessor :language, :name, :multiverse_id, :image_url
|
9
|
+
end
|
10
|
+
end
|
data/lib/mtg_sdk/legality.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require_relative 'representers/legality_representer'
|
2
|
-
|
3
|
-
module MTG
|
4
|
-
class Legality
|
5
|
-
include Roar::JSON
|
6
|
-
include LegalityRepresenter
|
7
|
-
|
8
|
-
attr_accessor :format, :legality
|
9
|
-
end
|
10
|
-
end
|
1
|
+
require_relative 'representers/legality_representer'
|
2
|
+
|
3
|
+
module MTG
|
4
|
+
class Legality
|
5
|
+
include Roar::JSON
|
6
|
+
include LegalityRepresenter
|
7
|
+
|
8
|
+
attr_accessor :format, :legality
|
9
|
+
end
|
10
|
+
end
|
@@ -1,66 +1,66 @@
|
|
1
|
-
module MTG
|
2
|
-
class QueryBuilder
|
3
|
-
include RestClient
|
4
|
-
attr_accessor :type, :query
|
5
|
-
|
6
|
-
def initialize(type)
|
7
|
-
@type = type
|
8
|
-
@query = {}
|
9
|
-
end
|
10
|
-
|
11
|
-
# Adds a parameter to the hash of query parameters
|
12
|
-
#
|
13
|
-
# @param args [Hash] the query parameter
|
14
|
-
# @return [QueryBuilder] the QueryBuilder
|
15
|
-
def where(args)
|
16
|
-
@query.merge!(args)
|
17
|
-
self
|
18
|
-
end
|
19
|
-
|
20
|
-
# Find a single resource by the resource id
|
21
|
-
#
|
22
|
-
# @param id [String] the resource id
|
23
|
-
# @return [Object] the Type object response
|
24
|
-
def find(id)
|
25
|
-
response = RestClient.get("#{@type.Resource}/#{id}")
|
26
|
-
singular_resource = @type.Resource[0...-1]
|
27
|
-
if response.body[singular_resource].nil?
|
28
|
-
raise ArgumentError, 'Resource not found'
|
29
|
-
end
|
30
|
-
|
31
|
-
type.new.from_json(response.body[singular_resource].to_json)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Get all resources from a query by paging through data
|
35
|
-
#
|
36
|
-
# @return [Array<Object>] Array of resources
|
37
|
-
def all
|
38
|
-
list = []
|
39
|
-
page = 1
|
40
|
-
fetch_all = true
|
41
|
-
|
42
|
-
if @query.has_key?(:page)
|
43
|
-
page = @query[:page]
|
44
|
-
fetch_all = false
|
45
|
-
end
|
46
|
-
|
47
|
-
while true
|
48
|
-
response = RestClient.get(@type.Resource, @query)
|
49
|
-
data = response.body[@type.Resource]
|
50
|
-
if !data.empty?
|
51
|
-
data.each {|item| list << @type.new.from_json(item.to_json)}
|
52
|
-
|
53
|
-
if !fetch_all
|
54
|
-
break
|
55
|
-
else
|
56
|
-
where(page: page += 1)
|
57
|
-
end
|
58
|
-
else
|
59
|
-
break
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
return list
|
64
|
-
end
|
65
|
-
end
|
1
|
+
module MTG
|
2
|
+
class QueryBuilder
|
3
|
+
include RestClient
|
4
|
+
attr_accessor :type, :query
|
5
|
+
|
6
|
+
def initialize(type)
|
7
|
+
@type = type
|
8
|
+
@query = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
# Adds a parameter to the hash of query parameters
|
12
|
+
#
|
13
|
+
# @param args [Hash] the query parameter
|
14
|
+
# @return [QueryBuilder] the QueryBuilder
|
15
|
+
def where(args)
|
16
|
+
@query.merge!(args)
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
# Find a single resource by the resource id
|
21
|
+
#
|
22
|
+
# @param id [String] the resource id
|
23
|
+
# @return [Object] the Type object response
|
24
|
+
def find(id)
|
25
|
+
response = RestClient.get("#{@type.Resource}/#{id}")
|
26
|
+
singular_resource = @type.Resource[0...-1]
|
27
|
+
if response.body[singular_resource].nil?
|
28
|
+
raise ArgumentError, 'Resource not found'
|
29
|
+
end
|
30
|
+
|
31
|
+
type.new.from_json(response.body[singular_resource].to_json)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Get all resources from a query by paging through data
|
35
|
+
#
|
36
|
+
# @return [Array<Object>] Array of resources
|
37
|
+
def all
|
38
|
+
list = []
|
39
|
+
page = 1
|
40
|
+
fetch_all = true
|
41
|
+
|
42
|
+
if @query.has_key?(:page)
|
43
|
+
page = @query[:page]
|
44
|
+
fetch_all = false
|
45
|
+
end
|
46
|
+
|
47
|
+
while true
|
48
|
+
response = RestClient.get(@type.Resource, @query)
|
49
|
+
data = response.body[@type.Resource]
|
50
|
+
if !data.empty?
|
51
|
+
data.each {|item| list << @type.new.from_json(item.to_json)}
|
52
|
+
|
53
|
+
if !fetch_all
|
54
|
+
break
|
55
|
+
else
|
56
|
+
where(page: page += 1)
|
57
|
+
end
|
58
|
+
else
|
59
|
+
break
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
return list
|
64
|
+
end
|
65
|
+
end
|
66
66
|
end
|
@@ -1,56 +1,56 @@
|
|
1
|
-
require 'roar/json'
|
2
|
-
require 'roar/coercion'
|
3
|
-
require_relative 'legality_representer'
|
4
|
-
require_relative 'foreign_name_representer'
|
5
|
-
require_relative 'ruling_representer'
|
6
|
-
require_relative '../legality'
|
7
|
-
require_relative '../foreign_name'
|
8
|
-
require_relative '../ruling'
|
9
|
-
|
10
|
-
module MTG
|
11
|
-
module CardRepresenter
|
12
|
-
include Roar::JSON
|
13
|
-
include Roar::Coercion
|
14
|
-
|
15
|
-
property :name
|
16
|
-
property :layout
|
17
|
-
property :mana_cost, as: :manaCost
|
18
|
-
property :cmc
|
19
|
-
property :type
|
20
|
-
property :rarity
|
21
|
-
property :text
|
22
|
-
property :flavor
|
23
|
-
property :artist
|
24
|
-
property :number
|
25
|
-
property :power
|
26
|
-
property :toughness
|
27
|
-
property :loyalty
|
28
|
-
property :multiverse_id, as: :multiverseid
|
29
|
-
property :watermark
|
30
|
-
property :border
|
31
|
-
property :timeshifted
|
32
|
-
property :hand
|
33
|
-
property :life
|
34
|
-
property :reserved
|
35
|
-
property :release_date, as: :releaseDate, type: Date
|
36
|
-
property :starter
|
37
|
-
property :original_text, as: :originalText
|
38
|
-
property :original_type, as: :originalType
|
39
|
-
property :source
|
40
|
-
property :set
|
41
|
-
property :set_name, as: :setName
|
42
|
-
property :id
|
43
|
-
property :image_url, as: :imageUrl
|
44
|
-
|
45
|
-
collection :names
|
46
|
-
collection :supertypes
|
47
|
-
collection :subtypes
|
48
|
-
collection :types
|
49
|
-
collection :colors
|
50
|
-
collection :variations
|
51
|
-
collection :printings
|
52
|
-
collection :legalities, extend: LegalityRepresenter, class: Legality
|
53
|
-
collection :rulings, extend: RulingRepresenter, class: Ruling
|
54
|
-
collection :foreign_names, as: :foreignNames, extend: ForeignNameRepresenter, class: ForeignName
|
55
|
-
end
|
1
|
+
require 'roar/json'
|
2
|
+
require 'roar/coercion'
|
3
|
+
require_relative 'legality_representer'
|
4
|
+
require_relative 'foreign_name_representer'
|
5
|
+
require_relative 'ruling_representer'
|
6
|
+
require_relative '../legality'
|
7
|
+
require_relative '../foreign_name'
|
8
|
+
require_relative '../ruling'
|
9
|
+
|
10
|
+
module MTG
|
11
|
+
module CardRepresenter
|
12
|
+
include Roar::JSON
|
13
|
+
include Roar::Coercion
|
14
|
+
|
15
|
+
property :name
|
16
|
+
property :layout
|
17
|
+
property :mana_cost, as: :manaCost
|
18
|
+
property :cmc
|
19
|
+
property :type
|
20
|
+
property :rarity
|
21
|
+
property :text
|
22
|
+
property :flavor
|
23
|
+
property :artist
|
24
|
+
property :number
|
25
|
+
property :power
|
26
|
+
property :toughness
|
27
|
+
property :loyalty
|
28
|
+
property :multiverse_id, as: :multiverseid
|
29
|
+
property :watermark
|
30
|
+
property :border
|
31
|
+
property :timeshifted
|
32
|
+
property :hand
|
33
|
+
property :life
|
34
|
+
property :reserved
|
35
|
+
property :release_date, as: :releaseDate, type: Date
|
36
|
+
property :starter
|
37
|
+
property :original_text, as: :originalText
|
38
|
+
property :original_type, as: :originalType
|
39
|
+
property :source
|
40
|
+
property :set
|
41
|
+
property :set_name, as: :setName
|
42
|
+
property :id
|
43
|
+
property :image_url, as: :imageUrl
|
44
|
+
|
45
|
+
collection :names
|
46
|
+
collection :supertypes
|
47
|
+
collection :subtypes
|
48
|
+
collection :types
|
49
|
+
collection :colors
|
50
|
+
collection :variations
|
51
|
+
collection :printings
|
52
|
+
collection :legalities, extend: LegalityRepresenter, class: Legality
|
53
|
+
collection :rulings, extend: RulingRepresenter, class: Ruling
|
54
|
+
collection :foreign_names, as: :foreignNames, extend: ForeignNameRepresenter, class: ForeignName
|
55
|
+
end
|
56
56
|
end
|