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
@@ -1,13 +1,13 @@
|
|
1
|
-
require 'roar/json'
|
2
|
-
require 'roar/coercion'
|
3
|
-
|
4
|
-
module MTG
|
5
|
-
module ChangelogRepresenter
|
6
|
-
include Roar::JSON
|
7
|
-
include Roar::Coercion
|
8
|
-
|
9
|
-
property :release_date, as: :releaseDate, type: Date
|
10
|
-
property :version
|
11
|
-
property :details
|
12
|
-
end
|
1
|
+
require 'roar/json'
|
2
|
+
require 'roar/coercion'
|
3
|
+
|
4
|
+
module MTG
|
5
|
+
module ChangelogRepresenter
|
6
|
+
include Roar::JSON
|
7
|
+
include Roar::Coercion
|
8
|
+
|
9
|
+
property :release_date, as: :releaseDate, type: Date
|
10
|
+
property :version
|
11
|
+
property :details
|
12
|
+
end
|
13
13
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require 'roar/json'
|
2
|
-
|
3
|
-
module MTG
|
4
|
-
module ForeignNameRepresenter
|
5
|
-
include Roar::JSON
|
6
|
-
|
7
|
-
property :name
|
8
|
-
property :language
|
9
|
-
property :multiverse_id, as: :multiverseid
|
10
|
-
property :image_url, as: :imageUrl
|
11
|
-
end
|
1
|
+
require 'roar/json'
|
2
|
+
|
3
|
+
module MTG
|
4
|
+
module ForeignNameRepresenter
|
5
|
+
include Roar::JSON
|
6
|
+
|
7
|
+
property :name
|
8
|
+
property :language
|
9
|
+
property :multiverse_id, as: :multiverseid
|
10
|
+
property :image_url, as: :imageUrl
|
11
|
+
end
|
12
12
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require 'roar/json'
|
2
|
-
|
3
|
-
module MTG
|
4
|
-
module LegalityRepresenter
|
5
|
-
include Roar::JSON
|
6
|
-
|
7
|
-
property :format
|
8
|
-
property :legality
|
9
|
-
end
|
1
|
+
require 'roar/json'
|
2
|
+
|
3
|
+
module MTG
|
4
|
+
module LegalityRepresenter
|
5
|
+
include Roar::JSON
|
6
|
+
|
7
|
+
property :format
|
8
|
+
property :legality
|
9
|
+
end
|
10
10
|
end
|
@@ -1,12 +1,12 @@
|
|
1
|
-
require 'roar/json'
|
2
|
-
require 'roar/coercion'
|
3
|
-
|
4
|
-
module MTG
|
5
|
-
module RulingRepresenter
|
6
|
-
include Roar::JSON
|
7
|
-
include Roar::Coercion
|
8
|
-
|
9
|
-
property :date, type: Date
|
10
|
-
property :text
|
11
|
-
end
|
1
|
+
require 'roar/json'
|
2
|
+
require 'roar/coercion'
|
3
|
+
|
4
|
+
module MTG
|
5
|
+
module RulingRepresenter
|
6
|
+
include Roar::JSON
|
7
|
+
include Roar::Coercion
|
8
|
+
|
9
|
+
property :date, type: Date
|
10
|
+
property :text
|
11
|
+
end
|
12
12
|
end
|
@@ -1,22 +1,22 @@
|
|
1
|
-
require 'roar/json'
|
2
|
-
|
3
|
-
module MTG
|
4
|
-
module SetRepresenter
|
5
|
-
include Roar::JSON
|
6
|
-
|
7
|
-
property :code
|
8
|
-
property :name
|
9
|
-
property :type
|
10
|
-
property :border
|
11
|
-
property :mkm_id
|
12
|
-
property :mkm_name
|
13
|
-
property :block
|
14
|
-
property :old_code, as: :oldCode
|
15
|
-
property :online_only, as: :onlineOnly
|
16
|
-
property :release_date, as: :releaseDate
|
17
|
-
property :gatherer_code, as: :gatherCode
|
18
|
-
property :magic_cards_info_code, as: :magicCardsInfoCode
|
19
|
-
|
20
|
-
collection :booster
|
21
|
-
end
|
1
|
+
require 'roar/json'
|
2
|
+
|
3
|
+
module MTG
|
4
|
+
module SetRepresenter
|
5
|
+
include Roar::JSON
|
6
|
+
|
7
|
+
property :code
|
8
|
+
property :name
|
9
|
+
property :type
|
10
|
+
property :border
|
11
|
+
property :mkm_id
|
12
|
+
property :mkm_name
|
13
|
+
property :block
|
14
|
+
property :old_code, as: :oldCode
|
15
|
+
property :online_only, as: :onlineOnly
|
16
|
+
property :release_date, as: :releaseDate
|
17
|
+
property :gatherer_code, as: :gatherCode
|
18
|
+
property :magic_cards_info_code, as: :magicCardsInfoCode
|
19
|
+
|
20
|
+
collection :booster
|
21
|
+
end
|
22
22
|
end
|
data/lib/mtg_sdk/rest_client.rb
CHANGED
@@ -1,32 +1,32 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'faraday_middleware'
|
3
|
-
require 'erb'
|
4
|
-
|
5
|
-
module MTG
|
6
|
-
module RestClient
|
7
|
-
|
8
|
-
def self.get(endpoint, params=nil)
|
9
|
-
if params.nil?
|
10
|
-
query = endpoint
|
11
|
-
else
|
12
|
-
query = "#{endpoint}?#{params_to_query(params)}"
|
13
|
-
end
|
14
|
-
|
15
|
-
client.get(query)
|
16
|
-
end
|
17
|
-
|
18
|
-
protected
|
19
|
-
|
20
|
-
def self.client
|
21
|
-
@client = Faraday.new "#{API_URL}/v#{MTG.configuration.api_version}" do |conn|
|
22
|
-
conn.response :xml, :content_type => /\bxml$/
|
23
|
-
conn.response :json, :content_type => /\bjson$/
|
24
|
-
conn.adapter Faraday.default_adapter
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.params_to_query(params)
|
29
|
-
params.map {|p, v| "#{p}=#{ERB::Util.url_encode(v.to_s)}"}.join('&')
|
30
|
-
end
|
31
|
-
end
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday_middleware'
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
module MTG
|
6
|
+
module RestClient
|
7
|
+
|
8
|
+
def self.get(endpoint, params=nil)
|
9
|
+
if params.nil?
|
10
|
+
query = endpoint
|
11
|
+
else
|
12
|
+
query = "#{endpoint}?#{params_to_query(params)}"
|
13
|
+
end
|
14
|
+
|
15
|
+
client.get(query)
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
|
20
|
+
def self.client
|
21
|
+
@client = Faraday.new "#{API_URL}/v#{MTG.configuration.api_version}" do |conn|
|
22
|
+
conn.response :xml, :content_type => /\bxml$/
|
23
|
+
conn.response :json, :content_type => /\bjson$/
|
24
|
+
conn.adapter Faraday.default_adapter
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.params_to_query(params)
|
29
|
+
params.map {|p, v| "#{p}=#{ERB::Util.url_encode(v.to_s)}"}.join('&')
|
30
|
+
end
|
31
|
+
end
|
32
32
|
end
|
data/lib/mtg_sdk/ruling.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require_relative 'representers/ruling_representer'
|
2
|
-
|
3
|
-
module MTG
|
4
|
-
class Ruling
|
5
|
-
include Roar::JSON
|
6
|
-
include RulingRepresenter
|
7
|
-
|
8
|
-
attr_accessor :date, :text
|
9
|
-
end
|
10
|
-
end
|
1
|
+
require_relative 'representers/ruling_representer'
|
2
|
+
|
3
|
+
module MTG
|
4
|
+
class Ruling
|
5
|
+
include Roar::JSON
|
6
|
+
include RulingRepresenter
|
7
|
+
|
8
|
+
attr_accessor :date, :text
|
9
|
+
end
|
10
|
+
end
|
data/lib/mtg_sdk/set.rb
CHANGED
@@ -1,53 +1,61 @@
|
|
1
|
-
require_relative 'representers/set_representer'
|
2
|
-
require_relative 'card'
|
3
|
-
require_relative 'rest_client'
|
4
|
-
|
5
|
-
module MTG
|
6
|
-
class Set
|
7
|
-
include Roar::JSON
|
8
|
-
include SetRepresenter
|
9
|
-
include RestClient
|
10
|
-
|
11
|
-
attr_accessor :code, :name, :type, :border, :mkm_id, :mkm_name,
|
12
|
-
:release_date, :gatherer_code, :magic_cards_info_code, :booster,
|
13
|
-
:old_code, :block, :online_only
|
14
|
-
|
15
|
-
# Get the resource string
|
16
|
-
#
|
17
|
-
# @return [string] The API resource string
|
18
|
-
def self.Resource
|
19
|
-
"sets"
|
20
|
-
end
|
21
|
-
|
22
|
-
# Find a single set by the set code
|
23
|
-
#
|
24
|
-
# @param code [String] the Set code
|
25
|
-
# @return [Set] a Set object
|
26
|
-
def self.find(code)
|
27
|
-
QueryBuilder.new(Set).find(code)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Get all sets from a query
|
31
|
-
#
|
32
|
-
# @return [Array<Set>] Array of Set objects
|
33
|
-
def self.all
|
34
|
-
QueryBuilder.new(Set).all
|
35
|
-
end
|
36
|
-
|
37
|
-
#
|
38
|
-
|
39
|
-
# @param
|
40
|
-
# @return [
|
41
|
-
def self.
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
cards
|
51
|
-
|
52
|
-
|
53
|
-
|
1
|
+
require_relative 'representers/set_representer'
|
2
|
+
require_relative 'card'
|
3
|
+
require_relative 'rest_client'
|
4
|
+
|
5
|
+
module MTG
|
6
|
+
class Set
|
7
|
+
include Roar::JSON
|
8
|
+
include SetRepresenter
|
9
|
+
include RestClient
|
10
|
+
|
11
|
+
attr_accessor :code, :name, :type, :border, :mkm_id, :mkm_name,
|
12
|
+
:release_date, :gatherer_code, :magic_cards_info_code, :booster,
|
13
|
+
:old_code, :block, :online_only
|
14
|
+
|
15
|
+
# Get the resource string
|
16
|
+
#
|
17
|
+
# @return [string] The API resource string
|
18
|
+
def self.Resource
|
19
|
+
"sets"
|
20
|
+
end
|
21
|
+
|
22
|
+
# Find a single set by the set code
|
23
|
+
#
|
24
|
+
# @param code [String] the Set code
|
25
|
+
# @return [Set] a Set object
|
26
|
+
def self.find(code)
|
27
|
+
QueryBuilder.new(Set).find(code)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Get all sets from a query
|
31
|
+
#
|
32
|
+
# @return [Array<Set>] Array of Set objects
|
33
|
+
def self.all
|
34
|
+
QueryBuilder.new(Set).all
|
35
|
+
end
|
36
|
+
|
37
|
+
# Adds a parameter to the hash of query parameters
|
38
|
+
#
|
39
|
+
# @param args [Hash] the query parameter
|
40
|
+
# @return [QueryBuilder] the QueryBuilder
|
41
|
+
def self.where(args)
|
42
|
+
QueryBuilder.new(Set).where(args)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Generate a booster pack for a specific set
|
46
|
+
|
47
|
+
# @param code [String] the Set code
|
48
|
+
# @return [Array<Card>] Array of Card objects
|
49
|
+
def self.generate_booster(code)
|
50
|
+
cards = []
|
51
|
+
response = RestClient.get("sets/#{code}/booster")
|
52
|
+
data = response.body['cards']
|
53
|
+
|
54
|
+
data.each do |card|
|
55
|
+
cards << Card.new.from_json(card.to_json)
|
56
|
+
end
|
57
|
+
|
58
|
+
cards
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/mtg_sdk/subtype.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
module MTG
|
2
|
-
class Subtype
|
3
|
-
include RestClient
|
4
|
-
|
5
|
-
# Get all subtypes
|
6
|
-
#
|
7
|
-
# @return [Array<String>] All subtypes
|
8
|
-
def self.all
|
9
|
-
RestClient.get('subtypes').body['subtypes']
|
10
|
-
end
|
11
|
-
end
|
1
|
+
module MTG
|
2
|
+
class Subtype
|
3
|
+
include RestClient
|
4
|
+
|
5
|
+
# Get all subtypes
|
6
|
+
#
|
7
|
+
# @return [Array<String>] All subtypes
|
8
|
+
def self.all
|
9
|
+
RestClient.get('subtypes').body['subtypes']
|
10
|
+
end
|
11
|
+
end
|
12
12
|
end
|
data/lib/mtg_sdk/supertype.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
module MTG
|
2
|
-
class Supertype
|
3
|
-
include RestClient
|
4
|
-
|
5
|
-
# Get all supertypes
|
6
|
-
#
|
7
|
-
# @return [Array<String>] All supertypes
|
8
|
-
def self.all
|
9
|
-
RestClient.get('supertypes').body['supertypes']
|
10
|
-
end
|
11
|
-
end
|
1
|
+
module MTG
|
2
|
+
class Supertype
|
3
|
+
include RestClient
|
4
|
+
|
5
|
+
# Get all supertypes
|
6
|
+
#
|
7
|
+
# @return [Array<String>] All supertypes
|
8
|
+
def self.all
|
9
|
+
RestClient.get('supertypes').body['supertypes']
|
10
|
+
end
|
11
|
+
end
|
12
12
|
end
|
data/lib/mtg_sdk/type.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
module MTG
|
2
|
-
class Type
|
3
|
-
include RestClient
|
4
|
-
|
5
|
-
# Get all types
|
6
|
-
#
|
7
|
-
# @return [Array<String>] All types
|
8
|
-
def self.all
|
9
|
-
RestClient.get('types').body['types']
|
10
|
-
end
|
11
|
-
end
|
1
|
+
module MTG
|
2
|
+
class Type
|
3
|
+
include RestClient
|
4
|
+
|
5
|
+
# Get all types
|
6
|
+
#
|
7
|
+
# @return [Array<String>] All types
|
8
|
+
def self.all
|
9
|
+
RestClient.get('types').body['types']
|
10
|
+
end
|
11
|
+
end
|
12
12
|
end
|
data/lib/mtg_sdk/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module MTG
|
2
|
-
VERSION = "3.
|
3
|
-
end
|
1
|
+
module MTG
|
2
|
+
VERSION = "3.1.0"
|
3
|
+
end
|
data/mtg_sdk.gemspec
CHANGED
@@ -1,36 +1,36 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'mtg_sdk/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "mtg_sdk"
|
8
|
-
spec.version = MTG::VERSION
|
9
|
-
spec.authors = ["Andrew Backes"]
|
10
|
-
spec.email = ["backes.andrew@gmail.com"]
|
11
|
-
spec.summary = "Magic: The Gathering SDK for magicthegathering.io"
|
12
|
-
spec.description = "Magic: The Gathering SDK is a wrapper around the MTG API located at magicthegathering.io"
|
13
|
-
spec.homepage = "https://magicthegathering.io"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
|
-
|
21
|
-
spec.add_development_dependency "bundler", "~> 1.12"
|
22
|
-
spec.add_development_dependency "rake", "~> 11.2"
|
23
|
-
spec.add_development_dependency "minitest", "~> 5.9"
|
24
|
-
spec.add_development_dependency "vcr", "~> 3.0"
|
25
|
-
spec.add_development_dependency "webmock", "~> 2.1"
|
26
|
-
spec.add_development_dependency "simplecov", "~> 0.12"
|
27
|
-
spec.add_development_dependency "coveralls", "~> 0.8"
|
28
|
-
spec.add_development_dependency "codeclimate-test-reporter", "~> 0.6"
|
29
|
-
|
30
|
-
spec.add_dependency "roar", "~> 1.0"
|
31
|
-
spec.add_dependency "json", "~> 2.0"
|
32
|
-
spec.add_dependency "multi_json", "~> 1.12"
|
33
|
-
spec.add_dependency "multi_xml", "~> 0.5"
|
34
|
-
spec.add_dependency "faraday_middleware", "~> 0.10"
|
35
|
-
spec.add_dependency "virtus", "~> 1.0"
|
36
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mtg_sdk/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mtg_sdk"
|
8
|
+
spec.version = MTG::VERSION
|
9
|
+
spec.authors = ["Andrew Backes"]
|
10
|
+
spec.email = ["backes.andrew@gmail.com"]
|
11
|
+
spec.summary = "Magic: The Gathering SDK for magicthegathering.io"
|
12
|
+
spec.description = "Magic: The Gathering SDK is a wrapper around the MTG API located at magicthegathering.io"
|
13
|
+
spec.homepage = "https://magicthegathering.io"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
22
|
+
spec.add_development_dependency "rake", "~> 11.2"
|
23
|
+
spec.add_development_dependency "minitest", "~> 5.9"
|
24
|
+
spec.add_development_dependency "vcr", "~> 3.0"
|
25
|
+
spec.add_development_dependency "webmock", "~> 2.1"
|
26
|
+
spec.add_development_dependency "simplecov", "~> 0.12"
|
27
|
+
spec.add_development_dependency "coveralls", "~> 0.8"
|
28
|
+
spec.add_development_dependency "codeclimate-test-reporter", "~> 0.6"
|
29
|
+
|
30
|
+
spec.add_dependency "roar", "~> 1.0"
|
31
|
+
spec.add_dependency "json", "~> 2.0"
|
32
|
+
spec.add_dependency "multi_json", "~> 1.12"
|
33
|
+
spec.add_dependency "multi_xml", "~> 0.5"
|
34
|
+
spec.add_dependency "faraday_middleware", "~> 0.10"
|
35
|
+
spec.add_dependency "virtus", "~> 1.0"
|
36
|
+
end
|