mtg_sdk 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +155 -0
  6. data/Rakefile +16 -0
  7. data/lib/mtg_sdk.rb +32 -0
  8. data/lib/mtg_sdk/card.rb +48 -0
  9. data/lib/mtg_sdk/changelog.rb +29 -0
  10. data/lib/mtg_sdk/configuration.rb +9 -0
  11. data/lib/mtg_sdk/foreign_name.rb +10 -0
  12. data/lib/mtg_sdk/legality.rb +10 -0
  13. data/lib/mtg_sdk/representers/card_representer.rb +54 -0
  14. data/lib/mtg_sdk/representers/changelog_representer.rb +13 -0
  15. data/lib/mtg_sdk/representers/foreign_name_representer.rb +11 -0
  16. data/lib/mtg_sdk/representers/legality_representer.rb +10 -0
  17. data/lib/mtg_sdk/representers/ruling_representer.rb +12 -0
  18. data/lib/mtg_sdk/representers/set_representer.rb +21 -0
  19. data/lib/mtg_sdk/resource.rb +21 -0
  20. data/lib/mtg_sdk/rest_client.rb +31 -0
  21. data/lib/mtg_sdk/ruling.rb +10 -0
  22. data/lib/mtg_sdk/set.rb +64 -0
  23. data/lib/mtg_sdk/subtype.rb +15 -0
  24. data/lib/mtg_sdk/supertype.rb +15 -0
  25. data/lib/mtg_sdk/type.rb +15 -0
  26. data/lib/mtg_sdk/version.rb +3 -0
  27. data/mtg_sdk.gemspec +33 -0
  28. data/test/card_test.rb +62 -0
  29. data/test/changelog_test.rb +12 -0
  30. data/test/configuration_test.rb +10 -0
  31. data/test/fixtures/all_changelogs.yml +129 -0
  32. data/test/fixtures/all_subtypes.yml +129 -0
  33. data/test/fixtures/all_supertypes.yml +59 -0
  34. data/test/fixtures/all_types.yml +59 -0
  35. data/test/fixtures/booster.yml +974 -0
  36. data/test/fixtures/invalid_code.yml +49 -0
  37. data/test/fixtures/invalid_id.yml +49 -0
  38. data/test/fixtures/one_card.yml +111 -0
  39. data/test/fixtures/one_set.yml +60 -0
  40. data/test/fixtures/query_cards_pageSize.yml +356 -0
  41. data/test/fixtures/query_zurgo.yml +336 -0
  42. data/test/set_test.rb +34 -0
  43. data/test/subtype_test.rb +12 -0
  44. data/test/supertype_test.rb +12 -0
  45. data/test/test_helper.rb +10 -0
  46. data/test/type_test.rb +12 -0
  47. metadata +263 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ecbca7d3400b152d12b478b78169107fbd7a0db2
