Sha256: 9d09409dc7e41040b5574aaa3991994277eea7e302806f282fbf5fbd338e71a8
Contents?: true
Size: 1.91 KB
Versions: 2
Compression:
Stored size: 1.91 KB
Contents
require_relative 'representers/card_representer' require_relative 'resource' module MTG class Card < Resource include Roar::JSON include CardRepresenter include RestClient attr_accessor :name, :layout, :names, :mana_cost, :cmc, :colors, :type, :supertypes, :subtypes, :types, :rarity, :text, :flavor, :artist, :number, :power, :toughness, :loyalty, :multiverse_id, :variations, :watermark, :border, :timeshifted, :hand, :life, :reserved, :release_date, :starter, :rulings, :foreign_names, :printings, :original_text, :original_type, :legalities, :source, :image_url, :set, :id # Find a single card by the card multiverse id # # @param id [Integer] the multiverse id # @return [Card] the Card object response def self.find(id) response = RestClient.get("cards/#{id}") if response.body['card'].nil? raise ArgumentError, 'Card not found' end new.from_json(response.body['card'].to_json) end # Get all cards from a query by paging through data # # @return [Array<Card>] Array of Card objects def self.all cards = [] page = 0 while true where(page: page += 1) response = RestClient.get('cards', query[:parameters]) data = response.body['cards'] data.empty? ? break : data.each {|card| cards << new.from_json(card.to_json)} end @query = nil cards end # Execute a query and convert the response # into a list of Card objects # # @return [Array<Card>] Array of Card objects def self.get cards = [] response = RestClient.get('cards', query[:parameters]) data = response.body['cards'] data.each do |card| cards << new.from_json(card.to_json) end @query = nil cards end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mtg_sdk-1.1.1 | lib/mtg_sdk/card.rb |
mtg_sdk-1.1.0 | lib/mtg_sdk/card.rb |