Skip to content

Commit 9c8e24d

Browse files
committed
Adds BnetScraper::InvalidProfileError to ProfileScraper
1 parent 8cdf573 commit 9c8e24d

File tree

5 files changed

+577
-0
lines changed

5 files changed

+577
-0
lines changed

lib/bnet_scraper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
require 'nokogiri'
44

55
module BnetScraper
6+
class InvalidProfileError < Exception ; end
67
end

lib/bnet_scraper/starcraft2/profile_scraper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ def get_profile_data
3838
@race = html.css("#season-snapshot .module-footer a").first().inner_html()
3939
@wins = html.css("#career-stats h2").inner_html()
4040
@achievement_points = html.css("#profile-header h3").inner_html()
41+
else
42+
raise BnetScraper::InvalidProfileError
4143
end
4244
end
4345

@@ -54,6 +56,8 @@ def get_league_list
5456
href: "#{profile_url}ladder/#{league.attr('href')}"
5557
}
5658
end
59+
else
60+
raise BnetScraper::InvalidProfileError
5761
end
5862
end
5963

spec/starcraft2/profile_scraper_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
subject.should_receive(:output)
4646
subject.scrape
4747
end
48+
49+
it 'should return InvalidProfileError if response is 404' do
50+
scraper = BnetScraper::Starcraft2::ProfileScraper.new url: 'http://us.battle.net/sc2/en/profile/2377239/1/SomeDude/'
51+
expect { scraper.scrape }.to raise_error(BnetScraper::InvalidProfileError)
52+
end
4853
end
4954

5055
describe '#output' do

0 commit comments

Comments
 (0)