Skip to content

Commit d460186

Browse files
committed
Adds BnetScraper::Starcraft2.valid_profile?
1 parent e1c17da commit d460186

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

lib/bnet_scraper/starcraft2.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,15 @@ def self.full_profile_scrape bnet_id, account, region = 'na'
4343
profile_output[:leagues] = parsed_leagues
4444
return profile_output
4545
end
46+
47+
# Determine if Supplied profile is valid. Useful for validating now before an
48+
# async scraping later
49+
#
50+
# @param [Hash] options - account information hash
51+
# @return [TrueClass, FalseClass] valid - whether account is valid
52+
def self.valid_profile? options
53+
scraper = BaseScraper.new(options)
54+
scraper.valid?
55+
end
4656
end
4757
end

lib/bnet_scraper/starcraft2/base_scraper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ def region_info
6161
REGIONS[region]
6262
end
6363

64+
def valid?
65+
result = Faraday.get profile_url
66+
result.success?
67+
end
68+
6469
def scrape
6570
raise NotImplementedError, "Abstract method #scrape called."
6671
end

spec/starcraft2_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,16 @@
2929
actual.should == expected
3030
end
3131
end
32+
33+
describe '#valid_profile?' do
34+
it 'should return true on valid profile' do
35+
result = BnetScraper::Starcraft2.valid_profile? url: 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/'
36+
result.should be_true
37+
end
38+
39+
it 'should return false on invalid profile' do
40+
result = BnetScraper::Starcraft2.valid_profile? url: 'http://us.battle.net/sc2/en/profile/2377239/1/SomeDude/'
41+
result.should be_false
42+
end
43+
end
3244
end

spec/support/shared/sc2_scraper.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,18 @@
6969
subject.profile_url(2).should == 'http://us.battle.net/sc2/en/profile/2377239/2/Demon/'
7070
end
7171
end
72+
73+
describe '#valid?' do
74+
it 'should return true when profile is valid' do
75+
result = subject.valid?
76+
result.should be_true
77+
end
78+
79+
it 'should return false when profile is invalid' do
80+
scraper = scraper_class.new(url: 'http://us.battle.net/sc2/en/profile/2377239/1/SomeDude/')
81+
82+
result = scraper.valid?
83+
result.should be_false
84+
end
85+
end
7286
end

0 commit comments

Comments
 (0)