4
+ data.tar.gz: 6e6f2b0b4f5ce0b21914e38763471a9838d159e6
5
+ SHA512:
6
+ metadata.gz: 7f9d8fd01135a18cb01dfd5b2b2e4b276dd0a008d557832a1a3ba0af151cf90d827d21f3d1bd75d3247ec0de1549be9f25ddbe329d7abbda7e09257e0b0cb241
7
+ data.tar.gz: 62eafd2a5699518aba55cd18b35487a65c536c6b61d9b326f5acd46ec52eaf4b40699b7899c743eb17e4d0722a9efd97da4b78c37fb6849fedd5489a4372b758
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .vscode
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mtg_sdk.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Andrew Backes
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,155 @@
1
+ # Magic: The Gathering SDK
2
+
3
+ This is the Magic: The Gathering SDK Ruby implementation. It is a wrapper around the MTG API of magicthegathering.io.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mtg_sdk'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mtg_sdk
18
+
19
+ ## Usage
20
+
21
+ To change the API version (currently defaults to version 1)
22
+
23
+ MTG.configure do |config|
24
+ config.api_version = 2
25
+ end
26
+
27
+ ### Classes
28
+
29
+ Card
30
+ Set
31
+ ForeignName
32
+ Ruling
33
+ Legality
34
+ Subtype
35
+ Supertype
36
+ Type
37
+ Changelog
38
+
39
+ ### Properties Per Class
40
+
41
+ #### Card
42
+
43
+ name
44
+ multiverse_id
45
+ layout
46
+ names
47
+ mana_cost
48
+ cmc
49
+ colors
50
+ type
51
+ supertypes
52
+ subtypes
53
+ rarity
54
+ text
55
+ flavor
56
+ artist
57
+ number
58
+ power
59
+ toughness
60
+ loyalty
61
+ variations
62
+ watermark
63
+ border
64
+ timeshifted
65
+ hand
66
+ life
67
+ reserved
68
+ release_date
69
+ starter
70
+ rulings
71
+ foreign_names
72
+ printings
73
+ original_text
74
+ original_type
75
+ legalities
76
+ source
77
+ image_url
78
+ set
79
+ id
80
+
81
+ #### Set
82
+
83
+ code
84
+ name
85
+ gatherer_code
86
+ old_code
87
+ magic_cards_info_code
88
+ release_date
89
+ border
90
+ type
91
+ block
92
+ online_only
93
+ booster
94
+ mkm_id
95
+ mkm_name
96
+
97
+ #### ForeignName
98
+
99
+ language
100
+ name
101
+ multiverse_id
102
+
103
+ #### Ruling
104
+
105
+ date
106
+ text
107
+
108
+ #### Legality
109
+
110
+ format
111
+ legality
112
+
113
+ #### Changelog
114
+
115
+ version
116
+ release_date
117
+ details
118
+
119
+ ### Functions Available
120
+
121
+ #### Find a card by multiverse id
122
+
123
+ card = MTG::Card.find(386616)
124
+
125
+ #### Filter Cards via query parameters
126
+
127
+ cards = MTG::Card.where(set: ktk).where(subtypes: 'warrior,human').get
128
+
129
+ #### Find a set by code
130
+
131
+ set = MTG::Set.find('ktk')
132
+
133
+ #### Filter sets via query parameters
134
+
135
+ sets = MTG::Set.where(name: khans).get
136
+
137
+ #### Get all Types
138
+
139
+ types = MTG::Type.all
140
+
141
+ #### Get all Subtypes
142
+
143
+ subtypes = MTG::Subtype.all
144
+
145
+ #### Get all Supertypes
146
+
147
+ supertypes = MTG::Supertype.all
148
+
149
+ ## Contributing
150
+
151
+ 1. Fork it ( https://github.com/[my-github-username]/mtg_sdk/fork )
152
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
153
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
154
+ 4. Push to the branch (`git push origin my-new-feature`)
155
+ 5. Create a new Pull Request
@@ -0,0 +1,16 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+ require_relative 'lib/mtg_sdk'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList['test/*_test.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ desc "TODO"
12
+ task :cards do
13
+ card = MTG::Card.find(88803)
14
+ puts card.rulings.first.date
15
+
16
+ end
@@ -0,0 +1,32 @@
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
+
14
+ module MTG
15
+ API_URL = 'https://api.magicthegathering.io'
16
+
17
+ class << self
18
+ attr_writer :configuration
19
+ end
20
+
21
+ def self.configuration
22
+ @configuration ||= Configuration.new
23
+ end
24
+
25
+ def self.configure
26
+ yield(configuration)
27
+ end
28
+
29
+ def self.reset
30
+ @configuration = Configuration.new
31
+ end
32
+ end
@@ -0,0 +1,48 @@
1
+ require_relative 'representers/card_representer'
2
+ require_relative 'rest_client'
3
+ require_relative 'resource'
4
+
5
+ module MTG
6
+ class Card < Resource
7
+ include Roar::JSON
8
+ include CardRepresenter
9
+ include RestClient
10
+
11
+ attr_accessor :name, :layout, :names, :mana_cost, :cmc, :colors, :type, :supertypes, :subtypes, :types,
12
+ :rarity, :text, :flavor, :artist, :number, :power, :toughness, :loyalty, :multiverse_id, :variations,
13
+ :watermark, :border, :timeshifted, :hand, :life, :reserved, :release_date, :starter,
14
+ :rulings, :foreign_names, :printings, :original_text, :original_type, :legalities,
15
+ :source, :image_url, :set, :id
16
+
17
+ # Find a single card by the card multiverse id
18
+ #
19
+ # @param id [Integer] the multiverse id
20
+ # @return [Card] the Card object response
21
+ def self.find(id)
22
+ response = RestClient.get("cards/#{id}")
23
+
24
+ if response.body['card'].nil?
25
+ raise ArgumentError, 'Card not found'
26
+ end
27
+
28
+ new.from_json(response.body['card'].to_json)
29
+ end
30
+
31
+ # Execute a query and convert the response
32
+ # into a list of Card objects
33
+ #
34
+ # @return [Array<Card>] Array of Card objects
35
+ def self.get
36
+ cards = []
37
+ response = RestClient.get('cards', query[:parameters])
38
+ data = response.body['cards']
39
+
40
+ data.each do |card|
41
+ cards << new.from_json(card.to_json)
42
+ end
43
+
44
+ @query = nil
45
+ cards
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,29 @@
1
+ require_relative 'representers/changelog_representer'
2
+ require_relative 'rest_client'
3
+ require_relative 'resource'
4
+
5
+ module MTG
6
+ class Changelog < Resource
7
+ include Roar::JSON
8
+ include RestClient
9
+ include ChangelogRepresenter
10
+
11
+ attr_accessor :version, :details, :release_date
12
+
13
+ # Get all changelogs
14
+ #
15
+ # @return [Array<Changelog>] Array of Changelog objects
16
+ def self.all
17
+ changelogs = []
18
+ response = RestClient.get('changelogs')
19
+ data = response.body['changelogs']
20
+
21
+ data.each do |changelog|
22
+ changelogs << new.extend(ChangelogRepresenter).from_json(changelog.to_json)
23
+ end
24
+
25
+ @query = nil
26
+ changelogs
27
+ end
28
+ end
29
+ end
@@ -0,0 +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
9
+ end
@@ -0,0 +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
9
+ end
10
+ end
@@ -0,0 +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
@@ -0,0 +1,54 @@
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: :release_date, 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 :id
42
+ property :image_url, as: :imageUrl
43
+
44
+ collection :supertypes
45
+ collection :subtypes
46
+ collection :types
47
+ collection :colors
48
+ collection :variations
49
+ collection :printings
50
+ collection :legalities, extend: LegalityRepresenter, class: Legality
51
+ collection :rulings, extend: RulingRepresenter, class: Ruling
52
+ collection :foreign_names, as: :foreignNames, extend: ForeignNameRepresenter, class: ForeignName
53
+ end
54
+ end
@@ -0,0 +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
13
+ end