Skip to content

Commit

Permalink
Merge 712f723 into 2cb441f
Browse files Browse the repository at this point in the history
  • Loading branch information
Arie committed May 18, 2021
2 parents 2cb441f + 712f723 commit 69a25ca
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 21 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Expand Up @@ -2,10 +2,10 @@ language: ruby
cache: bundler
sudo: false
rvm:
- 2.0
- 2.1
- 2.2
- 2.3.1
- 2.6
- 2.7
- 3.0
-
- jruby-head
- ruby-head
matrix:
Expand Down
2 changes: 1 addition & 1 deletion lib/steam-condenser/community/game_leaderboard.rb
Expand Up @@ -197,7 +197,7 @@ def parse_entries
def self.load_leaderboards(app_id)
begin
url = "http://steamcommunity.com/stats/#{app_id}/leaderboards/?xml=1"
boards_data = MultiXml.parse(open(url, proxy: true)).values.first
boards_data = MultiXml.parse(URI.open(url, proxy: true)).values.first
rescue
raise SteamCondenser::Error.new 'XML data could not be parsed.', $!
end
Expand Down
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
7 changes: 2 additions & 5 deletions lib/steam-condenser/community/xml_data.rb
Expand Up @@ -8,23 +8,20 @@
require 'multi_xml'

module SteamCondenser::Community

# This class provides basic functionality to parse XML data
#
# @author Sebastian Staudt
module XMLData

# Parse the given URL as XML data using `multi_xml`
#
# @param [String] url The URL to parse
# @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
rescue StandardError
raise SteamCondenser::Error.new "XML data could not be parsed: #{$!.message}", $!
end

end
end
1 change: 1 addition & 0 deletions steam-condenser.gemspec
Expand Up @@ -15,6 +15,7 @@ Gem::Specification.new do |s|

s.add_dependency 'multi_json', '~> 1.6'
s.add_dependency 'multi_xml', '~> 0.5'
s.add_dependency 'rexml', '~> 3.2'

s.add_development_dependency 'mocha', '~> 1.1'
s.add_development_dependency 'rake', '~> 10.4'
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

0 comments on commit 69a25ca

Please sign in to comment.