Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecated usage of Kernel#open to open URIs #27

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/steam-condenser/community/web_api.rb
Expand Up @@ -132,7 +132,7 @@ def self.get(format, interface, method, version = 1, params = {})
debug_url = @@api_key.nil? ? url : url.gsub(@@api_key, 'SECRET')
log.debug "Querying Steam Web API: #{debug_url}"
end
open(url, { 'Content-Type' => 'application/x-www-form-urlencoded' , proxy: true }).read
URI.open(url, { 'Content-Type' => 'application/x-www-form-urlencoded' , proxy: true }).read
rescue OpenURI::HTTPError
status = $!.io.status[0]
status = [status, ''] unless status.is_a? Array
Expand Down
2 changes: 1 addition & 1 deletion lib/steam-condenser/community/xml_data.rb
Expand Up @@ -20,7 +20,7 @@ module XMLData
# @return [Hash<String, Object>] The data parsed from the XML document
# @raise [Error] if an error occurs while parsing the XML data
def parse(url)
data = open url, proxy: true
data = URI.open(url, proxy: true)
@xml_data = MultiXml.parse(data).values.first
rescue
raise SteamCondenser::Error.new "XML data could not be parsed: #{$!.message}", $!
Expand Down
6 changes: 3 additions & 3 deletions test/steam-condenser/community/test_steam_group.rb
Expand Up @@ -31,7 +31,7 @@ class TestSteamGroup < Test::Unit::TestCase

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

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

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

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

group = Community::SteamGroup.new 'valve', false
assert_equal 239, group.member_count
Expand Down
4 changes: 2 additions & 2 deletions test/steam-condenser/community/test_steam_id.rb
Expand Up @@ -87,7 +87,7 @@ class TestSteamId < Test::Unit::TestCase

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

steam_id = Community::SteamId.new 'Son_of_Thor'

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

Community::SteamId.new 'Son_of_Thor'
end
Expand Down
10 changes: 5 additions & 5 deletions test/steam-condenser/community/test_web_api.rb
Expand Up @@ -59,7 +59,7 @@ class TestWebApi < Test::Unit::TestCase

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

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

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

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

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