MtgDbClient 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aed2b67453334ccc26e01ab6bb8aa9190a5aeacc
4
- data.tar.gz: 3b67e2a42ae7bb6cb2751631e5df39921d5527a9
3
+ metadata.gz: 4ec664ae5d0916c4db0aec9c425ef0f7646a8838
4
+ data.tar.gz: de176ae28597cff5b4c5ab8d58c7e06c48935290
5
5
  SHA512:
6
- metadata.gz: bf46f433ea45aa2bd2eba843438d7af5f8a0373dde4b0c7598fb4b2949fd989520fd9dd0f501344775ee50fc800345dca4a5054bf7c275e77f804534058d37a1
7
- data.tar.gz: 97103f98a8b29d454d55ca4bbb923310cf55809164f5368f01bceb4c68df86829623a991d64de8e93eab03ab5861cf9837cc59925983b401d2d9e42d75256ff0
6
+ metadata.gz: c363142c310bc7e037be06b908490e0e22bdea656df5e135c52fc5365f38a900e5cfb34aa0d8f0046edf8e203c2943796faf1447fa91100b084819024edf85e5
7
+ data.tar.gz: edf8b87250c4e0062317502f11b761fb11a42e7e23a15ca9298287ca1fd7b4eb477d7d89922471153b3bcf69c36143050310799e3f276dce4329520a9e612b73
@@ -0,0 +1,51 @@
1
+ module MtgDbClient
2
+ class Card
3
+ attr_accessor :id, :related_card_id, :set_number, :name, :search_name, :description,
4
+ :flavor, :colors, :mana_cost, :converted_mana_cost, :card_set_name, :type,
5
+ :sub_type, :power, :toughness, :loyalty, :rarity, :artist, :card_set_id,
6
+ :token, :promo, :rulings, :formats, :released_at
7
+
8
+ def initialize(response)
9
+ self.id = response["id"]
10
+ self.related_card_id = response["relatedCardId"]
11
+ self.set_number = response["setNumber"]
12
+ self.name = response["name"]
13
+ self.search_name=response["searchName"]
14
+ self.description=response["description"]
15
+ self.flavor = response["flavor"]
16
+ self.colors = response["colors"]
17
+ self.mana_cost = response["manacost"]
18
+ self.converted_mana_cost = response["convertedManaCost"]
19
+ self.card_set_name = response["cardSetName"]
20
+ self.type = response["type"]
21
+ self.sub_type = response["subType"]
22
+ self.power = response["power"]
23
+ self.toughness = response["toughness"]
24
+ self.loyalty = response["loyalty"]
25
+ self.rarity = response["rarity"]
26
+ self.artist = response["artist"]
27
+ self.card_set_id = response["cardSetId"]
28
+ self.token = response["token"]
29
+ self.promo = response["promo"]
30
+ self.rulings = response["rulings"].map{|r| Ruling.new(r)}
31
+ self.formats = response["formats"].map{|f| Format.new(f)}
32
+ self.released_at = Date.parse(response["releasedAt"])
33
+ end
34
+
35
+ def image_low
36
+ sub_path = ['api.mtgdb.info/content/card_images', self.id].join("/")
37
+ get_path + sub_path
38
+ end
39
+
40
+ def image_high
41
+ sub_path = ['api.mtgdb.info/content/high_res_card_images', self.id].join("/")
42
+ get_path + sub_path
43
+ end
44
+
45
+
46
+ private
47
+ def get_path
48
+ "http://"
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,25 @@
1
+ module MtgDbClient
2
+ class CardSet
3
+ attr_accessor :id, :name, :type, :block, :description,
4
+ :common_count, :uncommon_count, :rare_count, :mythic_rare_count, :basic_land_count,
5
+ :total_cards, :release_date, :card_ids
6
+
7
+ def initialize(response)
8
+ self.id = response["id"]
9
+ self.name = response["name"]
10
+ self.type = response["type"]
11
+ self.block = response["block"]
12
+ self.description = response["description"]
13
+ self.common_count = response["common"]
14
+ self.uncommon_count = response["uncommon"]
15
+ self.rare_count = response["rare"]
16
+ self.mythic_rare_count = response["mythicRare"]
17
+ self.basic_land_count = response["basicLand"]
18
+ self.total_cards = response["total"]
19
+ if(response["releaseDate"] != nil)
20
+ self.release_date = Date.parse(response["release_date"])
21
+ end
22
+ self.card_ids = response["cardIds"]
23
+ end
24
+ end
25
+ end
@@ -31,55 +31,64 @@ module MtgDbClient
31
31
 
32
32
  #Set Functions
33
33
  def get_sets
34
- self.class.get("/sets/")
34
+ self.class.get("/sets").map{|s| CardSet.new(s)}
35
35
  end
