gamesdb 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -0
- data/Gemfile.lock +53 -0
- data/README.md +4 -0
- data/gamesdb.gemspec +23 -0
- data/lib/gamesdb.rb +12 -0
- data/lib/gamesdb/client.rb +71 -0
- data/lib/gamesdb/models/game.rb +7 -0
- data/lib/gamesdb/models/games.rb +10 -0
- data/lib/gamesdb/requests/list_games.rb +16 -0
- data/lib/gamesdb/saxdocument.rb +63 -0
- data/lib/gamesdb/seeds/games.yaml +82 -0
- data/lib/gamesdb/version.rb +3 -0
- data/spec/games_spec.rb +10 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/support/client_helper.rb +9 -0
- metadata +124 -0
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gamesdb (0.0.1)
|
5
|
+
cistern
|
6
|
+
excon
|
7
|
+
nokogiri
|
8
|
+
rest-client
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
cistern (0.1.4)
|
14
|
+
coderay (1.0.8)
|
15
|
+
diff-lcs (1.1.3)
|
16
|
+
excon (0.16.10)
|
17
|
+
guard (1.5.4)
|
18
|
+
listen (>= 0.4.2)
|
19
|
+
lumberjack (>= 1.0.2)
|
20
|
+
pry (>= 0.9.10)
|
21
|
+
thor (>= 0.14.6)
|
22
|
+
guard-rspec (2.3.1)
|
23
|
+
guard (>= 1.1)
|
24
|
+
rspec (~> 2.11)
|
25
|
+
listen (0.6.0)
|
26
|
+
lumberjack (1.0.2)
|
27
|
+
method_source (0.8.1)
|
28
|
+
mime-types (1.21)
|
29
|
+
nokogiri (1.5.5)
|
30
|
+
pry (0.9.10)
|
31
|
+
coderay (~> 1.0.5)
|
32
|
+
method_source (~> 0.8)
|
33
|
+
slop (~> 3.3.1)
|
34
|
+
rest-client (1.6.7)
|
35
|
+
mime-types (>= 1.16)
|
36
|
+
rspec (2.12.0)
|
37
|
+
rspec-core (~> 2.12.0)
|
38
|
+
rspec-expectations (~> 2.12.0)
|
39
|
+
rspec-mocks (~> 2.12.0)
|
40
|
+
rspec-core (2.12.2)
|
41
|
+
rspec-expectations (2.12.1)
|
42
|
+
diff-lcs (~> 1.1.3)
|
43
|
+
rspec-mocks (2.12.2)
|
44
|
+
slop (3.3.3)
|
45
|
+
thor (0.17.0)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
ruby
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
gamesdb!
|
52
|
+
guard-rspec
|
53
|
+
rspec
|
data/README.md
ADDED
data/gamesdb.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
6
|
+
require 'gamesdb/version'
|
7
|
+
|
8
|
+
Gem::Specification.new do |gem|
|
9
|
+
gem.name = "gamesdb"
|
10
|
+
gem.version = Gamesdb::Version
|
11
|
+
gem.authors = ["Eugene Howe"]
|
12
|
+
gem.email = "eugene@xtreme-computers.net"
|
13
|
+
gem.summary = "Gem for searching thegamesdb.net"
|
14
|
+
gem.homepage = "https://github.com/ehowe/gamesdb.git"
|
15
|
+
|
16
|
+
gem.files = `git ls-files`.split($/)
|
17
|
+
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_dependency 'cistern'
|
20
|
+
gem.add_dependency 'excon'
|
21
|
+
gem.add_dependency 'nokogiri'
|
22
|
+
gem.add_dependency 'rest-client'
|
23
|
+
end
|
data/lib/gamesdb.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
class Gamesdb::Client < Cistern::Service
|
2
|
+
|
3
|
+
model_path "gamesdb/models"
|
4
|
+
request_path "gamesdb/requests"
|
5
|
+
|
6
|
+
model :game
|
7
|
+
collection :games
|
8
|
+
request :list_games
|
9
|
+
|
10
|
+
class Real
|
11
|
+
attr_reader :connection
|
12
|
+
|
13
|
+
def initialize(options={})
|
14
|
+
url = options[:url] || 'http://thegamesdb.net/api'
|
15
|
+
|
16
|
+
@connection = RestClient::Resource.new(url) #Excon.new(url)
|
17
|
+
end
|
18
|
+
|
19
|
+
def request(options)
|
20
|
+
path = options[:path]
|
21
|
+
method = options[:method] || :get
|
22
|
+
method = method.to_sym
|
23
|
+
headers = options[:headers] || {}
|
24
|
+
body = options[:body] || nil
|
25
|
+
expects = options[:expects] || 200
|
26
|
+
query = options[:query] || nil
|
27
|
+
|
28
|
+
connect_hash = {
|
29
|
+
:method => method,
|
30
|
+
:headers => headers,
|
31
|
+
:path => path,
|
32
|
+
:expects => expects,
|
33
|
+
:body => body,
|
34
|
+
#:query => query
|
35
|
+
}
|
36
|
+
|
37
|
+
path = "#{path}?#{query.map{|k,v| "#{URI.escape(k.to_s)}=#{URI.escape(v.to_s)}"}.join("&")}" unless query.empty?
|
38
|
+
response = case method
|
39
|
+
when :get
|
40
|
+
connection[path].get(headers)
|
41
|
+
when :post
|
42
|
+
connection[path].post(body, headers)
|
43
|
+
when :delete
|
44
|
+
connection[path].delete(headers)
|
45
|
+
end
|
46
|
+
|
47
|
+
document = Gamesdb::SaxDocument.new
|
48
|
+
parser = Nokogiri::XML::SAX::PushParser.new(document)
|
49
|
+
parser << response
|
50
|
+
parser.finish
|
51
|
+
document.body
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Mock
|
56
|
+
def initialize(options={})
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.data
|
60
|
+
@data ||= {}
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.reset!
|
64
|
+
@data = nil
|
65
|
+
end
|
66
|
+
|
67
|
+
def data
|
68
|
+
self.class.data
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Gamesdb::Client
|
2
|
+
class Real
|
3
|
+
def list_games(search)
|
4
|
+
request(
|
5
|
+
:path => "/GetGamesList.php",
|
6
|
+
:query => {"name" => search},
|
7
|
+
)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class Mock
|
12
|
+
def list_games(search)
|
13
|
+
YAML.load_file(File.expand_path("../../seeds/games.yaml", __FILE__))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class Gamesdb::SaxDocument < Nokogiri::XML::SAX::Document
|
2
|
+
attr_reader :stack
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@stack = []
|
6
|
+
end
|
7
|
+
|
8
|
+
def characters(string)
|
9
|
+
@value ||= ''
|
10
|
+
@value << string.strip
|
11
|
+
end
|
12
|
+
|
13
|
+
def body
|
14
|
+
@stack.first.each do |key, value|
|
15
|
+
@stack.first[key] = [value] if value.is_a?(Hash)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def end_element(name)
|
20
|
+
last = @stack.pop
|
21
|
+
if last.empty? && @value.empty?
|
22
|
+
@stack.last[name] = ''
|
23
|
+
elsif last == {:i_nil=>"true"}
|
24
|
+
@stack.last[name] = nil
|
25
|
+
elsif !@value.empty?
|
26
|
+
@stack.last[name] = @value
|
27
|
+
end
|
28
|
+
@value = ''
|
29
|
+
end
|
30
|
+
|
31
|
+
def start_element(name, attributes = [])
|
32
|
+
@value = ''
|
33
|
+
parsed_attributes = {}
|
34
|
+
until attributes.empty?
|
35
|
+
if attributes.first.is_a?(Array)
|
36
|
+
key, value = attributes.shift
|
37
|
+
else
|
38
|
+
key, value = attributes.shift, attributes.shift
|
39
|
+
end
|
40
|
+
parsed_attributes[key.gsub(':','_')] = value
|
41
|
+
end
|
42
|
+
if @stack.last.is_a?(Array)
|
43
|
+
@stack.last << {name => parsed_attributes}
|
44
|
+
else
|
45
|
+
data = if @stack.empty?
|
46
|
+
@stack.push(parsed_attributes)
|
47
|
+
parsed_attributes
|
48
|
+
elsif @stack.last[name]
|
49
|
+
unless @stack.last[name].is_a?(Array)
|
50
|
+
@stack.last[name] = [@stack.last[name]]
|
51
|
+
end
|
52
|
+
@stack.last[name] << parsed_attributes
|
53
|
+
@stack.last[name].last
|
54
|
+
else
|
55
|
+
@stack.last[name] = {}
|
56
|
+
@stack.last[name].merge!(parsed_attributes)
|
57
|
+
@stack.last[name]
|
58
|
+
end
|
59
|
+
@stack.push(data)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
@@ -0,0 +1,82 @@
|
|
1
|
+
---
|
2
|
+
Game:
|
3
|
+
- id: '665'
|
4
|
+
GameTitle: X-Men
|
5
|
+
ReleaseDate: '1993'
|
6
|
+
Platform: Sega Genesis
|
7
|
+
- id: '8104'
|
8
|
+
GameTitle: X-Men
|
9
|
+
ReleaseDate: 01/01/1993
|
10
|
+
Platform: Sega Mega Drive
|
11
|
+
- id: '14795'
|
12
|
+
GameTitle: X-Men
|
13
|
+
ReleaseDate: 01/01/1994
|
14
|
+
Platform: Sega Game Gear
|
15
|
+
- id: '1386'
|
16
|
+
GameTitle: The Uncanny X-Men
|
17
|
+
ReleaseDate: 12/01/1989
|
18
|
+
Platform: Nintendo Entertainment System (NES)
|
19
|
+
- id: '4763'
|
20
|
+
GameTitle: X-Men Legends
|
21
|
+
ReleaseDate: 09/21/2004
|
22
|
+
Platform: Sony Playstation 2
|
23
|
+
- id: '4765'
|
24
|
+
GameTitle: ! 'X-Men: Next Dimension'
|
25
|
+
ReleaseDate: 10/15/2002
|
26
|
+
Platform: Sony Playstation 2
|
27
|
+
- id: '5444'
|
28
|
+
GameTitle: X-Men Legends
|
29
|
+
ReleaseDate: 09/24/2004
|
30
|
+
Platform: Nintendo GameCube
|
31
|
+
- id: '8311'
|
32
|
+
GameTitle: ! 'X-Men: Destiny'
|
33
|
+
ReleaseDate: 09/27/2011
|
34
|
+
Platform: Sony Playstation 3
|
35
|
+
- id: '8898'
|
36
|
+
GameTitle: ! 'X-Men: Destiny'
|
37
|
+
ReleaseDate: 09/27/2011
|
38
|
+
Platform: Microsoft Xbox 360
|
39
|
+
- id: '11467'
|
40
|
+
GameTitle: ! 'X-Men: Next Dimension'
|
41
|
+
ReleaseDate: 10/15/2002
|
42
|
+
Platform: Nintendo GameCube
|
43
|
+
- id: '14096'
|
44
|
+
GameTitle: ! 'X-Men: Destiny'
|
45
|
+
ReleaseDate: 09/27/2011
|
46
|
+
Platform: Nintendo Wii
|
47
|
+
- id: '628'
|
48
|
+
GameTitle: X-Men vs. Street Fighter
|
49
|
+
ReleaseDate: 06/30/1998
|
50
|
+
Platform: Sony Playstation
|
51
|
+
- id: '2468'
|
52
|
+
GameTitle: ! 'X-Men: Children Of The Atom'
|
53
|
+
ReleaseDate: '1994'
|
54
|
+
Platform: Arcade
|
55
|
+
- id: '3123'
|
56
|
+
GameTitle: ! 'X-Men: Mojo World'
|
57
|
+
ReleaseDate: 09/14/1996
|
58
|
+
Platform: Sega Master System
|
59
|
+
- id: '3291'
|
60
|
+
GameTitle: ! 'X-Men: Mutant Apocalypse'
|
61
|
+
ReleaseDate: 01/01/1994
|
62
|
+
Platform: Super Nintendo (SNES)
|
63
|
+
- id: '4209'
|
64
|
+
GameTitle: ! 'X-Men Origins: Wolverine'
|
65
|
+
ReleaseDate: 05/01/2009
|
66
|
+
Platform: PC
|
67
|
+
- id: '4034'
|
68
|
+
GameTitle: ! 'X-Men: The Official Game'
|
69
|
+
ReleaseDate: 05/16/2006
|
70
|
+
Platform: Nintendo Game Boy Advance
|
71
|
+
- id: '4146'
|
72
|
+
GameTitle: ! 'X-Men: Reign of Apocalypse'
|
73
|
+
ReleaseDate: 09/25/2001
|
74
|
+
Platform: Nintendo Game Boy Advance
|
75
|
+
- id: '4978'
|
76
|
+
GameTitle: ! 'X-Men Origins: Wolverine'
|
77
|
+
ReleaseDate: 05/01/2009
|
78
|
+
Platform: Nintendo Wii
|
79
|
+
- id: '5374'
|
80
|
+
GameTitle: ! 'X-Men: The Official Game'
|
81
|
+
ReleaseDate: 05/16/2006
|
82
|
+
Platform: Sony Playstation 2
|
data/spec/games_spec.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
ENV['MOCK_GAMES'] ||= "false"
|
2
|
+
|
3
|
+
Bundler.require(:test)
|
4
|
+
|
5
|
+
require File.expand_path('../../lib/gamesdb', __FILE__)
|
6
|
+
|
7
|
+
Dir[File.expand_path('../{support,matchers}/*.rb', __FILE__)].each { |f| require(f) }
|
8
|
+
|
9
|
+
if ENV['MOCK_GAMES'] == "true"
|
10
|
+
Gamesdb::Client.mock!
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.before(:all) do
|
15
|
+
Gamesdb::Client.reset! if Gamesdb::Client.mocking?
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gamesdb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Eugene Howe
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: cistern
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: excon
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: nokogiri
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rest-client
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description:
|
79
|
+
email: eugene@xtreme-computers.net
|
80
|
+
executables: []
|
81
|
+
extensions: []
|
82
|
+
extra_rdoc_files: []
|
83
|
+
files:
|
84
|
+
- Gemfile
|
85
|
+
- Gemfile.lock
|
86
|
+
- README.md
|
87
|
+
- gamesdb.gemspec
|
88
|
+
- lib/gamesdb.rb
|
89
|
+
- lib/gamesdb/client.rb
|
90
|
+
- lib/gamesdb/models/game.rb
|
91
|
+
- lib/gamesdb/models/games.rb
|
92
|
+
- lib/gamesdb/requests/list_games.rb
|
93
|
+
- lib/gamesdb/saxdocument.rb
|
94
|
+
- lib/gamesdb/seeds/games.yaml
|
95
|
+
- lib/gamesdb/version.rb
|
96
|
+
- spec/games_spec.rb
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
- spec/support/client_helper.rb
|
99
|
+
homepage: https://github.com/ehowe/gamesdb.git
|
100
|
+
licenses: []
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options: []
|
103
|
+
require_paths:
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 1.8.24
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: Gem for searching thegamesdb.net
|
123
|
+
test_files: []
|
124
|
+
has_rdoc:
|