MtgDbClient 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8b8d521c692827950e1ed1171bfe49e1435bb845
4
+ data.tar.gz: 11f557bef676a4264b0c8d5b42ef71db9a2957dc
5
+ SHA512:
6
+ metadata.gz: c61b9c89b367010a79d8cf0aa8458453bc406d04733c0146adccab0c19be68b91390325e5a7bc15757e13d7483e06d250914400d8c5207e52c81ec824997daca
7
+ data.tar.gz: 4758b50b36da62231a4b63e3263900243eace1d0c2c216b4ec327c644f9b56c55fd0fd670c4678fd3de641e2cc44a00b8cbb2b2ef95ff326526890f40f7ae605
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in MtgDbClient.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Chase Park
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,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'MtgDbClient/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "MtgDbClient"
8
+ spec.version = MtgDbClient::VERSION
9
+ spec.authors = ["Chase Park"]
10
+ spec.email = ["chasepark@comcast.net"]
11
+ spec.description = %q{Client gem that wraps the MtgDb Api}
12
+ spec.summary = %q{Client gem that wraps the MtgDb Api}
13
+ spec.homepage = "http://www.github.com/chasepark/MtgDbClient"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "httparty", "~> 0.13.1"
25
+ end
data/README.md ADDED
@@ -0,0 +1,126 @@
1
+ # MtgDbClient
2
+
3
+ This is a simple api wrapper gem for the MtgDb Api found at 'http://api.mtgdb.info'. This is a 1:1 representation of the C# wrapper.
4
+
5
+ ####Dependencies
6
+ HttParty
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'MtgDbClient'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install MtgDbClient
21
+
22
+ ## Usage
23
+ To get started using MtgDbClient first setup the client
24
+
25
+ require "mtgdbclient"
26
+
27
+ client = MtgDbClient.new
28
+
29
+ ###Configuration
30
+
31
+ MtgDbClient.configure do|config|
32
+ config.endpoint = 'api.mtgdb.info'
33
+ #default is api.mtgdb.info
34
+ end
35
+
36
+
37
+ ###The following functions are currently supported:
38
+
39
+ ####Get Rarity Types
40
+ returns all available rarity types.
41
+
42
+ client.get_rarity_types
43
+
44
+ ####Get Card Types
45
+ returns all available card types
46
+
47
+ client.get_card_types
48
+
49
+ ####Get Card Subtypes
50
+ returns all unique subtypes available on all cards
51
+
52
+ client.get_card_subtypes
53
+
54
+ ####Get Sets
55
+ returns a list of sets
56
+
57
+ client.get_sets
58
+
59
+ ####Get Set
60
+ returns a set, specified by the three character set identifier
61
+
62
+ client.get_set(set_id)
63
+
64
+ ####Get Random Card In Set
65
+ returns a random card from a specified set
66
+
67
+ client.get_random_card_from_set(set_id)
68
+
69
+ ####Get Sets By Id
70
+ returns a details of the specified sets
71
+
72
+ client.get_sets_by_id([set_ids])
73
+
74
+ ####Get Card
75
+ returns a card specified by the multiverse(oracle) id
76
+
77
+ client.get_card(card_id)
78
+
79
+ ####Get Cards By Id
80
+ returns detaisl of specified cards
81
+
82
+ client.get_cards_by_id([multiverse_ids])
83
+
84
+ ####Get Cards
85
+ returns a list of all cards (WARNING: This takes some time to run.)
86
+
87
+ client.get_cards
88
+
89
+ ####Get Random Card
90
+ returns a completely random card
91
+
92
+ client.get_random_card
93
+
94
+ ####Get Card By Name
95
+ returns all instances of a card by name
96
+
97
+ client.get_card_by_name(card_name)
98
+
99
+ ####Filter Cards
100
+ returns a list of all cards with the specified filter
101
+
102
+ client.filter_cards(property, value)
103
+
104
+ ####Get Card In Set
105
+ returns a card in a specified set with the collector number
106
+
107
+ client.get_card_in_set(set_id, collector_id)
108
+ ####Search
109
+ gets a list of cards that meet the specified criteria
110
+
111
+ client.search(text, start=0, limit=0, isComplex=false)
112
+
113
+
114
+ ## Contributing
115
+
116
+ 1. Fork it
117
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
118
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
119
+ 4. Push to the branch (`git push origin my-new-feature`)
120
+ 5. Create new Pull Request
121
+
122
+
123
+ ##Legal
124
+ MtgApi Notice:
125
+
126
+ All information provided is copyrighted by Wizards of the Coast. This api and/or web applications on this domain are not in anyway affiliated with Wizards of the Coast.
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ Rake::TestTask.new do |test|
4
+ test.libs << 'lib' << 'test'
5
+ test.ruby_opts << "-rubygems"
6
+ test.pattern = 'test/**/*_test.rb'
7
+ test.verbose = true
8
+ end
@@ -0,0 +1,86 @@
1
+ require "httparty"
2
+
3
+
4
+ module MtgDbClient
5
+ class Client
6
+ include HTTParty
7
+ attr_accessor *Configuration::VALID_CONFIG_KEYS
8
+
9
+ def initialize(options={})
10
+ merged_options = MtgDbClient.options.merge(options)
11
+
12
+ Configuration::VALID_CONFIG_KEYS.each do |key|
13
+ send("#{key}=", merged_options[key])
14
+ end
15
+
16
+ self.class.base_uri 'api.mtgdb.info'
17
+ end
18
+
19
+ #Common Functions
20
+ def get_rarity_types
21
+ self.class.get("/cards/rarity")
22
+ end
23
+
24
+ def get_card_types
25
+ self.class.get("/cards/types")
26
+ end
27
+
28
+ def get_card_subtypes
29
+ self.class.get("/cards/subtypes")
30
+ end
31
+
32
+ #Set Functions
33
+ def get_sets
34
+ self.class.get("/sets/")
35
+ end
36
+
37
+ def get_set(set_id)
38
+ self.class.get("/sets/#{set_id}")
39
+ end
40
+
41
+ def get_random_card_in_set(set_id)
42
+ self.class.get("/sets/#{set_id}/cards/random")
43
+ end
44
+
45
+ def get_sets_by_id(set_ids=[])
46
+ self.class.get("/sets/#{set_ids.join(',').upcase}")
47
+ end
48
+
49
+ #Card Functions
50
+ def get_card(multiverse_id)
51
+ self.class.get("/cards/#{multiverse_id}")
52
+ end
53
+
54
+ def get_cards_by_id(multiverse_ids=[])
55
+ self.class.get("/cards/#{multiverse_ids.join(',')}")
56
+ end
57
+
58
+ def get_cards
59
+ self.class.get("/cards/")
60
+ end
61
+
62
+ def get_random_card
63
+ self.class.get("/cards/random")
64
+ end
65
+
66
+ def get_card_by_name(card_name)
67
+ self.class.get(URI.escape("/cards/#{card_name}"))
68
+ end
69
+
70
+ def filter_cards(property, value)
71
+ self.class.get(URI.escape("/cards/#{property}=#{value}"))
72
+ end
73
+
74
+ def get_card_in_set(set_id, collector_number)
75
+ self.class.get(URI.escape("/sets/#{set_id}/cards/#{collector_number}"))
76
+ end
77
+
78
+ def search(text, start=0, limit=0, isComplex=false)
79
+ if isComplex
80
+ self.class.get(URI.escape("/search/?q=#{text}&start=#{start}&limit=#{limit}"))
81
+ else
82
+ self.class.get(URI.escape("/search/#{text}?start=#{start}&limit=#{limit}"))
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,32 @@
1
+ module MtgDbClient
2
+ module Configuration
3
+ VALID_CONNECTION_KEYS = [:endpoint].freeze
4
+ VALID_OPTION_KEYS = [:format].freeze
5
+ VALID_CONFIG_KEYS = VALID_CONNECTION_KEYS + VALID_OPTION_KEYS
6
+
7
+ DEFAULT_ENDPOINT = "api.mtgdb.info"
8
+ DEFAULT_FORMAT = :json
9
+
10
+ attr_accessor *VALID_CONFIG_KEYS
11
+
12
+ def self.extended(base)
13
+ base.reset
14
+ end
15
+
16
+ def reset
17
+ self.endpoint = DEFAULT_ENDPOINT
18
+ self.format = DEFAULT_FORMAT
19
+ end
20
+
21
+ def configure
22
+ yield self
23
+ end
24
+
25
+ def options
26
+ Hash[ * VALID_CONFIG_KEYS.map { |key| [key, send(key)] }.flatten ]
27
+ end
28
+ end
29
+ end
30
+
31
+
32
+
@@ -0,0 +1,3 @@
1
+ module MtgDbClient
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,20 @@
1
+ require "MtgDbClient/version"
2
+ require "MtgDbClient/configuration"
3
+ require "MtgDbClient/client"
4
+
5
+ module MtgDbClient
6
+ extend Configuration
7
+
8
+ def new(options={})
9
+ Client.new(options)
10
+ end
11
+
12
+ def method_missing(method, *args, &block)
13
+ return super unless new.respond_to?(method)
14
+ new.send(method, *args, &block)
15
+ end
16
+
17
+ def respond_to?(method, include_private = false)
18
+ new.respond_to?(method, include_private) || super(method, include_private)
19
+ end
20
+ end
@@ -0,0 +1,161 @@
1
+ require 'helper'
2
+
3
+ describe 'client' do
4
+ before do
5
+ @keys = MtgDbClient::Configuration::VALID_CONFIG_KEYS
6
+ end
7
+
8
+ describe 'with module configuration' do
9
+ before do
10
+ MtgDbClient.configure do |config|
11
+ @keys.each do |key|
12
+ config.send("#{key}=", key)
13
+ end
14
+ end
15
+ end
16
+ after do
17
+ MtgDbClient.reset
18
+ end
19
+ it 'should inherit module configuration' do
20
+ mtgdb_client = MtgDbClient::Client.new
21
+ @keys.each do |key|
22
+ mtgdb_client.send(key).must_equal key
23
+ end
24
+ end
25
+ end
26
+
27
+ it 'should be initializable' do
28
+ mtgdb_client = MtgDbClient::Client.new
29
+ mtgdb_client.wont_be_nil
30
+ end
31
+
32
+ it 'should have a set of configured default options' do
33
+ mtgdb_client = MtgDbClient::Client.new
34
+ end
35
+
36
+ describe '.sets' do
37
+ it 'should return a list of sets' do
38
+ mtgdb_client = MtgDbClient::Client.new
39
+ mtgdb_client.get_sets.wont_be_nil
40
+ end
41
+ end
42
+
43
+ describe '.rarity_types' do
44
+ it 'should return a list of rarities' do
45
+ mtgdb_client = MtgDbClient::Client.new
46
+ mtgdb_client.get_rarity_types.wont_be_nil
47
+ end
48
+ end
49
+
50
+ describe '.card_types' do
51
+ it 'should return a list of card master types' do
52
+ mtgdb_client = MtgDbClient::Client.new
53
+ mtgdb_client.get_card_types.wont_be_nil
54
+ end
55
+ end
56
+
57
+ describe '.card_subtypes' do
58
+ it 'should return a list of card subtypes' do
59
+ mtgdb_client = MtgDbClient::Client.new
60
+ mtgdb_client.get_card_subtypes.wont_be_nil
61
+ end
62
+ end
63
+
64
+
65
+ describe '.get_card(id)' do
66
+ it 'should return a specific card for a valid id' do
67
+ mtgdb_client = MtgDbClient::Client.new
68
+ card = mtgdb_client.get_card(386676)
69
+ card.wont_be_nil
70
+ end
71
+ end
72
+
73
+ describe '.random_card_in_set(set_id)' do
74
+ it 'should retun a random card from a specified set' do
75
+ mtgdb_client = MtgDbClient::Client.new
76
+ card = mtgdb_client.get_random_card_in_set("TMP")
77
+ card.wont_be_nil
78
+ end
79
+ end
80
+
81
+ describe '.sets_by_id(set_ids)' do
82
+ it 'should return the details of the specified sets' do
83
+ mtgdb_client = MtgDbClient::Client.new
84
+ sets = mtgdb_client.get_sets_by_id(["tmp", "sth", "exo" ])
85
+ sets.wont_be_nil
86
+ end
87
+ end
88
+
89
+ describe '.get_cards_by_id(multiverse_ids)' do
90
+ it 'should get a list of the cards with specified ids' do
91
+ mtgdb_client = MtgDbClient::Client.new
92
+ cards = mtgdb_client.get_cards_by_id([4818,4822,4823,4825,4826,4829])
93
+ cards.wont_be_nil
94
+ end
95
+ end
96
+
97
+ describe '.random_card' do
98
+ it 'should return a random card from a random set' do
99
+ mtgdb_client = MtgDbClient::Client.new
100
+ mtgdb_client.get_random_card.wont_be_nil
101
+ end
102
+ end
103
+
104
+ describe '.get_card_by_name' do
105
+ it 'should return all copies of a card with the same name' do
106
+ mtgdb_client = MtgDbClient::Client.new
107
+ card = mtgdb_client.get_card_by_name("Echo Chamber")
108
+ card.wont_be_nil
109
+ end
110
+ end
111
+
112
+ #commented due to the time it takes to run the test.
113
+ #describe '.get_cards' do
114
+ # it 'returns all cards' do
115
+ # mtgdb_client = MtgDbClient::Client.new
116
+ # cards = mtgdb_client.get_cards
117
+ # cards.wont_be_nil
118
+ # end
119
+ #end
120
+
121
+ describe '.filter_cards(property, value)' do
122
+ it 'should return a list of cards with the specified property' do
123
+ mtgdb_client = MtgDbClient::Client.new
124
+ mtgdb_client.filter_cards("subtype", "Rat").wont_be_nil
125
+ end
126
+ end
127
+
128
+ describe '.get_card_in_set(set_id, collector_number)' do
129
+ it 'should return the specified card in the specified set' do
130
+ mtgdb_client = MtgDbClient::Client.new
131
+ card = mtgdb_client.get_card_in_set("tmp", 1)
132
+ card["name"].must_equal 'Abandon Hope'
133
+ end
134
+ end
135
+
136
+ describe '.get_set(set_id)' do
137
+ it 'should return the specified set' do
138
+ mtgdb_client = MtgDbClient::Client.new
139
+ set = mtgdb_client.get_set("tmp")
140
+ set["name"].must_equal "Tempest"
141
+ end
142
+ end
143
+
144
+ describe '.search' do
145
+ describe 'complex search' do
146
+ it 'should return all blue cloud creatures with a converted mana cost less than three' do
147
+ mtgdb_client = MtgDbClient::Client.new
148
+ results = mtgdb_client.search("color eq blue and type m 'Creature' and description m 'flying' " +
149
+ "and convertedmanacost lt 3 and name m 'Cloud'", 0, 0, true)
150
+ results.wont_be_nil
151
+ end
152
+ end
153
+
154
+ describe 'basic search' do
155
+ it 'should return all cards that contain the word giant' do
156
+ mtgdb_client = MtgDbClient::Client.new
157
+ mtgdb_client.search("giant").wont_be_nil
158
+ end
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,11 @@
1
+ require 'helper'
2
+ describe '.configure' do
3
+ MtgDbClient::Configuration::VALID_CONFIG_KEYS.each do |key|
4
+ it "should set the #{key}" do
5
+ MtgDbClient.configure do |config|
6
+ config.send("#{key}=", key)
7
+ MtgDbClient.send(key).must_equal key
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ describe MtgDbClient do
4
+ it 'should have a version' do
5
+ MtgDbClient::VERSION.wont_be_nil
6
+ end
7
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'MtgDbClient'
2
+ require 'minitest/spec'
3
+ require 'minitest/autorun'
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: MtgDbClient
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Chase Park
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.13.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.13.1
55
+ description: Client gem that wraps the MtgDb Api
56
+ email:
57
+ - chasepark@comcast.net
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - MtgDbClient.gemspec
66
+ - README.md
67
+ - Rakefile
68
+ - lib/MtgDbClient.rb
69
+ - lib/MtgDbClient/client.rb
70
+ - lib/MtgDbClient/configuration.rb
71
+ - lib/MtgDbClient/version.rb
72
+ - test/MtgDbClient/client_test.rb
73
+ - test/MtgDbClient/configuration_test.rb
74
+ - test/MtgDbClient/mtgdbclient_test.rb
75
+ - test/helper.rb
76
+ homepage: http://www.github.com/chasepark/MtgDbClient
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.2.2
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Client gem that wraps the MtgDb Api
100
+ test_files:
101
+ - test/MtgDbClient/client_test.rb
102
+ - test/MtgDbClient/configuration_test.rb
103
+ - test/MtgDbClient/mtgdbclient_test.rb
104
+ - test/helper.rb