36
36
 
37
37
  def get_set(set_id)
38
- self.class.get("/sets/#{set_id}")
38
+ response = self.class.get(URI.escape("/sets/#{set_id}"))
39
+ CardSet.new(response)
39
40
  end
40
41
 
41
42
  def get_random_card_in_set(set_id)
42
- self.class.get("/sets/#{set_id}/cards/random")
43
+ response = self.class.get(URI.escape("/sets/#{set_id}/cards/random"))
44
+ Card.new(response)
43
45
  end
44
46
 
45
47
  def get_sets_by_id(set_ids=[])
46
- self.class.get("/sets/#{set_ids.join(',').upcase}")
48
+ self.class.get(URI.escape("/sets/#{set_ids.join(',').upcase}")).map{|s| CardSet.new(s)}
49
+ end
50
+
51
+ def get_cards_in_set(set_id)
52
+ self.class.get(URI.escape("/sets/#{set_id}/cards")).map{|c| Card.new(c)}
47
53
  end
48
54
 
49
55
  #Card Functions
50
56
  def get_card(multiverse_id)
51
- self.class.get("/cards/#{multiverse_id}")
57
+ response = self.class.get("/cards/#{multiverse_id}")
58
+ Card.new(response)
52
59
  end
53
60
 
54
61
  def get_cards_by_id(multiverse_ids=[])
55
- self.class.get("/cards/#{multiverse_ids.join(',')}")
62
+ self.class.get(URI.escape("/cards/#{multiverse_ids.join(',')}")).map{|c| Card.new(c)}
56
63
  end
57
64
 
58
65
  def get_cards
59
- self.class.get("/cards/")
66
+ self.class.get("/cards").map{|c| Card.new(c)}
60
67
  end
61
68
 
62
69
  def get_random_card
63
- self.class.get("/cards/random")
70
+ response = self.class.get("/cards/random")
71
+ Card.new(response)
64
72
  end
65
73
 
66
74
  def get_card_by_name(card_name)
67
- self.class.get(URI.escape("/cards/#{card_name}"))
75
+ response = self.class.get(URI.escape("/cards/#{card_name}")).map{|c| Card.new(c)}
68
76
  end
69
77
 
70
78
  def filter_cards(property, value)
71
- self.class.get(URI.escape("/cards/?#{property}=#{value}"))
79
+ self.class.get(URI.escape("/cards/?#{property}=#{value}")).map{|c| Card.new(c)}
72
80
  end
73
81
 
74
82
  def get_card_in_set(set_id, collector_number)
75
- self.class.get(URI.escape("/sets/#{set_id}/cards/#{collector_number}"))
83
+ response = self.class.get(URI.escape("/sets/#{set_id.upcase}/cards/#{collector_number.to_s}"))
84
+ Card.new(response)
76
85
  end
77
86
 
78
87
  def search(text, start=0, limit=0, isComplex=false)
79
88
  if isComplex
80
- self.class.get(URI.escape("/search/?q=#{text}&start=#{start}&limit=#{limit}"))
89
+ self.class.get(URI.escape("/search/?q=#{text}&start=#{start}&limit=#{limit}")).map{|c| Card.new(c)}
81
90
  else
82
- self.class.get(URI.escape("/search/#{text}?start=#{start}&limit=#{limit}"))
91
+ self.class.get(URI.escape("/search/#{text}?start=#{start}&limit=#{limit}")).map{|c| Card.new(c)}
83
92
  end
84
93
  end
85
94
  end
@@ -1,11 +1,14 @@
1
1
  module MtgDbClient
2
2
  module Configuration
3
3
  VALID_CONNECTION_KEYS = [:endpoint].freeze
4
- VALID_OPTION_KEYS = [:format].freeze
4
+ VALID_OPTION_KEYS = [:format, :low_res_image_path, :high_res_image_path, :use_https].freeze
5
5
  VALID_CONFIG_KEYS = VALID_CONNECTION_KEYS + VALID_OPTION_KEYS
6
6
 
7
7
  DEFAULT_ENDPOINT = "api.mtgdb.info"
8
8
  DEFAULT_FORMAT = :json
9
+ DEFAULT_LOW_RESOLUTION_IMAGE_PATH = "content/card_images"
10
+ DEFAULT_HIGH_RESOLUTION_IMAGE_PATH = "content/hi_res_card_images"
11
+ DEFAULT_USE_HTTPS = false
9
12
 
10
13
  attr_accessor *VALID_CONFIG_KEYS
11
14
 
@@ -16,6 +19,9 @@ module MtgDbClient
16
19
  def reset
17
20
  self.endpoint = DEFAULT_ENDPOINT
18
21
  self.format = DEFAULT_FORMAT
