Skip to content

Commit 5d0fd1f

Browse files
authored
Merge pull request #28 from Arie/master
Ruby 3.0 compatibility
2 parents 368bf45 + 5fa72ab commit 5d0fd1f

File tree

10 files changed

+38
-21
lines changed

10 files changed

+38
-21
lines changed

.travis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ language: ruby
22
cache: bundler
33
sudo: false
44
rvm:
5-
- 2.0
65
- 2.1
76
- 2.2
8-
- 2.3.1
7+
- 2.3
8+
- 2.6
9+
- 2.7
10+
- 3.0
11+
-
912
- jruby-head
1013
- ruby-head
1114
matrix:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Currently it is implemented in Java, PHP and Ruby.
1212

1313
## Requirements
1414

15-
* Ruby 2.0 or newer (and compatible Ruby VMs)
15+
* Ruby 2.1 or newer (and compatible Ruby VMs)
1616
* Any operating system able to run such a VM
1717

1818
The following gems are required:

lib/steam-condenser/community/game_leaderboard.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
require 'multi_xml'
77

8+
require 'steam-condenser/community/uri'
89
require 'steam-condenser/community/game_leaderboard_entry'
910
require 'steam-condenser/community/steam_id'
1011
require 'steam-condenser/community/xml_data'
@@ -197,7 +198,7 @@ def parse_entries
197198
def self.load_leaderboards(app_id)
198199
begin
199200
url = "http://steamcommunity.com/stats/#{app_id}/leaderboards/?xml=1"
200-
boards_data = MultiXml.parse(open(url, proxy: true)).values.first
201+
boards_data = MultiXml.parse(URI.open(url, proxy: true)).values.first
201202
rescue
202203
raise SteamCondenser::Error.new 'XML data could not be parsed.', $!
203204
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require 'open-uri'
2+
3+
module SteamCondenser::Community
4+
module URI
5+
if RUBY_VERSION >= '2.7.0'
6+
def self.open(*args)
7+
::URI.open(*args)
8+
end
9+
else
10+
def self.open(*args)
11+
Kernel.open(*args)
12+
end
13+
end
14+
end
15+
end

lib/steam-condenser/community/web_api.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Copyright (c) 2010-2015, Sebastian Staudt
55

66
require 'multi_json'
7-
require 'open-uri'
7+
require 'steam-condenser/community/uri'
88

99
require 'steam-condenser/error/web_api'
1010

@@ -132,7 +132,7 @@ def self.get(format, interface, method, version = 1, params = {})
132132
debug_url = @@api_key.nil? ? url : url.gsub(@@api_key, 'SECRET')
133133
log.debug "Querying Steam Web API: #{debug_url}"
134134
end
135-
open(url, { 'Content-Type' => 'application/x-www-form-urlencoded' , proxy: true }).read
135+
URI.open(url, { 'Content-Type' => 'application/x-www-form-urlencoded' , proxy: true }).read
136136
rescue OpenURI::HTTPError
137137
status = $!.io.status[0]
138138
status = [status, ''] unless status.is_a? Array

lib/steam-condenser/community/xml_data.rb

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,20 @@
88
require 'multi_xml'
99

1010
module SteamCondenser::Community
11-
1211
# This class provides basic functionality to parse XML data
1312
#
1413
# @author Sebastian Staudt
1514
module XMLData
16-
1715
# Parse the given URL as XML data using `multi_xml`
1816
#
1917
# @param [String] url The URL to parse
2018
# @return [Hash<String, Object>] The data parsed from the XML document
2119
# @raise [Error] if an error occurs while parsing the XML data
2220
def parse(url)
23-
data = open url, proxy: true
21+
data = URI.open url, proxy: true
2422
@xml_data = MultiXml.parse(data).values.first
25-
rescue
23+
rescue StandardError
2624
raise SteamCondenser::Error.new "XML data could not be parsed: #{$!.message}", $!
2725
end
28-
2926
end
3027
end

steam-condenser.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Gem::Specification.new do |s|
1515

1616
s.add_dependency 'multi_json', '~> 1.6'
1717
s.add_dependency 'multi_xml', '~> 0.5'
18+
s.add_dependency 'rexml', '~> 3.2'
1819

1920
s.add_development_dependency 'mocha', '~> 1.1'
2021
s.add_development_dependency 'rake', '~> 10.4'

test/steam-condenser/community/test_steam_group.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class TestSteamGroup < Test::Unit::TestCase
3131

3232
should 'be able to fetch its members and properties' do
3333
url = fixture_io 'valve-members.xml'
34-
Community::SteamGroup.any_instance.expects(:open).with('http://steamcommunity.com/gid/103582791429521412/memberslistxml?p=1', proxy: true).returns url
34+
Community::URI.expects(:open).with('http://steamcommunity.com/gid/103582791429521412/memberslistxml?p=1', proxy: true).returns url
3535

