games_radar_api 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +46 -0
- data/Rakefile +9 -0
- data/games_radar_api.gemspec +28 -0
- data/lib/faraday/raise_http_exception.rb +51 -0
- data/lib/games_radar_api.rb +26 -0
- data/lib/games_radar_api/api.rb +22 -0
- data/lib/games_radar_api/client.rb +18 -0
- data/lib/games_radar_api/client/cheats.rb +18 -0
- data/lib/games_radar_api/client/developers.rb +9 -0
- data/lib/games_radar_api/client/franchises.rb +9 -0
- data/lib/games_radar_api/client/games.rb +25 -0
- data/lib/games_radar_api/client/genres.rb +9 -0
- data/lib/games_radar_api/client/guides.rb +18 -0
- data/lib/games_radar_api/client/news.rb +57 -0
- data/lib/games_radar_api/client/platforms.rb +9 -0
- data/lib/games_radar_api/client/publishers.rb +9 -0
- data/lib/games_radar_api/client/screenshots.rb +20 -0
- data/lib/games_radar_api/client/videos.rb +18 -0
- data/lib/games_radar_api/configuration.rb +51 -0
- data/lib/games_radar_api/connection.rb +32 -0
- data/lib/games_radar_api/error.rb +19 -0
- data/lib/games_radar_api/request.rb +42 -0
- data/lib/games_radar_api/version.rb +3 -0
- data/spec/lib/games_radar_api/client/cheats_spec.rb +33 -0
- data/spec/lib/games_radar_api/client/developers_spec.rb +22 -0
- data/spec/lib/games_radar_api/client/franchises_spec.rb +22 -0
- data/spec/lib/games_radar_api/client/games_spec.rb +52 -0
- data/spec/lib/games_radar_api/client/genres_spec.rb +21 -0
- data/spec/lib/games_radar_api/client/guides_spec.rb +31 -0
- data/spec/lib/games_radar_api/client/news_spec.rb +77 -0
- data/spec/lib/games_radar_api/client/platforms_spec.rb +22 -0
- data/spec/lib/games_radar_api/client/publishers_spec.rb +22 -0
- data/spec/lib/games_radar_api/client/screenshots_spec.rb +29 -0
- data/spec/lib/games_radar_api/client/videos_spec.rb +24 -0
- data/spec/lib/games_radar_api/client_spec.rb +59 -0
- data/spec/lib/games_radar_api/configuration_spec.rb +26 -0
- data/spec/lib/games_radar_api/games_radar_api_spec.rb +7 -0
- data/spec/spec_helper.rb +15 -0
- metadata +204 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
module GamesRadarApi
|
2
|
+
class Client
|
3
|
+
module Videos
|
4
|
+
def videos(options={:region=>'us',:platform=>'all',:genre=>'all',:game_name=>'',:page_num=>1,:page_size=>10,:sort=>'newest'})
|
5
|
+
response = get('/videos',options)
|
6
|
+
self.total_rows = response.videos.total_rows.to_i
|
7
|
+
response.videos.video
|
8
|
+
end
|
9
|
+
|
10
|
+
def game_videos(id,options={:region=>'us',:page_num=>1,:page_size=>10})
|
11
|
+
response = get("/game/videos/#{id}",options)
|
12
|
+
self.total_rows = response.videos.total_rows.to_i
|
13
|
+
response.videos.video
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require File.expand_path('../version', __FILE__)
|
3
|
+
|
4
|
+
module GamesRadarApi
|
5
|
+
module Configuration
|
6
|
+
VALID_CONNECTION_KEYS = [:adapter,:endpoint,:user_agent,:method,:proxy].freeze
|
7
|
+
VALID_OPTIONS_KEYS = [:api_key,:format].freeze
|
8
|
+
VALID_CONFIG_KEYS = VALID_CONNECTION_KEYS + VALID_OPTIONS_KEYS
|
9
|
+
|
10
|
+
DEFAULT_ADAPTER = Faraday.default_adapter.freeze
|
11
|
+
DEFAULT_ENDPOINT = 'http://api.gamesradar.com'.freeze
|
12
|
+
DEFAULT_METHOD = 'get'.freeze
|
13
|
+
DEFAULT_USER_AGENT = "Games Radar API Gem #{GamesRadarApi::VERSION}".freeze
|
14
|
+
|
15
|
+
DEFAULT_API_KEY = nil
|
16
|
+
DEFAULT_FORMAT = :xml
|
17
|
+
DEFAULT_PROXY = nil
|
18
|
+
|
19
|
+
# Build accessor methods for every config options so we can do this, for example:
|
20
|
+
# GamesRadarApi.format = :xml
|
21
|
+
attr_accessor *VALID_CONFIG_KEYS
|
22
|
+
|
23
|
+
# Make sure we have the default values set when we get 'extended'
|
24
|
+
def self.extended(base)
|
25
|
+
base.reset
|
26
|
+
end
|
27
|
+
|
28
|
+
# Convenience method to allow configuration options to be set in a block
|
29
|
+
def configure
|
30
|
+
yield self
|
31
|
+
end
|
32
|
+
|
33
|
+
# Create a has of options and their values
|
34
|
+
def options
|
35
|
+
Hash[* VALID_CONFIG_KEYS.map { |key| [key,send(key)] }.flatten ]
|
36
|
+
end
|
37
|
+
|
38
|
+
# Reset all configuration options to defaults
|
39
|
+
def reset
|
40
|
+
self.adapter = DEFAULT_ADAPTER
|
41
|
+
self.endpoint = DEFAULT_ENDPOINT
|
42
|
+
self.method = DEFAULT_METHOD
|
43
|
+
self.user_agent = DEFAULT_USER_AGENT
|
44
|
+
|
45
|
+
self.api_key = DEFAULT_API_KEY
|
46
|
+
self.format = DEFAULT_FORMAT
|
47
|
+
self.proxy = DEFAULT_PROXY
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'faraday_middleware'
|
2
|
+
Dir[File.expand_path('../../faraday/*.rb', __FILE__)].each{|f| require f}
|
3
|
+
|
4
|
+
module GamesRadarApi
|
5
|
+
# @private
|
6
|
+
module Connection
|
7
|
+
private
|
8
|
+
|
9
|
+
def connection(raw=false)
|
10
|
+
options = {
|
11
|
+
:headers => {'Accept' => "application/#{format}; charset=utf-8", 'User-Agent' => user_agent},
|
12
|
+
:proxy => proxy,
|
13
|
+
:ssl => {:verify => false},
|
14
|
+
:url => endpoint,
|
15
|
+
}
|
16
|
+
|
17
|
+
Faraday::Connection.new(options) do |connection|
|
18
|
+
#connection.use FaradayMiddleware::OAuth2, client_id, access_token
|
19
|
+
connection.use Faraday::Request::UrlEncoded
|
20
|
+
connection.use FaradayMiddleware::Mashify unless raw
|
21
|
+
unless raw
|
22
|
+
case format.to_s.downcase
|
23
|
+
when 'json' then connection.use Faraday::Response::ParseJson
|
24
|
+
when 'xml' then connection.use Faraday::Response::ParseXml
|
25
|
+
end
|
26
|
+
end
|
27
|
+
connection.use FaradayMiddleware::RaiseHttpException
|
28
|
+
connection.adapter(adapter)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module GamesRadarApi
|
2
|
+
# Custom error class for rescuing from all Instagram errors
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
# Raised when Instagram returns the HTTP status code 400
|
6
|
+
class BadRequest < Error; end
|
7
|
+
|
8
|
+
# Raised when Instagram returns the HTTP status code 404
|
9
|
+
class NotFound < Error; end
|
10
|
+
|
11
|
+
# Raised when Instagram returns the HTTP status code 500
|
12
|
+
class InternalServerError < Error; end
|
13
|
+
|
14
|
+
# Raised when Instagram returns the HTTP status code 503
|
15
|
+
class ServiceUnavailable < Error; end
|
16
|
+
|
17
|
+
# Raised when a subscription payload hash is invalid
|
18
|
+
class InvalidSignature < Error; end
|
19
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module GamesRadarApi
|
2
|
+
# Defines HTTP request methods
|
3
|
+
module Request
|
4
|
+
# Perform an HTTP GET request
|
5
|
+
def get(path, options={}, raw=false, unformatted=false)
|
6
|
+
request(:get, path, options, raw, unformatted)
|
7
|
+
end
|
8
|
+
|
9
|
+
# Perform an HTTP POST request
|
10
|
+
def post(path, options={}, raw=false, unformatted=false)
|
11
|
+
request(:post, path, options, raw, unformatted)
|
12
|
+
end
|
13
|
+
|
14
|
+
# Perform an HTTP PUT request
|
15
|
+
def put(path, options={}, raw=false, unformatted=false)
|
16
|
+
request(:put, path, options, raw, unformatted)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Perform an HTTP DELETE request
|
20
|
+
def delete(path, options={}, raw=false, unformatted=false)
|
21
|
+
request(:delete, path, options, raw, unformatted)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
# Perform an HTTP request
|
27
|
+
def request(method, path, options, raw=false, unformatted=false)
|
28
|
+
options = options.merge(:api_key=>api_key)
|
29
|
+
options.delete_if { |k, v| v.nil? or v.eql?'' }
|
30
|
+
response = connection(raw).send(method) do |request|
|
31
|
+
case method
|
32
|
+
when :get, :delete
|
33
|
+
request.url(path, options)
|
34
|
+
when :post, :put
|
35
|
+
request.path = path
|
36
|
+
request.body = options unless options.empty?
|
37
|
+
end
|
38
|
+
end
|
39
|
+
raw ? response : response.body
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
require File.expand_path('../../../../spec_helper', __FILE__)
|
3
|
+
|
4
|
+
describe GamesRadarApi::Client::Cheats do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@client = get_client
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'Cheats List' do
|
11
|
+
it 'should have at least one result' do
|
12
|
+
@client.cheats
|
13
|
+
@client.total_rows.must_be :>, 0
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should have a cheat url' do
|
17
|
+
response = @client.cheats
|
18
|
+
response.each do |c|
|
19
|
+
c.url.wont_be_nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'Game Cheats' do
|
26
|
+
it 'should fetch cheats for a specified game' do
|
27
|
+
@client.game_cheats(2008021217411530005)
|
28
|
+
@client.total_rows.must_be :>, 0
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path('../../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe GamesRadarApi::Client::Developers do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = get_client
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'Developers list' do
|
10
|
+
let(:response) { @client.developers }
|
11
|
+
it 'should have at least one result' do
|
12
|
+
response.size.must_be :>, 0
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should return valid developers' do
|
16
|
+
response.first.name.must_equal ' Eyebrow Interactive'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path('../../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe GamesRadarApi::Client::Franchises do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = get_client
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'Franchises list' do
|
10
|
+
let(:response) { @client.franchises }
|
11
|
+
it 'should have at least one result' do
|
12
|
+
response.size.must_be :>, 0
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should return valid franchises' do
|
16
|
+
response.first.name.us.must_equal '.hack'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path('../../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe GamesRadarApi::Client::Games do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = get_client
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'Game List' do
|
10
|
+
it 'should fetch 10 games by default' do
|
11
|
+
response = @client.games
|
12
|
+
response.size.must_equal 10
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should filter by platform' do
|
16
|
+
response = @client.games(:platform=>'ps3')
|
17
|
+
response.each do |g|
|
18
|
+
g.platform.name.must_equal 'PS3'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'Game Detail' do
|
24
|
+
it 'should fetch the correct game' do
|
25
|
+
response = @client.game('16725')
|
26
|
+
response.name.uk.must_equal 'God of War Saga'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should return nil for an invalid game' do
|
30
|
+
response = @client.game('34$')
|
31
|
+
response.must_be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'Game Search' do
|
37
|
+
it 'should fetch relevant games' do
|
38
|
+
response = @client.game_search('Darksiders','xbox360')
|
39
|
+
response.each do |g|
|
40
|
+
g.name.downcase.must_include 'darksiders'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should return nil if no games are found' do
|
45
|
+
response = @client.game_search('Darksdiers','xbox360')
|
46
|
+
response.must_be_nil
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path('../../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe GamesRadarApi::Client::Genres do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = get_client
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'genres list' do
|
10
|
+
it 'should have at least one result' do
|
11
|
+
response = @client.genres
|
12
|
+
response.size.must_be :>, 0
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
require File.expand_path('../../../../spec_helper', __FILE__)
|
3
|
+
|
4
|
+
describe GamesRadarApi::Client::Guides do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@client = get_client
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'Guides and Faqs List' do
|
11
|
+
it 'should have at least one result' do
|
12
|
+
@client.guides
|
13
|
+
@client.total_rows.must_be :>, 0
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should have a cheat url' do
|
17
|
+
response = @client.guides
|
18
|
+
response.each do |c|
|
19
|
+
c.url.wont_be_nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'Game Guides' do
|
26
|
+
it 'should fetch guides for a specified game' do
|
27
|
+
@client.game_guides(8783).size.must_be :>, 0
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require File.expand_path('../../../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe GamesRadarApi::Client::News do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = get_client
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'News list' do
|
10
|
+
it 'should have at least one result' do
|
11
|
+
@client.news
|
12
|
+
@client.total_rows.must_be :>, 0
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe 'Features List' do
|
17
|
+
|
18
|
+
it 'should fetch 10 features by default' do
|
19
|
+
@client.features.size.must_equal 10
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should allow filtering by game name' do
|
23
|
+
response = @client.features(:game_name=>'d')
|
24
|
+
response.each do |f|
|
25
|
+
f.game.name.downcase[0].must_equal 'd'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'Previews List' do
|
32
|
+
|
33
|
+
it 'should fetch some previews by default' do
|
34
|
+
@client.previews.size.must_be :>, 0
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'Reviews List' do
|
40
|
+
|
41
|
+
it 'should fetch some reviews by default' do
|
42
|
+
@client.reviews.size.must_be :>, 0
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'Game News' do
|
49
|
+
it 'should fetch news for a specified game' do
|
50
|
+
@client.game_news(8783)
|
51
|
+
@client.total_rows.must_be :>, 0
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'Game Reviews' do
|
56
|
+
it 'should fetch reviews for a specified game' do
|
57
|
+
@client.game_reviews(8783)
|
58
|
+
@client.total_rows.must_be :>, 0
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe 'Game Previews' do
|
63
|
+
it 'should fetch previews for a specified game' do
|
64
|
+
@client.game_previews(8783)
|
65
|
+
@client.total_rows.must_be :>, 0
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe 'Game Features' do
|
70
|
+
it 'should fetch features for a specified game' do
|
71
|
+
@client.game_features(8783)
|
72
|
+
@client.total_rows.must_be :>, 0
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
end
|