22
+ self.low_res_image_path = DEFAULT_LOW_RESOLUTION_IMAGE_PATH
23
+ self.high_res_image_path = DEFAULT_HIGH_RESOLUTION_IMAGE_PATH
24
+ self.use_https = DEFAULT_USE_HTTPS
19
25
  end
20
26
 
21
27
  def configure
@@ -0,0 +1,10 @@
1
+ module MtgDbClient
2
+ class Format
3
+ attr_accessor :name, :legality
4
+
5
+ def initialize(response)
6
+ self.name = response["name"]
7
+ self.legality = response["legality"]
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module MtgDbClient
2
+ class Ruling
3
+ attr_accessor :released_at, :rule
4
+
5
+ def initialize(response)
6
+ self.released_at = Date.parse(response["releasedAt"])
7
+ self.rule = response["rule"]
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module MtgDbClient
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/lib/MtgDbClient.rb CHANGED
@@ -1,6 +1,11 @@
1
1
  require "MtgDbClient/version"
2
2
  require "MtgDbClient/configuration"
3
3
  require "MtgDbClient/client"
4
+ require "MtgDbClient/card_set"
5
+ require "MtgDbClient/card"
6
+ require "MtgDbClient/ruling"
7
+ require "MtgDbClient/format"
8
+
4
9
 
5
10
  module MtgDbClient
6
11
  extend Configuration
@@ -36,28 +36,29 @@ end
36
36
  describe '.sets' do
37
37
  it 'should return a list of sets' do
38
38
  mtgdb_client = MtgDbClient::Client.new
39
- mtgdb_client.get_sets.wont_be_nil
39
+ sets = mtgdb_client.get_sets
40
+ sets.wont_be_empty
40
41
  end
41
42
  end
42
43
 
43
44
  describe '.rarity_types' do
44
45
  it 'should return a list of rarities' do
45
46
  mtgdb_client = MtgDbClient::Client.new
46
- mtgdb_client.get_rarity_types.wont_be_nil
47
+ mtgdb_client.get_rarity_types.wont_be_empty
47
48
  end
48
49
  end
49
50
 
50
51
  describe '.card_types' do
51
52
  it 'should return a list of card master types' do
52
53
  mtgdb_client = MtgDbClient::Client.new
53
- mtgdb_client.get_card_types.wont_be_nil
54
+ mtgdb_client.get_card_types.wont_be_empty
54
55
  end
55
56
  end
56
57
 
57
58
  describe '.card_subtypes' do
58
59
  it 'should return a list of card subtypes' do
59
60
  mtgdb_client = MtgDbClient::Client.new
60
- mtgdb_client.get_card_subtypes.wont_be_nil
61
+ mtgdb_client.get_card_subtypes.wont_be_empty
61
62
  end
62
63
  end
63
64
 
@@ -82,6 +83,7 @@ end
82
83
  it 'should return the details of the specified sets' do
83
84
  mtgdb_client = MtgDbClient::Client.new
84
85
  sets = mtgdb_client.get_sets_by_id(["tmp", "sth", "exo" ])
86
+ sets.inspect
85
87
  sets.wont_be_nil
86
88
  end
87
89
  end
@@ -129,7 +131,8 @@ end
129
131
  it 'should return the specified card in the specified set' do
130
132
  mtgdb_client = MtgDbClient::Client.new
131
133
  card = mtgdb_client.get_card_in_set("tmp", 1)
132
- card["name"].must_equal 'Abandon Hope'
134
+ puts card.image_low
135
+ card.name.must_equal 'Abandon Hope'
133
136
  end
134
137
  end
135
138
 
@@ -137,7 +140,7 @@ end
137
140
  it 'should return the specified set' do
138
141
  mtgdb_client = MtgDbClient::Client.new
139
142
  set = mtgdb_client.get_set("tmp")
140
- set["name"].must_equal "Tempest"
143
+ set.name.must_equal "Tempest"
141
144
  end
142
145
  end
143
146
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: MtgDbClient
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chase Park
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-21 00:00:00.000000000 Z
11
+ date: 2014-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,8 +66,12 @@ files:
66
66
  - README.md
67
67
  - Rakefile
68
68
  - lib/MtgDbClient.rb
69
+ - lib/MtgDbClient/card.rb
70
+ - lib/MtgDbClient/card_set.rb
69
71
  - lib/MtgDbClient/client.rb
70
72
  - lib/MtgDbClient/configuration.rb
73
+ - lib/MtgDbClient/format.rb
74
+ - lib/MtgDbClient/ruling.rb
71
75
  - lib/MtgDbClient/version.rb
72
76
  - test/MtgDbClient/client_test.rb
73
77
  - test/MtgDbClient/configuration_test.rb