games_radar 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,8 +35,8 @@ module GamesRadar
35
35
  }.merge(options)
36
36
 
37
37
  request "/games", options do |xml|
38
- total_rows = xml.at("total_rows").inner_text.to_i
39
- items = xml.search("game").collect {|node| new(node) }
38
+ total_rows = xml.at("total_rows").text.to_i
39
+ items = xml.search("game").collect {|node| initialize_with_node node }
40
40
 
41
41
  GamesRadar::Result.new(
42
42
  :items => items,
@@ -50,16 +50,21 @@ module GamesRadar
50
50
  def self.initialize_with_node(xml) # :nodoc:
51
51
  raise GamesRadar::GameNotFoundError unless xml.at("id")
52
52
 
53
- new(
54
- :id => xml.at("id").inner_text,
53
+ # First set up mandatory attributes
54
+ options = {
55
+ :id => xml.at("id").text,
55
56
  :name => {
56
- :us => xml.at("name > us").inner_text,
57
- :uk => xml.at("name > uk").inner_text
57
+ :us => xml.at("name > us").text,
58
+ :uk => xml.at("name > uk").text
58
59
  },
59
- :platform => GamesRadar::Platform.new(xml.at("platform > id").inner_text),
60
- :genre => GamesRadar::Genre.new(xml.at("genre > id").inner_text),
61
- :description => Nokogiri(xml.at("description").inner_text).inner_text
62
- )
60
+ :platform => GamesRadar::Platform.new(xml.at("platform > id").text)
61
+ }
62
+
63
+ # Then set up optional attributes
64
+ options[:genre] = GamesRadar::Genre.new(xml.at("genre > id").text) if xml.at("genre > id")
65
+ options[:description] = Nokogiri(xml.at("description").text).text if xml.at("description")
66
+
67
+ new(options)
63
68
  end
64
69
 
65
70
  # Return a game with the specified id.
@@ -24,6 +24,14 @@ module GamesRadar
24
24
  :filter => :game_name
25
25
  }
26
26
 
27
+ class << self
28
+ # Hold the latest response.
29
+ attr_accessor :response
30
+
31
+ # Hold the latest uri.
32
+ attr_accessor :uri
33
+ end
34
+
27
35
  # Make a API request processing the provided parameters and
28
36
  # merging the API key in every request.
29
37
  #
@@ -33,8 +41,9 @@ module GamesRadar
33
41
  # # do whatever you want with the response XML
34
42
  # end
35
43
  def request(path, params = {}, &block)
36
- uri = uri_for(path, params.dup)
37
- xml = Nokogiri::XML(open(uri).read)
44
+ GamesRadar::Request.uri = uri_for(path, params.dup)
45
+ GamesRadar::Request.response = open(GamesRadar::Request.uri)
46
+ xml = Nokogiri::XML(GamesRadar::Request.response.read)
38
47
 
39
48
  handle_exceptions! xml
40
49
 
@@ -43,7 +52,7 @@ module GamesRadar
43
52
 
44
53
  # Raise exception when XML contains known error codes
45
54
  def handle_exceptions!(xml) # :nodoc:
46
- case xml.search("error > code").inner_text.to_i
55
+ case xml.search("error > code").text.to_i
47
56
  when 10001 then raise GamesRadar::InvalidApiKeyError
48
57
  end
49
58
  end
@@ -2,7 +2,7 @@ module GamesRadar
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- PATCH = 0
5
+ PATCH = 1
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
data/test/request_test.rb CHANGED
@@ -29,4 +29,10 @@ class GamesRadar::GenreTest < Test::Unit::TestCase
29
29
  @request.prepare_params!(options)
30
30
  assert_equal "sport+games", options[:genre]
31
31
  end
32
+
33
+ def test_response_object
34
+ register_uri "/game/20060713144458560042?api_key=SxKuVse22qqUcZXq", "game.xml"
35
+ @request.request("/game/20060713144458560042") do |xml|
36
+ end
37
+ end
32
38
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: games_radar
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-16 00:00:00 -02:00
12
+ date: 2010-02-17 00:00:00 -02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency