the_games_db 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in the_games_db.gemspec
4
+ gemspec
@@ -0,0 +1,11 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+ watch(%r{^spec/.+_spec\.rb$})
9
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
10
+ watch('spec/spec_helper.rb') { "spec" }
11
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Jared Pace
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,77 @@
1
+ TheGamesDB: Ruby API Client
2
+ ===========================
3
+
4
+ Simple API wrapper for TheGamesDB.net.
5
+
6
+ Installation
7
+ ------------
8
+
9
+ ```bash
10
+ gem install the_games_db
11
+ ```
12
+
13
+
14
+ Usage
15
+ -----
16
+
17
+ ```ruby
18
+ require 'the_games_db'
19
+ mario_games = TheGamesDB::Game.search :name => 'Super Mario Bros'
20
+ mario_games.first.title
21
+ => "New Super Mario Bros."
22
+
23
+ smb3 = TheGamesDB::Game.find 112
24
+ smb3.title
25
+ => "Super Mario Bros. 3"
26
+ smb3.platform
27
+ => "Nintendo Entertainment System (NES)"
28
+ front_boxart = smb3.boxarts.detect {|boxart| boxart.side == "front"}
29
+ front_boxart.url
30
+ => "http://thegamesdb.net/banners/boxart/original/front/112-2.jpg"
31
+ ```
32
+
33
+
34
+ Available Properties
35
+ --------------------
36
+
37
+ game.id
38
+ game.title
39
+ game.overview
40
+ game.platform
41
+ game.esrb
42
+ game.players
43
+ game.cooperative
44
+ game.publisher
45
+ game.developer
46
+ game.release_date
47
+ game.rating
48
+ game.youtube_video
49
+ game.genres
50
+ game.banners
51
+ banner.width
52
+ banner.height
53
+ banner.path
54
+ game.boxarts
55
+ boxart.width
56
+ boxart.height
57
+ boxart.side
58
+ boxart.path
59
+ game.fanarts
60
+ fanart.original.width
61
+ fanart.original.height
62
+ fanart.original.path
63
+ fanart.vignette.width
64
+ fanart.vignette.height
65
+ fanart.vignette.path
66
+ fanart.thumb.path
67
+ game.screenshots
68
+ screenshot.original.width
69
+ screenshot.original.height
70
+ screenshot.original.path
71
+ screenshot.thumb.path
72
+
73
+
74
+ Copyright
75
+ ---------
76
+
77
+ Copyright (c) 2010 Jared Pace. See LICENSE for details.
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -0,0 +1,11 @@
1
+ require 'typhoeus'
2
+ require 'sax-machine'
3
+
4
+ require 'the_games_db/version'
5
+ require 'the_games_db/exception'
6
+ require 'the_games_db/image/banner'
7
+ require 'the_games_db/image/boxart'
8
+ require 'the_games_db/image/fanart'
9
+ require 'the_games_db/image/screenshot'
10
+ require 'the_games_db/game'
11
+ require 'the_games_db/feed'
@@ -0,0 +1,17 @@
1
+ module TheGamesDB
2
+ module Exception
3
+
4
+ class BadResponse < StandardError
5
+ def initialize(message)
6
+ super "Error Fetching Data from TheGamesDB: #{message}"
7
+ end
8
+ end
9
+
10
+ class GameNotFound < StandardError
11
+ def initialize(id)
12
+ super "Game Not Found: id = #{id}"
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,31 @@
1
+ module TheGamesDB
2
+ class Feed
3
+ include SAXMachine
4
+
5
+ BaseApiUrl = "http://thegamesdb.net/api/"
6
+ Timeout = 10_000 # milliseconds
7
+
8
+ element :baseImgUrl, :as => :base_image_url
9
+ elements :Game, :as => :games, :class => TheGamesDB::Game
10
+
11
+ def self.fetch_and_parse(path, params={})
12
+ parse fetch(path, params)
13
+ end
14
+
15
+ def self.fetch(path, params={})
16
+ response = Typhoeus::Request.get(api_url(path), :params => params, :timeout => Timeout)
17
+
18
+ bad_response!(response) unless response.success?
19
+ response.body
20
+ end
21
+
22
+ def self.api_url(path)
23
+ BaseApiUrl + path
24
+ end
25
+
26
+ def self.bad_response!(response)
27
+ raise TheGamesDB::Exception::BadResponse.new(response.curl_error_message)
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,47 @@
1
+ require 'date'
2
+
3
+ module TheGamesDB
4
+ class Game
5
+ include SAXMachine
6
+
7
+ parent :feed
8
+ element :id
9
+ element :GameTitle, :as => :title
10
+ element :Overview, :as => :overview
11
+ element :Platform, :as => :platform
12
+ element :ESRB, :as => :esrb
13
+ element :Players, :as => :players
14
+ element :'Co-op', :as => :cooperative
15
+ element :Publisher, :as => :publisher
16
+ element :Developer, :as => :developer
17
+ element :ReleaseDate, :as => :release_date
18
+ element :Rating, :as => :rating
19
+ element :Youtube, :as => :youtube_video
20
+ elements :genre, :as => :genres
21
+ elements :banner, :as => :banners, :class => TheGamesDB::Image::Banner
22
+ elements :boxart, :as => :boxarts, :class => TheGamesDB::Image::Boxart
23
+ elements :fanart, :as => :fanarts, :class => TheGamesDB::Image::Fanart
24
+ elements :screenshot, :as => :screenshots, :class => TheGamesDB::Image::Screenshot
25
+
26
+ attr_accessor :feed
27
+
28
+ def self.search(params = {})
29
+ feed = TheGamesDB::Feed.fetch_and_parse('GetGamesList.php', params)
30
+ feed.games
31
+ end
32
+
33
+ def self.find(id)
34
+ feed = TheGamesDB::Feed.fetch_and_parse('GetGame.php', :id => id)
35
+
36
+ feed.games.first || raise(TheGamesDB::Exception::GameNotFound.new id)
37
+ end
38
+
39
+ def release_date
40
+ return unless @release_date
41
+
42
+ month, day, year = @release_date.split('/').map(&:to_i)
43
+ Date.civil year, month, day
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,25 @@
1
+ module TheGamesDB
2
+ module Image
3
+ class Banner
4
+ include SAXMachine
5
+
6
+ parent :game
7
+ value :path
8
+ attribute :width
9
+ attribute :height
10
+
11
+ def url
12
+ game.feed.base_image_url + path
13
+ end
14
+
15
+ def width
16
+ @width.to_i
17
+ end
18
+
19
+ def height
20
+ @height.to_i
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,26 @@
1
+ module TheGamesDB
2
+ module Image
3
+ class Boxart
4
+ include SAXMachine
5
+
6
+ parent :game
7
+ value :path
8
+ attribute :side
9
+ attribute :width
10
+ attribute :height
11
+
12
+ def url
13
+ game.feed.base_image_url + path
14
+ end
15
+
16
+ def width
17
+ @width.to_i
18
+ end
19
+
20
+ def height
21
+ @height.to_i
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ require 'the_games_db/image/format'
2
+
3
+ module TheGamesDB
4
+ module Image
5
+ class Fanart
6
+ include SAXMachine
7
+
8
+ parent :game
9
+ element :original, :class => TheGamesDB::Image::Format
10
+ element :vignette, :class => TheGamesDB::Image::Format
11
+ element :thumb, :class => TheGamesDB::Image::Format
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ module TheGamesDB
2
+ module Image
3
+ class Format
4
+ include SAXMachine
5
+
6
+ parent :image
7
+ value :path
8
+ attribute :width
9
+ attribute :height
10
+
11
+ def url
12
+ image.game.feed.base_image_url + path
13
+ end
14
+
15
+ def width
16
+ @width.to_i
17
+ end
18
+
19
+ def height
20
+ @height.to_i
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,13 @@
1
+ require 'the_games_db/image/format'
2
+
3
+ module TheGamesDB
4
+ module Image
5
+ class Screenshot
6
+ include SAXMachine
7
+
8
+ parent :game
9
+ element :original, :class => TheGamesDB::Image::Format
10
+ element :thumb, :class => TheGamesDB::Image::Format
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module TheGamesDB
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,83 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+
3
+ <Data>
4
+ <baseImgUrl>http://thegamesdb.net/banners/</baseImgUrl>
5
+ <Game>
6
+ <id>140</id>
7
+ <GameTitle>Super Mario Bros.</GameTitle>
8
+ <Platform>Nintendo Entertainment System (NES)</Platform>
9
+ <ReleaseDate>09/13/1985</ReleaseDate>
10
+ <Overview>The player takes the role of Mario, or in the case of a second player, Mario's brother Luigi. The ultimate objective is to race through the worlds of the Mushroom Kingdom, evade or eliminate Bowser's forces, and save the Princess</Overview>
11
+ <ESRB>E - Everyone</ESRB>
12
+ <Genres>
13
+ <genre>Adventure</genre>
14
+ <genre>Platform</genre>
15
+ </Genres>
16
+ <Players>2</Players>
17
+ <Co-op>No</Co-op>
18
+ <Publisher>Nintendo</Publisher>
19
+ <Developer>Nintendo</Developer>
20
+ <Actors>N/A</Actors>
21
+ <Images>
22
+ <fanart>
23
+ <original width="1920" height="1080">fanart/original/140-1.jpg</original>
24
+ <vignette width="1920" height="1080">fanart/vignette/140-1.jpg</vignette>
25
+ <thumb>fanart/thumb/140-1.jpg</thumb>
26
+ </fanart>
27
+ <fanart>
28
+ <original width="1920" height="1080">fanart/original/140-10.jpg</original>
29
+ <vignette width="1920" height="1080">fanart/vignette/140-10.jpg</vignette>
30
+ <thumb>fanart/thumb/140-10.jpg</thumb>
31
+ </fanart>
32
+ <fanart>
33
+ <original width="1920" height="1080">fanart/original/140-2.jpg</original>
34
+ <vignette width="1920" height="1080">fanart/vignette/140-2.jpg</vignette>
35
+ <thumb>fanart/thumb/140-2.jpg</thumb>
36
+ </fanart>
37
+ <fanart>
38
+ <original width="1920" height="1080">fanart/original/140-3.jpg</original>
39
+ <vignette width="1920" height="1080">fanart/vignette/140-3.jpg</vignette>
40
+ <thumb>fanart/thumb/140-3.jpg</thumb>
41
+ </fanart>
42
+ <fanart>
43
+ <original width="1920" height="1080">fanart/original/140-4.jpg</original>
44
+ <vignette width="1920" height="1080">fanart/vignette/140-4.jpg</vignette>
45
+ <thumb>fanart/thumb/140-4.jpg</thumb>
46
+ </fanart>
47
+ <fanart>
48
+ <original width="1920" height="1080">fanart/original/140-5.jpg</original>
49
+ <vignette width="1920" height="1080">fanart/vignette/140-5.jpg</vignette>
50
+ <thumb>fanart/thumb/140-5.jpg</thumb>
51
+ </fanart>
52
+ <fanart>
53
+ <original width="1920" height="1080">fanart/original/140-6.jpg</original>
54
+ <vignette width="1920" height="1080">fanart/vignette/140-6.jpg</vignette>
55
+ <thumb>fanart/thumb/140-6.jpg</thumb>
56
+ </fanart>
57
+ <fanart>
58
+ <original width="1920" height="1080">fanart/original/140-7.jpg</original>
59
+ <vignette width="1920" height="1080">fanart/vignette/140-7.jpg</vignette>
60
+ <thumb>fanart/thumb/140-7.jpg</thumb>
61
+ </fanart>
62
+ <fanart>
63
+ <original width="1920" height="1080">fanart/original/140-8.jpg</original>
64
+ <vignette width="1920" height="1080">fanart/vignette/140-8.jpg</vignette>
65
+ <thumb>fanart/thumb/140-8.jpg</thumb>
66
+ </fanart>
67
+ <fanart>
68
+ <original width="1920" height="1080">fanart/original/140-9.jpg</original>
69
+ <vignette width="1920" height="1080">fanart/vignette/140-9.jpg</vignette>
70
+ <thumb>fanart/thumb/140-9.jpg</thumb>
71
+ </fanart>
72
+ <boxart side="front" width="709" height="1000">boxart/original/front/140-1.jpg</boxart>
73
+ <boxart side="back" width="1532" height="2100">boxart/original/back/140-2.jpg</boxart>
74
+ <banner width="760" height="140">graphical/140-g.jpg</banner>
75
+ <banner width="760" height="140">graphical/140-g2.jpg</banner>
76
+ <banner width="760" height="140">graphical/140-g3.jpg</banner>
77
+ <screenshot>
78
+ <original width="256" height="232">screenshots/140-1.jpg</original>
79
+ <thumb>screenshots/thumb/140-1.jpg</thumb>
80
+ </screenshot>
81
+ </Images>
82
+ </Game>
83
+ </Data>
@@ -0,0 +1,44 @@
1
+ <?xml version="1.0" encoding="UTF-8" ?>
2
+
3
+ <Data>
4
+ <Game>
5
+ <id>6859</id>
6
+ <GameTitle>New Super Mario Bros.</GameTitle>
7
+ <Platform>Nintendo DS</Platform>
8
+ </Game>
9
+ <Game>
10
+ <id>170</id>
11
+ <GameTitle>New Super Mario Bros. Wii</GameTitle>
12
+ <ReleaseDate>11/20/2009</ReleaseDate>
13
+ <Platform>Nintendo Wii</Platform>
14
+ </Game>
15
+ <Game>
16
+ <id>140</id>
17
+ <GameTitle>Super Mario Bros.</GameTitle>
18
+ <ReleaseDate>09/13/1985</ReleaseDate>
19
+ <Platform>Nintendo Entertainment System (NES)</Platform>
20
+ </Game>
21
+ <Game>
22
+ <id>3727</id>
23
+ <GameTitle>Super Mario Bros.</GameTitle>
24
+ <Platform>Nintendo Gameboy Advance</Platform>
25
+ </Game>
26
+ <Game>
27
+ <id>6410</id>
28
+ <GameTitle>Super Mario Bros. / Duck Hunt</GameTitle>
29
+ <ReleaseDate>07/26/1988</ReleaseDate>
30
+ <Platform>Nintendo Entertainment System (NES)</Platform>
31
+ </Game>
32
+ <Game>
33
+ <id>171</id>
34
+ <GameTitle>Super Mario Bros. 2</GameTitle>
35
+ <ReleaseDate>10/01/1988</ReleaseDate>
36
+ <Platform>Nintendo Entertainment System (NES)</Platform>
37
+ </Game>
38
+ <Game>
39
+ <id>112</id>
40
+ <GameTitle>Super Mario Bros. 3</GameTitle>
41
+ <ReleaseDate>10/23/1988</ReleaseDate>
42
+ <Platform>Nintendo Entertainment System (NES)</Platform>
43
+ </Game>
44
+ </Data>
@@ -0,0 +1,19 @@
1
+ require 'pathname'
2
+ require 'rspec'
3
+ require 'rspec/autorun'
4
+ require 'mocha'
5
+
6
+ SpecRoot = Pathname.new File.expand_path('..', __FILE__)
7
+ $LOAD_PATH.unshift(SpecRoot)
8
+ $LOAD_PATH.unshift(File.join(SpecRoot, '..', 'lib'))
9
+
10
+ require 'the_games_db'
11
+
12
+ RSpec.configure do |config|
13
+ config.color_enabled = true
14
+ config.filter_run :focused => true
15
+ config.run_all_when_everything_filtered = true
16
+ config.alias_example_to :fit, :focused => true
17
+ config.alias_example_to :they
18
+ config.mock_with :mocha
19
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe TheGamesDB::Feed do
4
+
5
+ let(:xml) { SpecRoot.join('fixtures', 'game.xml').read }
6
+
7
+ context ".fetch" do
8
+ context 'when the request was successful' do
9
+ before do
10
+ expected_url = "http://thegamesdb.net/api/GetGame.php"
11
+ successful_response = stub 'response', :success? => true, :body => xml
12
+ Typhoeus::Request.expects(:get).
13
+ with(expected_url, :params => {:id => 140}, :timeout => TheGamesDB::Feed::Timeout).
14
+ returns(successful_response)
15
+ end
16
+
17
+ it 'returns the XML response' do
18
+ TheGamesDB::Feed.fetch('GetGame.php', :id => 140).should == xml
19
+ end
20
+ end
21
+
22
+ context 'when the request was unsuccessful' do
23
+ let(:xml) { SpecRoot.join('fixtures', 'game.xml').read }
24
+ before do
25
+ expected_url = "http://thegamesdb.net/api/GetGame.php"
26
+ error_response = stub 'response', :success? => false, :code => 500, :curl_error_message => '500'
27
+ Typhoeus::Request.expects(:get).
28
+ with(expected_url, :params => {:id => 140}, :timeout => TheGamesDB::Feed::Timeout).
29
+ returns(error_response)
30
+ end
31
+
32
+ it 'raises an exception' do
33
+ expect do
34
+ TheGamesDB::Feed.fetch('GetGame.php', :id => 140)
35
+ end.should raise_error(TheGamesDB::Exception::BadResponse)
36
+ end
37
+ end
38
+
39
+ context 'when the request times out' do
40
+ let(:xml) { SpecRoot.join('fixtures', 'game.xml').read }
41
+ before do
42
+ expected_url = "http://thegamesdb.net/api/GetGame.php"
43
+ error_response = stub 'response', :success? => false, :timed_out? => true, :curl_error_message => 'Timed out'
44
+ Typhoeus::Request.expects(:get).
45
+ with(expected_url, :params => {:id => 140}, :timeout => TheGamesDB::Feed::Timeout).
46
+ returns(error_response)
47
+ end
48
+
49
+ it 'raises an exception' do
50
+ expect do
51
+ TheGamesDB::Feed.fetch('GetGame.php', :id => 140)
52
+ end.should raise_error(TheGamesDB::Exception::BadResponse)
53
+ end
54
+ end
55
+ end
56
+
57
+ context '.fetch_and_parse' do
58
+ before do
59
+ TheGamesDB::Feed.expects(:fetch).with('GetGame.php', :id => 140).returns(xml)
60
+ end
61
+
62
+ it 'parses the XML response' do
63
+ feed = TheGamesDB::Feed.fetch_and_parse 'GetGame.php', :id => 140
64
+ feed.base_image_url.should == "http://thegamesdb.net/banners/"
65
+ feed.games.should_not be_empty
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,81 @@
1
+ require 'spec_helper'
2
+
3
+ describe TheGamesDB::Game do
4
+
5
+ context '.search' do
6
+ it 'hits the GetGamesList API endpoint' do
7
+ TheGamesDB::Feed.expects(:fetch_and_parse).with('GetGamesList.php', :name => 'Mario').returns(stub_everything)
8
+ TheGamesDB::Game.search(:name => 'Mario')
9
+ end
10
+ end
11
+
12
+ context '.find' do
13
+ it 'hits the GetGame API endpoint' do
14
+ feed = stub 'feed', :games => [stub('game')]
15
+ TheGamesDB::Feed.expects(:fetch_and_parse).with('GetGame.php', :id => 140).returns(feed)
16
+ TheGamesDB::Game.find 140
17
+ end
18
+
19
+ context 'when the game is found' do
20
+ let(:game) { stub 'game' }
21
+
22
+ before do
23
+ feed = stub 'feed', :games => [game]
24
+ TheGamesDB::Feed.expects(:fetch_and_parse).returns(feed)
25
+ end
26
+
27
+ it 'returns the game' do
28
+ TheGamesDB::Game.find(140).should == game
29
+ end
30
+ end
31
+
32
+ context 'when the game is not found' do
33
+ before do
34
+ feed = stub 'feed', :games => []
35
+ TheGamesDB::Feed.expects(:fetch_and_parse).returns(feed)
36
+ end
37
+
38
+ it 'raises a not found error' do
39
+ expect do
40
+ TheGamesDB::Game.find(-1)
41
+ end.should raise_error(TheGamesDB::Exception::GameNotFound)
42
+ end
43
+ end
44
+ end
45
+
46
+ context 'when parsed' do
47
+ before do
48
+ game_xml = SpecRoot.join 'fixtures', 'game.xml'
49
+ TheGamesDB::Feed.stubs(:fetch).returns(game_xml.read)
50
+ end
51
+
52
+ let(:game) { TheGamesDB::Game.find 140 }
53
+
54
+ it 'correctly parses the values' do
55
+ game.id.should == "140"
56
+ game.title.should == "Super Mario Bros."
57
+ game.overview.should =~ /^The player takes the role of Mario/
58
+ game.platform.should == "Nintendo Entertainment System (NES)"
59
+ game.esrb.should == "E - Everyone"
60
+ game.players.should == "2"
61
+ game.cooperative.should == "No"
62
+ game.publisher.should == "Nintendo"
63
+ game.developer.should == "Nintendo"
64
+ game.release_date.should == Date.parse("September 13, 1985")
65
+ game.genres.should include('Adventure', 'Platform')
66
+
67
+ game.banners.should_not be_empty
68
+ game.banners.first.should be_a TheGamesDB::Image::Banner
69
+
70
+ game.boxarts.should_not be_empty
71
+ game.boxarts.first.should be_a TheGamesDB::Image::Boxart
72
+
73
+ game.fanarts.should_not be_empty
74
+ game.fanarts.first.should be_a TheGamesDB::Image::Fanart
75
+
76
+ game.screenshots.should_not be_empty
77
+ game.screenshots.first.should be_a TheGamesDB::Image::Screenshot
78
+ end
79
+ end
80
+
81
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe TheGamesDB::Image::Banner do
4
+
5
+ before do
6
+ game_xml = SpecRoot.join 'fixtures', 'game.xml'
7
+ TheGamesDB::Feed.stubs(:fetch).returns(game_xml.read)
8
+ end
9
+
10
+ let(:game) { TheGamesDB::Game.find 140 }
11
+ let(:banner) { game.banners.first }
12
+
13
+ it 'is parsed correctly' do
14
+ banner.width.should == 760
15
+ banner.height.should == 140
16
+ banner.path.should == "graphical/140-g.jpg"
17
+ end
18
+
19
+ context '#url' do
20
+ it 'is composed of the base image url and the path' do
21
+ banner.url.should == 'http://thegamesdb.net/banners/graphical/140-g.jpg'
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe TheGamesDB::Image::Boxart do
4
+
5
+ before do
6
+ game_xml = SpecRoot.join 'fixtures', 'game.xml'
7
+ TheGamesDB::Feed.stubs(:fetch).returns(game_xml.read)
8
+ end
9
+
10
+ let(:game) { TheGamesDB::Game.find 140 }
11
+ let(:boxart) { game.boxarts.first }
12
+
13
+ it 'is parsed correctly' do
14
+ boxart.side.should == "front"
15
+ boxart.width.should == 709
16
+ boxart.height.should == 1000
17
+ boxart.path.should == "boxart/original/front/140-1.jpg"
18
+ end
19
+
20
+ context '#url' do
21
+ it 'is composed of the base image url and the path' do
22
+ boxart.url.should == 'http://thegamesdb.net/banners/boxart/original/front/140-1.jpg'
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe TheGamesDB::Image::Fanart do
4
+
5
+ before do
6
+ game_xml = SpecRoot.join 'fixtures', 'game.xml'
7
+ TheGamesDB::Feed.stubs(:fetch).returns(game_xml.read)
8
+ end
9
+
10
+ let(:game) { TheGamesDB::Game.find 140 }
11
+ let(:fanart) { game.fanarts.first }
12
+
13
+ it 'is parsed correctly' do
14
+ fanart.original.should_not be_nil
15
+ fanart.original.width.should == 1920
16
+ fanart.original.height.should == 1080
17
+ fanart.original.path.should == 'fanart/original/140-1.jpg'
18
+
19
+ fanart.vignette.should_not be_nil
20
+ fanart.vignette.width.should == 1920
21
+ fanart.vignette.height.should == 1080
22
+ fanart.vignette.path.should == 'fanart/vignette/140-1.jpg'
23
+
24
+ fanart.thumb.should_not be_nil
25
+ fanart.thumb.path.should == 'fanart/thumb/140-1.jpg'
26
+ end
27
+
28
+ context '#url' do
29
+ it 'is composed of the base image url and the path' do
30
+ fanart.original.url.should == 'http://thegamesdb.net/banners/fanart/original/140-1.jpg'
31
+ fanart.vignette.url.should == 'http://thegamesdb.net/banners/fanart/vignette/140-1.jpg'
32
+ fanart.thumb.url.should == 'http://thegamesdb.net/banners/fanart/thumb/140-1.jpg'
33
+ end
34
+ end
35
+
36
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe TheGamesDB::Image::Screenshot do
4
+
5
+ before do
6
+ game_xml = SpecRoot.join 'fixtures', 'game.xml'
7
+ TheGamesDB::Feed.stubs(:fetch).returns(game_xml.read)
8
+ end
9
+
10
+ let(:game) { TheGamesDB::Game.find 140 }
11
+ let(:screenshot) { game.screenshots.first }
12
+
13
+ it 'is parsed correctly' do
14
+ screenshot.original.should_not be_nil
15
+ screenshot.original.width.should == 256
16
+ screenshot.original.height.should == 232
17
+ screenshot.original.path.should == 'screenshots/140-1.jpg'
18
+
19
+ screenshot.thumb.should_not be_nil
20
+ screenshot.thumb.path.should == 'screenshots/thumb/140-1.jpg'
21
+ end
22
+
23
+ context '#url' do
24
+ it 'is composed of the base image url and the path' do
25
+ screenshot.original.url.should == 'http://thegamesdb.net/banners/screenshots/140-1.jpg'
26
+ screenshot.thumb.url.should == 'http://thegamesdb.net/banners/screenshots/thumb/140-1.jpg'
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "the_games_db/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "the_games_db"
7
+ s.version = TheGamesDB::VERSION
8
+ s.authors = ["Jared Pace"]
9
+ s.email = ["jared@codeword.io"]
10
+ s.homepage = "https://github.com/jdpace/the_games_db"
11
+ s.summary = %q{TheGamesDB.net API wrapper}
12
+ s.description = %q{Ruby API Wrapper for TheGamesDB.net}
13
+
14
+ s.rubyforge_project = "the_games_db"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # Dependencies
22
+ s.add_dependency 'typhoeus', ['~> 0.2.4']
23
+ s.add_dependency 'nokogiri', ['~> 1.4.6']
24
+ s.add_dependency 'sax-machine', ['~> 0.0.20']
25
+
26
+ # Developmnet Dependencies
27
+ s.add_development_dependency 'rspec', ['~> 2.6']
28
+ s.add_development_dependency 'mocha', ['~> 0.9.12']
29
+ s.add_development_dependency 'guard-rspec', ['~> 0.4']
30
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: the_games_db
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Jared Pace
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-09-23 00:00:00 -04:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: typhoeus
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 0.2.4
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ prerelease: false
30
+ requirement: &id002 !ruby/object:Gem::Requirement
31
+ none: false
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: 1.4.6
36
+ type: :runtime
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: sax-machine
40
+ prerelease: false
41
+ requirement: &id003 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: 0.0.20
47
+ type: :runtime
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ prerelease: false
52
+ requirement: &id004 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ~>
56
+ - !ruby/object:Gem::Version
57
+ version: "2.6"
58
+ type: :development
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: mocha
62
+ prerelease: false
63
+ requirement: &id005 !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.12
69
+ type: :development
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: guard-rspec
73
+ prerelease: false
74
+ requirement: &id006 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ~>
78
+ - !ruby/object:Gem::Version
79
+ version: "0.4"
80
+ type: :development
81
+ version_requirements: *id006
82
+ description: Ruby API Wrapper for TheGamesDB.net
83
+ email:
84
+ - jared@codeword.io
85
+ executables: []
86
+
87
+ extensions: []
88
+
89
+ extra_rdoc_files: []
90
+
91
+ files:
92
+ - .gitignore
93
+ - Gemfile
94
+ - Guardfile
95
+ - LICENSE
96
+ - README.md
97
+ - Rakefile
98
+ - lib/the_games_db.rb
99
+ - lib/the_games_db/exception.rb
100
+ - lib/the_games_db/feed.rb
101
+ - lib/the_games_db/game.rb
102
+ - lib/the_games_db/image/banner.rb
103
+ - lib/the_games_db/image/boxart.rb
104
+ - lib/the_games_db/image/fanart.rb
105
+ - lib/the_games_db/image/format.rb
106
+ - lib/the_games_db/image/screenshot.rb
107
+ - lib/the_games_db/version.rb
108
+ - spec/fixtures/game.xml
109
+ - spec/fixtures/games.xml
110
+ - spec/spec_helper.rb
111
+ - spec/the_games_db/feed_spec.rb
112
+ - spec/the_games_db/game_spec.rb
113
+ - spec/the_games_db/image/banner_spec.rb
114
+ - spec/the_games_db/image/boxart_spec.rb
115
+ - spec/the_games_db/image/fanart_spec.rb
116
+ - spec/the_games_db/image/screenshot_spec.rb
117
+ - the_games_db.gemspec
118
+ has_rdoc: true
119
+ homepage: https://github.com/jdpace/the_games_db
120
+ licenses: []
121
+
122
+ post_install_message:
123
+ rdoc_options: []
124
+
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: "0"
133
+ required_rubygems_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: "0"
139
+ requirements: []
140
+
141
+ rubyforge_project: the_games_db
142
+ rubygems_version: 1.6.2
143
+ signing_key:
144
+ specification_version: 3
145
+ summary: TheGamesDB.net API wrapper
146
+ test_files:
147
+ - spec/fixtures/game.xml
148
+ - spec/fixtures/games.xml
149
+ - spec/spec_helper.rb
150
+ - spec/the_games_db/feed_spec.rb
151
+ - spec/the_games_db/game_spec.rb
152
+ - spec/the_games_db/image/banner_spec.rb
153
+ - spec/the_games_db/image/boxart_spec.rb
154
+ - spec/the_games_db/image/fanart_spec.rb
155
+ - spec/the_games_db/image/screenshot_spec.rb