scoreoid 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES.md CHANGED
@@ -1,6 +1,11 @@
1
1
  Scoreoid Ruby Change Log
2
2
  ========================
3
3
 
4
+ 2012-11-25 *v1.1.1*
5
+ -------------------
6
+
7
+ - Fix a issue that occured when parsing API responses where the root node is an array.
8
+
4
9
  2012-11-25 *v1.1.0*
5
10
  -------------------
6
11
 
@@ -35,14 +35,25 @@ module Scoreoid
35
35
  # @param [Hash] params Parameters to include in the API request.
36
36
  #
37
37
  # @raise [Scoreoid::APIError] if the Scoreoid API returns an error response.
38
+ # @raise [MultiJson::DecodeError] if the Scoreoid API response can't be parsed
39
+ # (report a bug if this happens!)
38
40
  #
39
41
  # @return [Hash] The Scoreoid API response parsed into a Hash.
40
42
  #
41
43
  # @see .query
42
44
  def query_and_parse(api_method, params={})
45
+ # We're gonna parse JSON, so ask for JSON
43
46
  params = params.merge(response: 'json')
44
47
 
48
+ # Query Scoreoid
45
49
  api_response = self.query(api_method, params)
50
+
51
+ # Fix for API responses that return arrays (they can't be parsed by MultiJson)
52
+ if api_response =~ /\A\[/ and api_response =~ /\]\Z/
53
+ api_response.sub!(/\A\[/, '') # Remove leading bracket
54
+ api_response.sub!(/\]\Z/, '') # Remove trailing bracket
55
+ end
56
+
46
57
  parsed_result = MultiJson.load(api_response)
47
58
 
48
59
  raise APIError, parsed_result['error'] if parsed_result.key? 'error'
@@ -1,4 +1,4 @@
1
1
  module Scoreoid
2
2
  # The currently loaded Scoreoid Ruby version.
3
- VERSION = '1.1.0'
3
+ VERSION = '1.1.1'
4
4
  end
@@ -66,5 +66,14 @@ describe Scoreoid::API do
66
66
  Scoreoid::API.query_and_parse('getScores')
67
67
  end.to raise_error(Scoreoid::APIError, 'The API key is broken or the game is not active')
68
68
  end
69
+
70
+ it 'should not raise an error if the the response is an array' do
71
+ example_response = %q([{"Player": {"username": "pwner"}}])
72
+ Scoreoid::API.stub(:query).and_return(example_response)
73
+
74
+ expect do
75
+ Scoreoid::API.query_and_parse('getPlayer', username: 'someuser')
76
+ end.to_not raise_error
77
+ end
69
78
  end
70
79
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scoreoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: