games_radar_api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +46 -0
  5. data/Rakefile +9 -0
  6. data/games_radar_api.gemspec +28 -0
  7. data/lib/faraday/raise_http_exception.rb +51 -0
  8. data/lib/games_radar_api.rb +26 -0
  9. data/lib/games_radar_api/api.rb +22 -0
  10. data/lib/games_radar_api/client.rb +18 -0
  11. data/lib/games_radar_api/client/cheats.rb +18 -0
  12. data/lib/games_radar_api/client/developers.rb +9 -0
  13. data/lib/games_radar_api/client/franchises.rb +9 -0
  14. data/lib/games_radar_api/client/games.rb +25 -0
  15. data/lib/games_radar_api/client/genres.rb +9 -0
  16. data/lib/games_radar_api/client/guides.rb +18 -0
  17. data/lib/games_radar_api/client/news.rb +57 -0
  18. data/lib/games_radar_api/client/platforms.rb +9 -0
  19. data/lib/games_radar_api/client/publishers.rb +9 -0
  20. data/lib/games_radar_api/client/screenshots.rb +20 -0
  21. data/lib/games_radar_api/client/videos.rb +18 -0
  22. data/lib/games_radar_api/configuration.rb +51 -0
  23. data/lib/games_radar_api/connection.rb +32 -0
  24. data/lib/games_radar_api/error.rb +19 -0
  25. data/lib/games_radar_api/request.rb +42 -0
  26. data/lib/games_radar_api/version.rb +3 -0
  27. data/spec/lib/games_radar_api/client/cheats_spec.rb +33 -0
  28. data/spec/lib/games_radar_api/client/developers_spec.rb +22 -0
  29. data/spec/lib/games_radar_api/client/franchises_spec.rb +22 -0
  30. data/spec/lib/games_radar_api/client/games_spec.rb +52 -0
  31. data/spec/lib/games_radar_api/client/genres_spec.rb +21 -0
  32. data/spec/lib/games_radar_api/client/guides_spec.rb +31 -0
  33. data/spec/lib/games_radar_api/client/news_spec.rb +77 -0
  34. data/spec/lib/games_radar_api/client/platforms_spec.rb +22 -0
  35. data/spec/lib/games_radar_api/client/publishers_spec.rb +22 -0
  36. data/spec/lib/games_radar_api/client/screenshots_spec.rb +29 -0
  37. data/spec/lib/games_radar_api/client/videos_spec.rb +24 -0
  38. data/spec/lib/games_radar_api/client_spec.rb +59 -0
  39. data/spec/lib/games_radar_api/configuration_spec.rb +26 -0
  40. data/spec/lib/games_radar_api/games_radar_api_spec.rb +7 -0
  41. data/spec/spec_helper.rb +15 -0
  42. metadata +204 -0
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in games_radar_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Ash
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # GamesRadarApi
2
+
3
+ This gem is a fully featured API wrapper for the Games Radar API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'games_radar_api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install games_radar_api
18
+
19
+ ## Configuration
20
+
21
+ You can use a block configuration to specify the API key. e.g.
22
+
23
+ GamesRadarApi.configure do |config|
24
+ config.api_key = "YOUR_CLIENT_ID"
25
+ end
26
+
27
+
28
+ ## Usage
29
+
30
+ To start using the GamesRadarAPI just initialize the client and start requesting. e.g.
31
+
32
+ require 'games_radar_api'
33
+
34
+ client = GamesRadarApi.client(:api_key=>'<YOUR_API_KEY>')
35
+ # search for games called Darksiders on the XBOX 360
36
+ response = client.game_search('Darksiders','xbox360')
37
+
38
+ Each request returns an array of Hashie objects which you can then manipulate in any way that you wish.
39
+
40
+ For a full list of available request methods have a look through the lib/games_radar_api/client directory
41
+
42
+ It's also recommended that you look through the Games Radar API Documentation for a clearer idea of the parameters values which each method accepts http://dl.gamesradar.com/api/GamesRadar_Developer_API_Documentation.pdf
43
+
44
+ ## Credits
45
+
46
+ This gem is created by Cube Websites
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |test|
5
+ test.test_files = FileList['spec/lib/games_radar_api/*_spec.rb','spec/lib/games_radar_api/client/*_spec.rb']
6
+ test.verbose = true
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'games_radar_api/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "games_radar_api"
8
+ gem.version = GamesRadarApi::VERSION
9
+ gem.authors = ["Cube Websites"]
10
+ gem.email = ["mail@cubewebsites.com"]
11
+ gem.description = "Allows interaction with the Games Radar API"
12
+ gem.summary = "This gem is created for developers to easily access all features of the Games Radar API"
13
+ gem.homepage = "https://github.com/cubewebsites/games_radar_api"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_runtime_dependency('faraday_middleware', '~> 0.8')
21
+ gem.add_runtime_dependency('faraday', ['>= 0.7', '< 0.9'])
22
+ gem.add_runtime_dependency('multi_xml', '>= 0.5.1')
23
+ gem.add_runtime_dependency('hashie', '>= 0.4.0')
24
+
25
+ gem.add_development_dependency('turn', '~> 0.9.6')
26
+ gem.add_development_dependency('rake', '~> 0.9.2.2')
27
+
28
+ end
@@ -0,0 +1,51 @@
1
+ require 'faraday'
2
+
3
+ # @private
4
+ module FaradayMiddleware
5
+ # @private
6
+ class RaiseHttpException < Faraday::Middleware
7
+ def call(env)
8
+ @app.call(env).on_complete do |response|
9
+ case response[:status].to_i
10
+ when 400
11
+ raise GamesRadarApi::BadRequest, error_message_400(response)
12
+ when 404
13
+ raise GamesRadarApi::NotFound, error_message_400(response)
14
+ when 500
15
+ raise GamesRadarApi::InternalServerError, error_message_500(response, "Something is technically wrong.")
16
+ when 503
17
+ end
18
+ end
19
+ end
20
+
21
+
22
+ def initialize(app)
23
+ super app
24
+ @parser = nil
25
+ end
26
+
27
+ private
28
+
29
+ def error_message_400(response)
30
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{error_body(response[:body])}"
31
+ end
32
+
33
+ def error_body(body)
34
+ # body gets passed as a string, not sure if it is passed as something else from other spots?
35
+ if not body.nil? and not body.empty? and body.kind_of?(String)
36
+ # removed multi_json thanks to wesnolte's commit
37
+ body = MultiXml.parse(body)
38
+ end
39
+
40
+ if body.nil?
41
+ nil
42
+ elsif body['error'] and body['error']['messages'] and body['error']['messages']['message'] and not body['error']['messages']['message'].empty?
43
+ ": #{body['error']['messages']['message']}"
44
+ end
45
+ end
46
+
47
+ def error_message_500(response, body=nil)
48
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{[response[:status].to_s + ':', body].compact.join(' ')}"
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,26 @@
1
+ Dir[File.dirname(__FILE__) + '/games_radar_api/*.rb'].each do |file|
2
+ require file
3
+ end
4
+
5
+ module GamesRadarApi
6
+ extend Configuration
7
+
8
+ # Alias for GamesRadarApi::Client.new
9
+ #
10
+ # @return [GamesRadarApi::Client]
11
+ def self.client(options={})
12
+ GamesRadarApi::Client.new(options)
13
+ end
14
+
15
+ # Delegate to GamesRadarApi::Client
16
+ def self.method_missing(method, *args, &block)
17
+ return super unless client.respond_to?(method)
18
+ client.send(method, *args, &block)
19
+ end
20
+
21
+ # Delegate to GamesRadarApi::Client
22
+ def self.respond_to?(method)
23
+ return client.respond_to?(method) || super
24
+ end
25
+
26
+ end
@@ -0,0 +1,22 @@
1
+ require File.expand_path('../connection', __FILE__)
2
+ require File.expand_path('../request', __FILE__)
3
+ require File.expand_path('../configuration', __FILE__)
4
+
5
+ module GamesRadarApi
6
+ # @private
7
+ class API
8
+ # @private
9
+ attr_accessor *Configuration::VALID_CONFIG_KEYS + [:total_rows]
10
+
11
+ # Creates a new API
12
+ def initialize(options={})
13
+ options = GamesRadarApi.options.merge(options)
14
+ Configuration::VALID_CONFIG_KEYS.each do |key|
15
+ send("#{key}=", options[key])
16
+ end
17
+ end
18
+
19
+ include Connection
20
+ include Request
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ module GamesRadarApi
2
+ class Client < API
3
+ Dir[File.expand_path('../client/*.rb',__FILE__)].each{ |f| require f }
4
+
5
+ include GamesRadarApi::Client::Cheats
6
+ include GamesRadarApi::Client::Developers
7
+ include GamesRadarApi::Client::Franchises
8
+ include GamesRadarApi::Client::Games
9
+ include GamesRadarApi::Client::Genres
10
+ include GamesRadarApi::Client::Guides
11
+ include GamesRadarApi::Client::News
12
+ include GamesRadarApi::Client::Platforms
13
+ include GamesRadarApi::Client::Publishers
14
+ include GamesRadarApi::Client::Screenshots
15
+ include GamesRadarApi::Client::Videos
16
+
17
+ end # Client
18
+ end
@@ -0,0 +1,18 @@
1
+ module GamesRadarApi
2
+ class Client
3
+ module Cheats
4
+ def cheats(options={:region=>'us',:platform=>'all',:genre=>'all',:game_name=>'',:page_num=>1,:page_size=>10,:sort=>'newest'})
5
+ response = get('/cheats',options)
6
+ self.total_rows = response.cheats.total_rows.to_i
7
+ response.cheats.cheat
8
+ end
9
+
10
+ def game_cheats(id,options={:region=>'us',:page_num=>1,:page_size=>10,:content=>'all_cheat'})
11
+ response = get("/game/cheats/#{id}",options)
12
+ self.total_rows = response.cheats.total_rows.to_i
13
+ response.cheats.cheat
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module GamesRadarApi
2
+ class Client
3
+ module Developers
4
+ def developers
5
+ get('/developers').developers.company
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module GamesRadarApi
2
+ class Client
3
+ module Franchises
4
+ def franchises
5
+ get('/franchises').franchises.franchise
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ module GamesRadarApi
2
+ class Client
3
+ module Games
4
+ def games(options={:platform=>'all',:genre=>'all',:page_num=>1,:page_size=>10,:sort=>'newest'})
5
+ response = get('/games',options)
6
+ self.total_rows = response.games.total_rows.to_i
7
+ response.games.game
8
+ end
9
+
10
+ def game(id)
11
+ response = get("/game/#{id}")
12
+ self.total_rows = response.total_rows.to_i
13
+ return response.game unless response.game.id.nil?
14
+ return nil
15
+ end
16
+
17
+ def game_search(query,platform,options={:region=>'us'})
18
+ response = get("/search/gameName/#{platform}/#{query}",options)
19
+ self.total_rows = response.games.total_rows.to_i
20
+ response.games.game
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ module GamesRadarApi
2
+ class Client
3
+ module Genres
4
+ def genres
5
+ get('/genres').genres.genre
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,18 @@
1
+ module GamesRadarApi
2
+ class Client
3
+ module Guides
4
+ def guides(options={:region=>'us',:platform=>'all',:genre=>'all',:game_name=>'',:page_num=>1,:page_size=>10,:sort=>'newest'})
5
+ response = get('/guidesandfaqs',options)
6
+ self.total_rows = response.cheats.total_rows.to_i
7
+ response.cheats.cheat
8
+ end
9
+
10
+ def game_guides(id,options={:region=>'us',:page_num=>1,:page_size=>10})
11
+ response = get("/game/guidesandfaqs/#{id}",options)
12
+ self.total_rows = response.cheats.total_rows.to_i
13
+ response.cheats.cheat
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,57 @@
1
+ module GamesRadarApi
2
+ class Client
3
+ module News
4
+ puts "NOTE: Tested the News API on 26 September 2012 and it wasn't returning any articles, just a number of rows"
5
+ puts "This module will therefore appear in this gem, but please don't be suprised if it doesn't work"
6
+ def news(options={:region=>'us',:platform=>'all',:genre=>'all',:game_name=>'',:page_num=>1,:page_size=>10,:sort=>'newest'})
7
+ response = get('/news',options)
8
+ self.total_rows = response.articles.total_rows.to_i
9
+ response.articles.article
10
+ end
11
+
12
+ def features(options={:region=>'us',:platform=>'all',:genre=>'all',:game_name=>'',:page_num=>1,:page_size=>10,:sort=>'newest'})
13
+ response = get('/features',options)
14
+ self.total_rows = response.articles.total_rows.to_i
15
+ response.articles.article
16
+ end
17
+
18
+ def previews(options={:region=>'us',:platform=>'all',:genre=>'all',:game_name=>'',:page_num=>1,:page_size=>10,:sort=>'newest'})
19
+ response = get('/previews',options)
20
+ self.total_rows = response.articles.total_rows.to_i
21
+ response.articles.article
22
+ end
23
+
24
+ def reviews(options={:region=>'us',:platform=>'all',:genre=>'all',:game_name=>'',:page_num=>1,:page_size=>10,:sort=>'newest'})
25
+ response = get('/reviews',options)
26
+ self.total_rows = response.articles.total_rows.to_i
27
+ response.articles.article
28
+ end
29
+
30
+
31
+ def game_news(id,options={:region=>'us',:page_num=>1,:page_size=>10})
32
+ response = get("/game/news/#{id}",options)
33
+ self.total_rows = response.articles.total_rows.to_i
34
+ response.articles.article
35
+ end
36
+
37
+ def game_features(id,options={:region=>'us',:page_num=>1,:page_size=>10})
38
+ response = get("/game/features/#{id}",options)
39
+ self.total_rows = response.articles.total_rows.to_i
40
+ response.articles.article
41
+ end
42
+
43
+ def game_previews(id,options={:region=>'us',:page_num=>1,:page_size=>10})
44
+ response = get("/game/previews/#{id}",options)
45
+ self.total_rows = response.articles.total_rows.to_i
46
+ response.articles.article
47
+ end
48
+
49
+ def game_reviews(id,options={:region=>'us',:page_num=>1,:page_size=>10})
50
+ response = get("/game/reviews/#{id}",options)
51
+ self.total_rows = response.articles.total_rows.to_i
52
+ response.articles.article
53
+ end
54
+
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,9 @@
1
+ module GamesRadarApi
2
+ class Client
3
+ module Platforms
4
+ def platforms
5
+ get('/platforms').platforms.platform
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module GamesRadarApi
2
+ class Client
3
+ module Publishers
4
+ def publishers
5
+ get('/publishers').publishers.company
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ module GamesRadarApi
2
+ class Client
3
+ module Screenshots
4
+ def screenshots(options={:region=>'us',:platform=>'all',:genre=>'all',:game_name=>'',:unique_game=>false,:page_num=>1,:page_size=>10,:sort=>'newest'})
5
+ puts "NOTE: Tested the Screenshot API on 26 September 2012 and it wasn't returning any rows"
6
+ puts "This module will therefore appear in this gem, but please don't be suprised if it doesn't work"
7
+ response = get('/screenshots',options)
8
+ self.total_rows = response.screenshots.total_rows.to_i
9
+ response.screenshots.screenshot
10
+ end
11
+
12
+ def game_screenshots(id,options={:region=>'us',:page_num=>1,:page_size=>10})
13
+ response = get("/game/screenshots/#{id}",options)
14
+ self.total_rows = response.screenshots.total_rows.to_i
15
+ response.screenshots.screenshot
16
+ end
17
+
18
+ end
19
+ end
20
+ end