3636
group = Community::SteamGroup.new 103582791429521412
3737
members = group.members
@@ -69,7 +69,7 @@ class TestSteamGroup < Test::Unit::TestCase
6969
should 'raise an exception when parsing invalid XML' do
7070
error = assert_raises Error do
7171
url = fixture_io 'invalid.xml'
72-
Community::SteamGroup.any_instance.expects(:open).with('http://steamcommunity.com/groups/valve/memberslistxml?p=1', proxy: true).returns url
72+
Community::URI.expects(:open).with('http://steamcommunity.com/groups/valve/memberslistxml?p=1', proxy: true).returns url
7373

7474
Community::SteamGroup.new 'valve'
7575
end
@@ -78,7 +78,7 @@ class TestSteamGroup < Test::Unit::TestCase
7878

7979
should 'be able to parse just the member count' do
8080
url = fixture_io 'valve-members.xml'
81-
Community::SteamGroup.any_instance.expects(:open).with('http://steamcommunity.com/groups/valve/memberslistxml?p=1', proxy: true).returns url
81+
Community::URI.expects(:open).with('http://steamcommunity.com/groups/valve/memberslistxml?p=1', proxy: true).returns url
8282

8383
group = Community::SteamGroup.new 'valve', false
8484
assert_equal 239, group.member_count

test/steam-condenser/community/test_steam_id.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class TestSteamId < Test::Unit::TestCase
8787

8888
should 'be able to fetch its data' do
8989
url = fixture_io 'sonofthor.xml'
90-
Community::SteamId.any_instance.expects(:open).with('http://steamcommunity.com/id/son_of_thor?xml=1', proxy: true).returns url
90+
Community::URI.expects(:open).with('http://steamcommunity.com/id/son_of_thor?xml=1', proxy: true).returns url
9191

9292
steam_id = Community::SteamId.new 'Son_of_Thor'
9393

@@ -157,7 +157,7 @@ class TestSteamId < Test::Unit::TestCase
157157
should 'raise an exception when parsing invalid XML' do
158158
error = assert_raises Error do
159159
url = fixture_io 'invalid.xml'
160-
Community::SteamId.any_instance.expects(:open).with('http://steamcommunity.com/id/son_of_thor?xml=1', proxy: true).returns url
160+
Community::URI.expects(:open).with('http://steamcommunity.com/id/son_of_thor?xml=1', proxy: true).returns url
161161

162162
Community::SteamId.new 'Son_of_Thor'
163163
end

test/steam-condenser/community/test_web_api.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class TestWebApi < Test::Unit::TestCase
5959

6060
should 'load data from the Steam Community Web API' do
6161
data = mock read: 'data'
62-
Community::WebApi.expects(:open).with do |url, options|
62+
Community::URI.expects(:open).with do |url, options|
6363
options == { proxy: true, 'Content-Type' => 'application/x-www-form-urlencoded' } &&
6464
url.start_with?('https://api.steampowered.com/interface/method/v2/?') &&
6565
(url.split('?').last.split('&') & %w{test=param format=json key=0123456789ABCDEF0123456789ABCDEF}).size == 3
@@ -72,7 +72,7 @@ class TestWebApi < Test::Unit::TestCase
7272
Community::WebApi.api_key = nil
7373

7474
data = mock read: 'data'
75-
Community::WebApi.expects(:open).with do |url, options|
75+
Community::URI.expects(:open).with do |url, options|
7676
options == { proxy: true, 'Content-Type' => 'application/x-www-form-urlencoded' } &&
7777
url.start_with?('https://api.steampowered.com/interface/method/v2/?') &&
7878
(url.split('?').last.split('&') & %w{test=param format=json}).size == 2
@@ -84,7 +84,7 @@ class TestWebApi < Test::Unit::TestCase
8484
should 'handle unauthorized access error when loading data' do
8585
io = mock status: [401]
8686
http_error = OpenURI::HTTPError.new '', io
87-
Community::WebApi.expects(:open).raises http_error
87+
Community::URI.expects(:open).raises http_error
8888

8989
error = assert_raises Error::WebApi do
9090
Community::WebApi.get :json, 'interface', 'method', 2, test: 'param'
@@ -95,7 +95,7 @@ class TestWebApi < Test::Unit::TestCase
9595
should 'handle generic HTTP errors when loading data' do
9696
io = mock status: [[404, 'Not found']]
9797
http_error = OpenURI::HTTPError.new '', io
98-
Community::WebApi.expects(:open).raises http_error
98+
Community::URI.expects(:open).raises http_error
9999

100100
error = assert_raises Error::WebApi do
101101
Community::WebApi.get :json, 'interface', 'method', 2, test: 'param'
@@ -107,7 +107,7 @@ class TestWebApi < Test::Unit::TestCase
107107
Community::WebApi.secure = false
108108

109109
data = mock read: 'data'
110-
Community::WebApi.expects(:open).with do |url, options|
110+
Community::URI.expects(:open).with do |url, options|
111111
options == { proxy: true, 'Content-Type' => 'application/x-www-form-urlencoded' } &&
112112
url.start_with?('http://api.steampowered.com/interface/method/v2/?') &&
113113
(url.split('?').last.split('&') & %w{test=param format=json key=0123456789ABCDEF0123456789ABCDEF}).size == 3

0 commit comments

Comments
 (0)