bnet_scraper 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ # Changelog!
2
+
3
+ ## 0.1.0 (Jul 06 2012)
4
+
5
+ * Replaces open-uri with Faraday
6
+ * Adds BnetScraper::InvalidProfileError when unsuccessfully scraping
7
+
8
+ ## 0.2.0 (Apr 20 2012)
9
+
10
+ * Adds Battle.net Status API
11
+ * Adds Match History scraping
12
+ * Adds Achievement scraping
13
+ * Documentation Improvements
14
+ * Adds Travis-CI Support
15
+
16
+ ## 0.1.0 (Mar 13 2012)
17
+
18
+ * Initial Release
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "bnet_scraper"
6
- s.version = "0.0.2"
6
+ s.version = "0.1.0"
7
7
  s.authors = ["Andrew Nordman"]
8
8
  s.email = ["anordman@majorleaguegaming.com"]
9
9
  s.homepage = "https://github.com/agoragames/bnet_scraper/"
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.require_paths = ["lib"]
17
17
 
18
18
  s.add_runtime_dependency 'nokogiri'
19
+ s.add_runtime_dependency 'faraday'
19
20
  s.add_development_dependency 'rake'
20
21
  s.add_development_dependency 'rspec'
21
22
  s.add_development_dependency 'fakeweb'
@@ -1,7 +1,7 @@
1
1
  require 'bnet_scraper/starcraft2'
2
- require 'net/http'
3
- require 'open-uri'
2
+ require 'faraday'
4
3
  require 'nokogiri'
5
4
 
6
5
  module BnetScraper
6
+ class InvalidProfileError < Exception ; end
7
7
  end
@@ -43,7 +43,12 @@ module BnetScraper
43
43
 
44
44
  # retrieves the account's achievements overview page HTML for scraping
45
45
  def get_response
46
- @response = Nokogiri::HTML(open(profile_url+"achievements/"))
46
+ response = Faraday.get "#{profile_url}achievements/"
47
+ if response.success?
48
+ @response = Nokogiri::HTML(response.body)
49
+ else
50
+ raise BnetScraper::InvalidProfileError
51
+ end
47
52
  end
48
53
 
49
54
  # scrapes the recent achievements from the account's achievements overview page
@@ -30,15 +30,20 @@ module BnetScraper
30
30
  end
31
31
 
32
32
  def scrape
33
- @response = Nokogiri::HTML(open(@url))
34
- value = @response.css(".data-title .data-label h3").inner_text().strip
35
- header_regex = /Season (\d{1}) - \s+(\dv\d)( Random)? (\w+)\s+Division (.+)/
36
- header_values = value.match(header_regex).to_a
37
- header_values.shift()
38
- @season, @size, @random, @division, @name = header_values
39
-
40
- @random = !@random.nil?
41
- output
33
+ @response = Faraday.get @url
34
+ if @response.success?
35
+ @response = Nokogiri::HTML(@response.body)
36
+ value = @response.css(".data-title .data-label h3").inner_text().strip
37
+ header_regex = /Season (\d{1}) - \s+(\dv\d)( Random)? (\w+)\s+Division (.+)/
38
+ header_values = value.match(header_regex).to_a
39
+ header_values.shift()
40
+ @season, @size, @random, @division, @name = header_values
41
+
42
+ @random = !@random.nil?
43
+ output
44
+ else
45
+ raise BnetScraper::InvalidProfileError
46
+ end
42
47
  end
43
48
 
44
49
  def output
@@ -25,7 +25,13 @@ module BnetScraper
25
25
 
26
26
  # retrieves the match history HTML for scraping
27
27
  def get_response
28
- @response = Nokogiri::HTML(open(match_url))
28
+ @response = Faraday.get match_url
29
+
30
+ if @response.success?
31
+ @response = Nokogiri::HTML(@response.body)
32
+ else
33
+ raise BnetScraper::InvalidProfileError
34
+ end
29
35
  end
30
36
 
31
37
  def scrape
@@ -30,23 +30,34 @@ module BnetScraper
30
30
 
31
31
  # scrapes the profile page for basic account information
32
32
  def get_profile_data
33
- response = Nokogiri::HTML(open(profile_url))
33
+ response = Faraday.get profile_url
34
34
 
35
- @race = response.css("#season-snapshot .module-footer a").first().inner_html()
36
- @wins = response.css("#career-stats h2").inner_html()
37
- @achievement_points = response.css("#profile-header h3").inner_html()
35
+ if response.success?
36
+ html = Nokogiri::HTML(response.body)
37
+
38
+ @race = html.css("#season-snapshot .module-footer a").first().inner_html()
39
+ @wins = html.css("#career-stats h2").inner_html()
40
+ @achievement_points = html.css("#profile-header h3").inner_html()
41
+ else
42
+ raise BnetScraper::InvalidProfileError
43
+ end
38
44
  end
39
45
 
40
46
  # scrapes the league list from account's league page and sets an array of URLs
41
47
  def get_league_list
42
- response = Nokogiri::HTML(open(profile_url + "ladder/leagues"))
48
+ response = Faraday.get profile_url + "ladder/leagues"
49
+ if response.success?
50
+ html = Nokogiri::HTML(response.body)
43
51
 
44
- @leagues = response.css("a[href*='#current-rank']").map do |league|
45
- {
46
- name: league.inner_html().strip,
47
- id: league.attr('href').sub('#current-rank',''),
48
- href: "#{profile_url}ladder/#{league.attr('href')}"
49
- }
52
+ @leagues = html.css("a[href*='#current-rank']").map do |league|
53
+ {
54
+ name: league.inner_html().strip,
55
+ id: league.attr('href').sub('#current-rank',''),
56
+ href: "#{profile_url}ladder/#{league.attr('href')}"
57
+ }
58
+ end
59
+ else
60
+ raise BnetScraper::InvalidProfileError
50
61
  end
51
62
  end
52
63
 
@@ -17,7 +17,8 @@ module BnetScraper
17
17
  class << self
18
18
 
19
19
  def fetch
20
- Nokogiri::HTML(open(SOURCE))
20
+ response = Faraday.get SOURCE
21
+ Nokogiri::HTML(response.body)
21
22
  .css('.forumPost').first.css('span').to_a
22
23
  .each_slice(2).map { |i| { :region => i.first.text, :status => i.last.text } }
23
24
  end
@@ -25,6 +25,12 @@ describe BnetScraper::Starcraft2::AchievementScraper do
25
25
  subject.should_receive(:scrape_showcase)
26
26
  subject.scrape
27
27
  end
28
+
29
+ it 'should return InvalidProfileError if response is 404' do
30
+ url = 'http://us.battle.net/sc2/en/profile/2377239/1/SomeDude/achievements/'
31
+ scraper = BnetScraper::Starcraft2::AchievementScraper.new(url: url)
32
+ expect { scraper.scrape }.to raise_error(BnetScraper::InvalidProfileError)
33
+ end
28
34
  end
29
35
 
30
36
  describe '#scrape_showcase' do
@@ -50,6 +50,12 @@ describe BnetScraper::Starcraft2::LeagueScraper do
50
50
  subject.should_receive(:output)
51
51
  subject.scrape
52
52
  end
53
+
54
+ it 'should raise InvalidProfileError when response is 404' do
55
+ url = 'http://us.battle.net/sc2/en/profile/2377239/1/SomeDude/leagues/12345'
56
+ scraper = BnetScraper::Starcraft2::LeagueScraper.new(url: url)
57
+ expect { scraper.scrape }.to raise_error(BnetScraper::InvalidProfileError)
58
+ end
53
59
  end
54
60
 
55
61
  describe '#output' do
@@ -34,6 +34,12 @@ describe BnetScraper::Starcraft2::MatchHistoryScraper do
34
34
  it 'should set the match date of each match' do
35
35
  subject.matches[0][:date].should == '3/12/2012'
36
36
  end
37
+
38
+ it 'should raised InvalidProfileError when response is 404' do
39
+ url = 'http://us.battle.net/sc2/en/profile/2377239/1/SomeDude/matches'
40
+ scraper = BnetScraper::Starcraft2::MatchHistoryScraper.new(url: url)
41
+ expect { scraper.scrape }.to raise_error(BnetScraper::InvalidProfileError)
42
+ end
37
43
  end
38
44
 
39
45
  describe '#output' do
@@ -45,6 +45,11 @@ describe BnetScraper::Starcraft2::ProfileScraper do
45
45
  subject.should_receive(:output)
46
46
  subject.scrape
47
47
  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
48
53
  end
49
54
 
50
55
  describe '#output' do
@@ -0,0 +1,565 @@
1
+
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-us" class="en-us">
3
+ <head xmlns:og="http://ogp.me/ns#" xmlns:fb="http://ogp.me/ns/fb#">
4
+ <title>Error - StarCraft II</title>
5
+ <meta content="false" http-equiv="imagetoolbar" />
6
+ <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible" />
7
+ <link rel="shortcut icon" href="/sc2/static/local-common/images/favicons/sc2.ico" type="image/x-icon"/>
8
+ <link rel="search" type="application/opensearchdescription+xml" href="http://us.battle.net/en-us/data/opensearch" title="Battle.net Search" />
9
+ <link rel="stylesheet" type="text/css" media="all" href="/sc2/static/local-common/css/common.css?v42" />
10
+ <!--[if IE]> <link rel="stylesheet" type="text/css" media="all" href="/sc2/static/local-common/css/common-ie.css?v42" />
11
+ <![endif]-->
12
+ <!--[if IE 6]> <link rel="stylesheet" type="text/css" media="all" href="/sc2/static/local-common/css/common-ie6.css?v42" />
13
+ <![endif]-->
14
+ <!--[if IE 7]> <link rel="stylesheet" type="text/css" media="all" href="/sc2/static/local-common/css/common-ie7.css?v42" />
15
+ <![endif]-->
16
+ <link title="StarCraft II™ - News" href="/sc2/en/feed/news" type="application/atom+xml" rel="alternate"/>
17
+ <link rel="stylesheet" type="text/css" media="all" href="/sc2/static/css/sc2.css?v21" />
18
+ <!--[if IE]> <link rel="stylesheet" type="text/css" media="all" href="/sc2/static/css/sc2-ie.css?v21" />
19
+ <![endif]-->
20
+ <!--[if IE 6]> <link rel="stylesheet" type="text/css" media="all" href="/sc2/static/css/sc2-ie6.css?v21" />
21
+ <![endif]-->
22
+ <!--[if IE 7]> <link rel="stylesheet" type="text/css" media="all" href="/sc2/static/css/sc2-ie7.css?v21" />
23
+ <![endif]-->
24
+ <script type="text/javascript" src="/sc2/static/local-common/js/third-party/jquery.js?v42"></script>
25
+ <script type="text/javascript" src="/sc2/static/local-common/js/core.js?v42"></script>
26
+ <script type="text/javascript" src="/sc2/static/local-common/js/tooltip.js?v42"></script>
27
+ <!--[if IE 6]> <script type="text/javascript">
28
+ //<![CDATA[
29
+ try { document.execCommand('BackgroundImageCache', false, true) } catch(e) {}
30
+ //]]>
31
+ </script>
32
+ <![endif]-->
33
+ <script type="text/javascript">
34
+ //<![CDATA[
35
+ Core.staticUrl = '/sc2/static';
36
+ Core.sharedStaticUrl= '/sc2/static/local-common';
37
+ Core.baseUrl = '/sc2/en';
38
+ Core.projectUrl = '/sc2';
39
+ Core.cdnUrl = 'http://us.media.blizzard.com';
40
+ Core.supportUrl = 'http://us.battle.net/support/';
41
+ Core.secureSupportUrl= 'https://us.battle.net/support/';
42
+ Core.project = 'sc2';
43
+ Core.locale = 'en-us';
44
+ Core.language = 'en';
45
+ Core.buildRegion = 'us';
46
+ Core.region = 'us';
47
+ Core.shortDateFormat= 'MM/dd/yyyy';
48
+ Core.dateTimeFormat = 'MM/dd/yyyy hh:mm a';
49
+ Core.loggedIn = false;
50
+ Flash.videoPlayer = 'http://us.media.blizzard.com/global-video-player/themes/sc2/video-player.swf';
51
+ Flash.videoBase = 'http://us.media.blizzard.com/sc2/media/videos';
52
+ Flash.ratingImage = 'http://us.media.blizzard.com/global-video-player/ratings/sc2/en-us.jpg';
53
+ Flash.expressInstall= 'http://us.media.blizzard.com/global-video-player/expressInstall.swf';
54
+ var _gaq = _gaq || [];
55
+ _gaq.push(['_setAccount', 'UA-544112-16']);
56
+ _gaq.push(['_setDomainName', '.battle.net']);
57
+ _gaq.push(['_setAllowLinker', true]);
58
+ _gaq.push(['_trackPageview']);
59
+ _gaq.push(['_trackPageLoadTime']);
60
+ //]]>
61
+ </script>
62
+ <meta property="og:site_name" content="StarCraft II™" />
63
+ <meta property="og:title" content="StarCraft II" />
64
+ <meta property="og:image" content="http://us.media.blizzard.com/battle.net/logos/og-sc2.png" />
65
+ <meta property="og:url" content="http://us.battle.net/sc2/en/profile/2377239/1/SomeDude/?error=404" />
66
+ <meta property="og:type" content="website" />
67
+ <meta property="og:locale" content="en_US" />
68
+ <meta property="fb:admins" content="470332842321,433163104416"/>
69
+ </head>
70
+ <body class=""><div id="wrapper">
71
+ <div id="header">
72
+ <div class="search-bar">
73
+ <form action="/sc2/en/search" method="get" autocomplete="off">
74
+ <div>
75
+ <input type="text" class="search-field input" name="q" id="search-field" maxlength="200" tabindex="40" alt="Search StarCraft II" value="Search StarCraft II" />
76
+ <input type="submit" class="search-button" value="" tabindex="41" />
77
+ </div>
78
+ </form>
79
+ </div>
80
+ <h1 id="logo"><a href="/sc2/en/">Battle.net</a></h1>
81
+ <div id="header-plate">
82
+ <ul class="menu" id="menu">
83
+ <li class="menu-home">
84
+ <a href="/sc2/en/">
85
+ <span>Home</span>
86
+ </a>
87
+ </li>
88
+ <li class="menu-game">
89
+ <a href="/sc2/en/game/">
90
+ <span>Game Guide</span>
91
+ </a>
92
+ </li>
93
+ <li class="menu-esports">
94
+ <a href="/sc2/en/esports/">
95
+ <span>eSports</span>
96
+ </a>
97
+ </li>
98
+ <li class="menu-media">
99
+ <a href="/sc2/en/media/">
100
+ <span>Media</span>
101
+ </a>
102
+ </li>
103
+ <li class="menu-forums">
104
+ <a href="/sc2/en/forum/">
105
+ <span>Forums</span>
106
+ </a>
107
+ </li>
108
+ <li class="menu-buy-now">
109
+ <a href="/sc2/en/buy-now/">
110
+ <span>Buy Now</span>
111
+ </a>
112
+ </li>
113
+ </ul>
114
+ <div id="user-plate" class="ajax-update">
115
+ <div id="user-empty">
116
+ <a href="?login" onclick="return Login.open('https://us.battle.net/login/login.frag')"><strong>Log in</strong></a> with your Battle.net account to post comments and personalize your site content.
117
+ </div>
118
+ </div>
119
+ <ol class="ui-breadcrumb">
120
+ <li class="last">
121
+ <a href="/sc2/en/" rel="np">
122
+ StarCraft II
123
+ </a>
124
+ </li>
125
+ </ol>
126
+ </div>
127
+ </div>
128
+ <div id="content">
129
+ <div id="content-top">
130
+ <div id="content-bot"> <div class="error-page">
131
+
132
+ <div class="warning-graphic"></div>
133
+
134
+ <div class="error-header">Page Not Found</div>
135
+ <div class="divider"></div>
136
+ <div class="error-desc">The page you were looking for either doesn’t exist or some terrible, terrible error has occurred.</div>
137
+
138
+
139
+ </div>
140
+ </div>
141
+ </div>
142
+ </div>
143
+ <div id="footer">
144
+ <div id="sitemap" class="promotions">
145
+ <div class="column">
146
+ <h3 class="bnet">
147
+ <a href="http://us.battle.net/" tabindex="100">Battle.net Home</a>
148
+ </h3>
149
+ <ul>
150
+ <li><a href="http://us.battle.net/what-is/">What is Battle.net?</a></li>
151
+ <li><a href="https://us.battle.net/account/management/get-a-game.html">Buy Games</a></li>
152
+ <li><a href="https://us.battle.net/account/management/">Account</a></li>
153
+ <li><a href="http://us.battle.net/support/">Support</a></li>
154
+ <li><a href="http://us.battle.net/realid/">Real ID</a></li>
155
+ <li><a href="http://us.battle.net/battletag/">BattleTag</a></li>
156
+ </ul>
157
+ </div>
158
+ <div class="column">
159
+ <h3 class="games">
160
+ <a href="http://us.battle.net/" tabindex="100">Games</a>
161
+ </h3>
162
+ <ul>
163
+ <li><a href="http://us.battle.net/sc2/">StarCraft II™</a></li>
164
+ <li><a href="http://us.battle.net/wow/">World of Warcraft™</a></li>
165
+ <li><a href="http://us.battle.net/d3/">Diablo III™</a></li>
166
+ <li><a href="http://us.battle.net/games/classic">Classic Games</a></li>
167
+ <li><a href="https://us.battle.net/account/download/">Game Client Downloads</a></li>
168
+ </ul>
169
+ </div>
170
+ <div class="column">
171
+ <h3 class="account">
172
+ <a href="https://us.battle.net/account/management/" tabindex="100">Account</a>
173
+ </h3>
174
+ <ul>
175
+ <li><a href="https://us.battle.net/account/support/login-support.html">Can’t log in?</a></li>
176
+ <li><a href="https://us.battle.net/account/creation/tos.html">Create Account</a></li>
177
+ <li><a href="https://us.battle.net/account/management/">Account Summary</a></li>
178
+ <li><a href="https://us.battle.net/account/management/authenticator.html">Account Security</a></li>
179
+ <li><a href="https://us.battle.net/account/management/add-game.html">Add a Game</a></li>
180
+ <li><a href="https://us.battle.net/account/management/redemption/redeem.html">Redeem Promo Codes</a></li>
181
+ </ul>
182
+ </div>
183
+ <div class="column">
184
+ <h3 class="support">
185
+ <a href="http://us.battle.net/support/" tabindex="100">Support</a>
186
+ </h3>
187
+ <ul>
188
+ <li><a href="http://us.battle.net/support/">Support Articles</a></li>
189
+ <li><a href="https://us.battle.net/account/parental-controls/index.html">Parental Controls</a></li>
190
+ <li><a href="http://us.battle.net/security/">Protect Your Account</a></li>
191
+ <li><a href="http://us.battle.net/security/help">Help! I got hacked!</a></li>
192
+ </ul>
193
+ </div>
194
+ <div id="footer-promotions">
195
+ <div class="sidebar-content"></div>
196
+ <div id="sidebar-marketing" class="sidebar-module">
197
+ <div class="bnet-offer">
198
+ <!-- -->
199
+ <div class="bnet-offer-bg">
200
+ <a href="https://us.battle.net/account/activation/landing.html?product=S2&amp;key&amp;purchase" target="_blank" id="ad5207109" class="bnet-offer-image" onclick="BnetAds.trackEvent('5207109', 'SCIIdig', 'sc2', true);">
201
+ <img src="http://us.media2.battle.net/cms/ad_300x100/ZNB918LXVJ251309281567042.jpg" width="300" height="100" alt=""/>
202
+ </a>
203
+ </div>
204
+ <script type="text/javascript">
205
+ //<![CDATA[
206
+ if(typeof (BnetAds.addEvent) != "undefined" )
207
+ BnetAds.addEvent(window, 'load', function(){ BnetAds.trackEvent('5207109', 'SCIIdig', 'sc2'); } );
208
+ else
209
+ BnetAds.trackEvent('5207109', 'SCIIdig', 'sc2');
210
+ //]]>
211
+ </script>
212
+ </div>
213
+ </div>
214
+ </div>
215
+ <span class="clear"><!-- --></span>
216
+ </div>
217
+ <div id="copyright">
218
+ <a href="javascript:;" tabindex="100" id="change-language">
219
+ <span>Americas - English (US)</span>
220
+ </a>
221
+ <span>©2012 Blizzard Entertainment, Inc. All rights reserved</span>
222
+ <a onclick="return Core.open(this);" href="http://us.blizzard.com/company/about/termsofuse.html" tabindex="100">Terms of Use</a>
223
+ <a onclick="return Core.open(this);" href="http://us.blizzard.com/company/legal/" tabindex="100">Legal</a>
224
+ <a onclick="return Core.open(this);" href="http://us.blizzard.com/company/about/privacy.html" tabindex="100">Privacy Policy</a>
225
+ <a onclick="return Core.open(this);" href="http://us.blizzard.com/company/about/infringementnotice.html" tabindex="100">Copyright Infringement</a>
226
+ </div>
227
+ <div id="international"></div>
228
+ <div id="legal">
229
+ <div id="legal-ratings" class="png-fix">
230
+ <a class="truste-link" href="//privacy-policy.truste.com/click-with-confidence/ctv/en/us.battle.net/seal_m" target="_blank">
231
+ <img class="legal-image" src="//privacy-policy.truste.com/certified-seal/wps/en/us.battle.net/seal_m.png" alt="Validate TRUSTe privacy certification"/>
232
+ </a>
233
+ <a href="http://www.esrb.org/ratings/ratings_guide.jsp" onclick="return Core.open(this);">
234
+ <img class="legal-image" alt="" src="/sc2/static/local-common/images/legal/us/esrb-teen-sc2.png" />
235
+ </a>
236
+ </div>
237
+ <div id="blizzard" class="png-fix">
238
+ <a href="http://blizzard.com" tabindex="100"><img src="/sc2/static/local-common/images/logos/blizz-sc2.png" alt="" /></a>
239
+ </div>
240
+ <span class="clear"><!-- --></span>
241
+ </div>
242
+ </div>
243
+ <div id="service">
244
+ <ul class="service-bar">
245
+ <li class="service-cell service-home"><a href="http://us.battle.net/" tabindex="50" accesskey="1" title="Battle.net Home"> </a></li>
246
+ <li class="service-cell service-welcome">
247
+ <a href="?login" onclick="return Login.open()">Log in</a> or <a href="https://us.battle.net/account/creation/tos.html">Create an Account</a>
248
+ </li>
249
+ <li class="service-cell service-account"><a href="https://us.battle.net/account/management/" class="service-link" tabindex="50" accesskey="3">Account</a></li>
250
+ <li class="service-cell service-support service-support-enhanced">
251
+ <a href="#support" class="service-link service-link-dropdown" tabindex="50" accesskey="4" id="support-link" onclick="return false" style="cursor: progress" rel="javascript">Support<span class="no-support-tickets" id="support-ticket-count"></span></a>
252
+ <div class="support-menu" id="support-menu" style="display:none;">
253
+ <div class="support-primary">
254
+ <ul class="support-nav">
255
+ <li>
256
+ <a href="http://us.battle.net/support/" tabindex="55" class="support-category">
257
+ <strong class="support-caption">Knowledge Center</strong>
258
+ Browse our support articles
259
+ </a>
260
+ </li>
261
+ <li>
262
+ <a href="https://us.battle.net/support/ticket/status" tabindex="55" class="support-category">
263
+ <strong class="support-caption">Your Support Tickets</strong>
264
+ View your active tickets (login required).
265
+ </a>
266
+ </li>
267
+ </ul>
268
+ <span class="clear"><!-- --></span>
269
+ </div>
270
+ <div class="support-secondary"></div>
271
+ <!--[if IE 6]> <iframe id="support-shim" src="javascript:false;" frameborder="0" scrolling="no" style="display: block; position: absolute; top: 0; left: 9px; width: 297px; height: 400px; z-index: -1;"></iframe>
272
+ <script type="text/javascript">
273
+ //<![CDATA[
274
+ (function(){
275
+ var doc = document;
276
+ var shim = doc.getElementById('support-shim');
277
+ shim.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
278
+ shim.style.display = 'block';
279
+ })();
280
+ //]]>
281
+ </script>
282
+ <![endif]-->
283
+ </div>
284
+ </li>
285
+ <li class="service-cell service-explore">
286
+ <a href="#explore" tabindex="50" accesskey="5" class="dropdown" id="explore-link" onclick="return false" style="cursor: progress" rel="javascript">Explore</a>
287
+ <div class="explore-menu" id="explore-menu" style="display:none;">
288
+ <div class="explore-primary">
289
+ <ul class="explore-nav">
290
+ <li>
291
+ <a href="http://us.battle.net/" tabindex="55" data-label="Home">
292
+ <strong class="explore-caption">Battle.net Home</strong>
293
+ Connect. Play. Unite.
294
+ </a>
295
+ </li>
296
+ <li>
297
+ <a href="https://us.battle.net/account/management/" tabindex="55" data-label="Account">
298
+ <strong class="explore-caption">Account</strong>
299
+ Manage your Account
300
+ </a>
301
+ </li>
302
+ <li>
303
+ <a href="http://us.battle.net/support/" tabindex="55" data-label="Support">
304
+ <strong class="explore-caption">Support</strong>
305
+ Get Support and explore the knowledgebase.
306
+ </a>
307
+ </li>
308
+ <li>
309
+ <a href="https://us.battle.net/account/management/get-a-game.html" tabindex="55" data-label="Buy Games">
310
+ <strong class="explore-caption">Buy Games</strong>
311
+ Digital Games for Download
312
+ </a>
313
+ </li>
314
+ </ul>
315
+ <div class="explore-links">
316
+ <h2 class="explore-caption">More</h2>
317
+ <ul>
318
+ <li><a href="http://us.battle.net/what-is/" tabindex="55" data-label="More">What is Battle.net?</a></li>
319
+ <li><a href="https://us.battle.net/account/parental-controls/index.html" tabindex="55" data-label="More">Parental Controls</a></li>
320
+ <li><a href="http://us.battle.net/security/" tabindex="55" data-label="More">Account Security</a></li>
321
+ <li><a href="https://us.battle.net/account/management/add-game.html" tabindex="55" data-label="More">Add a Game</a></li>
322
+ <li><a href="https://us.battle.net/account/support/password-reset.html" tabindex="55" data-label="More">Can’t log in?</a></li>
323
+ <li><a href="https://us.battle.net/account/download/" tabindex="55" data-label="More">Game Client Downloads</a></li>
324
+ <li><a href="https://us.battle.net/account/management/redemption/redeem.html" tabindex="55" data-label="More">Redeem Promo Codes</a></li>
325
+ <li><a href="http://us.battle.net/games/classic" tabindex="55" data-label="More">Classic Games</a></li>
326
+ </ul>
327
+ </div>
328
+ <span class="clear"><!-- --></span>
329
+ <!--[if IE 6]> <iframe id="explore-shim" src="javascript:false;" frameborder="0" scrolling="no" style="display: block; position: absolute; top: 0; left: 9px; width: 409px; height: 400px; z-index: -1;"></iframe>
330
+ <script type="text/javascript">
331
+ //<![CDATA[
332
+ (function(){
333
+ var doc = document;
334
+ var shim = doc.getElementById('explore-shim');
335
+ shim.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
336
+ shim.style.display = 'block';
337
+ })();
338
+ //]]>
339
+ </script>
340
+ <![endif]-->
341
+ </div>
342
+ <ul class="explore-secondary">
343
+ <li class="explore-game explore-game-sc2">
344
+ <a href="http://us.battle.net/sc2/" tabindex="55" data-label="Game - sc2">
345
+ <span class="explore-game-inner">
346
+ <strong class="explore-caption">StarCraft II™</strong>
347
+ <span>News &amp; Forums</span> <span>Beginner’s Guide</span> <span>Player Profiles</span>
348
+ </span>
349
+ </a>
350
+ </li>
351
+ <li class="explore-game explore-game-wow">
352
+ <a href="http://us.battle.net/wow/" tabindex="55" data-label="Game - wow">
353
+ <span class="explore-game-inner">
354
+ <strong class="explore-caption">World of Warcraft™</strong>
355
+ <span>Character Profiles</span> <span>News &amp; Forums</span> <span>Game Guide</span>
356
+ </span>
357
+ </a>
358
+ </li>
359
+ <li class="explore-game explore-game-d3">
360
+ <a href="http://us.battle.net/d3/" tabindex="55" data-label="Game - d3">
361
+ <span class="explore-game-inner">
362
+ <strong class="explore-caption">Diablo III™</strong>
363
+ <span>Game Guide</span> <span>News</span> <span>Forums</span>
364
+ </span>
365
+ </a>
366
+ </li>
367
+ </ul>
368
+ </div>
369
+ </li>
370
+ </ul>
371
+ <div id="warnings-wrapper">
372
+ <script type="text/javascript">
373
+ //<![CDATA[
374
+ $(function() {
375
+ App.saveCookie('html5Warning');
376
+ App.resetCookie('browserWarning');
377
+ });
378
+ //]]>
379
+ </script>
380
+ <!--[if lt IE 8]> <div id="browser-warning" class="warning warning-red">
381
+ <div class="warning-inner2">
382
+ You are using an outdated web browser.<br />
383
+ <a href="http://us.blizzard.com/support/article/browserupdate">Upgrade</a> or <a href="http://www.google.com/chromeframe/?hl=en-US" id="chrome-frame-link">install Google Chrome Frame</a>.
384
+ <a href="#close" class="warning-close" onclick="App.closeWarning('#browser-warning', 'browserWarning'); return false;"></a>
385
+ </div>
386
+ </div>
387
+ <![endif]-->
388
+ <!--[if lt IE 8]> <script type="text/javascript" src="/sc2/static/local-common/js/third-party/CFInstall.min.js?v42"></script>
389
+ <script type="text/javascript">
390
+ //<![CDATA[
391
+ $(function() {
392
+ var age = 365 * 24 * 60 * 60 * 1000;
393
+ var src = 'https://www.google.com/chromeframe/?hl=en-US';
394
+ if ('http:' == document.location.protocol) {
395
+ src = 'http://www.google.com/chromeframe/?hl=en-US';
396
+ }
397
+ document.cookie = "disableGCFCheck=0;path=/;max-age="+age;
398
+ $('#chrome-frame-link').bind({
399
+ 'click': function() {
400
+ App.closeWarning('#browser-warning');
401
+ CFInstall.check({
402
+ mode: 'overlay',
403
+ url: src
404
+ });
405
+ return false;
406
+ }
407
+ });
408
+ });
409
+ //]]>
410
+ </script>
411
+ <![endif]-->
412
+ <noscript>
413
+ <div id="javascript-warning" class="warning warning-red">
414
+ <div class="warning-inner2">
415
+ JavaScript must be enabled to use this site.
416
+ </div>
417
+ </div>
418
+ </noscript>
419
+ </div>
420
+ </div>
421
+ </div><script type="text/javascript" src="/sc2/static/local-common/js/search.js?v42"></script>
422
+ <script type="text/javascript">
423
+ //<![CDATA[
424
+ var xsToken = '';
425
+ var supportToken = '';
426
+ var Msg = {
427
+ support: {
428
+ ticketNew: 'Ticket {0} was created.',
429
+ ticketStatus: 'Ticket {0}’s status changed to {1}.',
430
+ ticketOpen: 'Open',
431
+ ticketAnswered: 'Answered',
432
+ ticketResolved: 'Resolved',
433
+ ticketCanceled: 'Canceled',
434
+ ticketArchived: 'Archived',
435
+ ticketInfo: 'Need Info',
436
+ ticketAll: 'View All Tickets'
437
+ },
438
+ cms: {
439
+ requestError: 'Your request cannot be completed.',
440
+ ignoreNot: 'Not ignoring this user',
441
+ ignoreAlready: 'Already ignoring this user',
442
+ stickyRequested: 'Sticky requested',
443
+ stickyHasBeenRequested: 'You have already sent a sticky request for this topic.',
444
+ postAdded: 'Post added to tracker',
445
+ postRemoved: 'Post removed from tracker',
446
+ userAdded: 'User added to tracker',
447
+ userRemoved: 'User removed from tracker',
448
+ validationError: 'A required field is incomplete',
449
+ characterExceed: 'The post body exceeds XXXXXX characters.',
450
+ searchFor: "Search for",
451
+ searchTags: "Articles tagged:",
452
+ characterAjaxError: "You may have become logged out. Please refresh the page and try again.",
453
+ ilvl: "Level {0}",
454
+ shortQuery: "Search requests must be at least three characters long."
455
+ },
456
+ bml: {
457
+ bold: 'Bold',
458
+ italics: 'Italics',
459
+ underline: 'Underline',
460
+ list: 'Unordered List',
461
+ listItem: 'List Item',
462
+ quote: 'Quote',
463
+ quoteBy: 'Posted by {0}',
464
+ unformat: 'Remove Formating',
465
+ cleanup: 'Fix Linebreaks',
466
+ code: 'Code Blocks',
467
+ item: 'WoW Item',
468
+ itemPrompt: 'Item ID:',
469
+ url: 'URL',
470
+ urlPrompt: 'URL Address:'
471
+ },
472
+ ui: {
473
+ submit: 'Submit',
474
+ cancel: 'Cancel',
475
+ reset: 'Reset',
476
+ viewInGallery: 'View in gallery',
477
+ loading: 'Loading…',
478
+ unexpectedError: 'An error has occurred',
479
+ fansiteFind: 'Find this on…',
480
+ fansiteFindType: 'Find {0} on…',
481
+ fansiteNone: 'No fansites available.'
482
+ },
483
+ grammar: {
484
+ colon: '{0}:',
485
+ first: 'First',
486
+ last: 'Last'
487
+ },
488
+ fansite: {
489
+ achievement: 'achievement',
490
+ character: 'character',
491
+ faction: 'faction',
492
+ 'class': 'class',
493
+ object: 'object',
494
+ talentcalc: 'talents',
495
+ skill: 'profession',
496
+ quest: 'quest',
497
+ spell: 'spell',
498
+ event: 'event',
499
+ title: 'title',
500
+ arena: 'arena team',
501
+ guild: 'guild',
502
+ zone: 'zone',
503
+ item: 'item',
504
+ race: 'race',
505
+ npc: 'NPC',
506
+ pet: 'pet'
507
+ },
508
+ search: {
509
+ kb: 'Support',
510
+ post: 'Forums',
511
+ article: 'Blog Articles',
512
+ static: 'General Content',
513
+ wowcharacter: 'Characters',
514
+ wowitem: 'Items',
515
+ wowguild: 'Guilds',
516
+ wowarenateam: 'Arena Teams',
517
+ url: 'Suggested Links',
518
+ other: 'Other'
519
+ }
520
+ };
521
+ //]]>
522
+ </script>
523
+ <script type="text/javascript">
524
+ //<![CDATA[
525
+ Core.load("/sc2/static/local-common/js/third-party/jquery-ui-1.8.6.custom.min.js?v42");
526
+ Core.load("/sc2/static/local-common/js/login.js?v42", false, function() {
527
+ Login.embeddedUrl = 'https://us.battle.net/login/login.frag';
528
+ });
529
+ //]]>
530
+ </script>
531
+ <script type="text/javascript" src="/sc2/static/local-common/js/menu.js?v42"></script>
532
+ <script type="text/javascript" src="/sc2/static/js/sc2.js?v21"></script>
533
+ <script type="text/javascript">
534
+ //<![CDATA[
535
+ $(function(){
536
+ Menu.initialize('/data/menu.json?v42');
537
+ Tooltip.options.useTable = true;
538
+ });
539
+ //]]>
540
+ </script>
541
+ <!--[if lt IE 8]> <script type="text/javascript" src="/sc2/static/local-common/js/third-party/jquery.pngFix.pack.js?v42"></script>
542
+ <script type="text/javascript">
543
+ //<![CDATA[
544
+ $('.png-fix').pngFix(); //]]>
545
+ </script>
546
+ <![endif]-->
547
+ <script type="text/javascript">
548
+ //<![CDATA[
549
+ (function() {
550
+ var ga = document.createElement('script');
551
+ var src = "https://ssl.google-analytics.com/ga.js";
552
+ if ('http:' == document.location.protocol) {
553
+ src = "http://www.google-analytics.com/ga.js";
554
+ }
555
+ ga.type = 'text/javascript';
556
+ ga.setAttribute('async', 'true');
557
+ ga.src = src;
558
+ var s = document.getElementsByTagName('script');
559
+ s = s[s.length-1];
560
+ s.parentNode.insertBefore(ga, s.nextSibling);
561
+ })();
562
+ //]]>
563
+ </script>
564
+ </body>
565
+ </html>
@@ -6,8 +6,13 @@ league_html = File.read File.dirname(__FILE__) + '/league.html'
6
6
  achievements_html = File.read File.dirname(__FILE__) + '/achievements.html'
7
7
  matches_html = File.read File.dirname(__FILE__) + '/matches.html'
8
8
  status_html = File.read File.dirname(__FILE__) + '/status.html'
9
+ failure_html = File.read File.dirname(__FILE__) + '/failure.html'
9
10
 
10
11
  FakeWeb.allow_net_connect = false
12
+ FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/2377239/1/SomeDude/', body: failure_html, status: 404, content_type: 'text/html'
13
+ FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/2377239/1/SomeDude/achievements/', body: failure_html, status: 404, content_type: 'text/html'
14
+ FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/2377239/1/SomeDude/leagues/12345', body: failure_html, status: 404, content_type: 'text/html'
15
+ FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/2377239/1/SomeDude/matches', body: failure_html, status: 404, content_type: 'text/html'
11
16
  FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/', body: profile_html, status: 200, content_type: 'text/html'
12
17
  FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/ladder/leagues', body: leagues_html, status: 200, content_type: 'text/html'
13
18
  FakeWeb.register_uri :get, 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/ladder/12345', body: league_html, status: 200, content_type: 'text/html'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bnet_scraper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-20 00:00:00.000000000 Z
12
+ date: 2012-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
16
- requirement: &70132164572300 !ruby/object:Gem::Requirement
16
+ requirement: &70185550262400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,21 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70132164572300
24
+ version_requirements: *70185550262400
25
+ - !ruby/object:Gem::Dependency
26
+ name: faraday
27
+ requirement: &70185550260120 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70185550260120
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: rake
27
- requirement: &70132164571740 !ruby/object:Gem::Requirement
38
+ requirement: &70185550258180 !ruby/object:Gem::Requirement
28
39
  none: false
29
40
  requirements:
30
41
  - - ! '>='
@@ -32,10 +43,10 @@ dependencies:
32
43
  version: '0'
33
44
  type: :development
34
45
  prerelease: false
35
- version_requirements: *70132164571740
46
+ version_requirements: *70185550258180
36
47
  - !ruby/object:Gem::Dependency
37
48
  name: rspec
38
- requirement: &70132164571280 !ruby/object:Gem::Requirement
49
+ requirement: &70185550256120 !ruby/object:Gem::Requirement
39
50
  none: false
40
51
  requirements:
41
52
  - - ! '>='
@@ -43,10 +54,10 @@ dependencies:
43
54
  version: '0'
44
55
  type: :development
45
56
  prerelease: false
46
- version_requirements: *70132164571280
57
+ version_requirements: *70185550256120
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: fakeweb
49
- requirement: &70132164570820 !ruby/object:Gem::Requirement
60
+ requirement: &70185550254960 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,7 +65,7 @@ dependencies:
54
65
  version: '0'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *70132164570820
68
+ version_requirements: *70185550254960
58
69
  description: BnetScraper is a Nokogiri-based scraper of Battle.net profile information.
59
70
  Currently this only includes Starcraft2.
60
71
  email:
@@ -66,6 +77,7 @@ files:
66
77
  - .gitignore
67
78
  - .rspec
68
79
  - .travis.yml
80
+ - CHANGELOG.md
69
81
  - Gemfile
70
82
  - LICENSE
71
83
  - README.md
@@ -89,6 +101,7 @@ files:
89
101
  - spec/starcraft2/status_scraper_spec.rb
90
102
  - spec/starcraft2_spec.rb
91
103
  - spec/support/achievements.html
104
+ - spec/support/failure.html
92
105
  - spec/support/league.html
93
106
  - spec/support/leagues.html
94
107
  - spec/support/load_fakeweb.rb
@@ -110,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
123
  version: '0'
111
124
  segments:
112
125
  - 0
113
- hash: -2131617336908961246
126
+ hash: 2368035120879927355
114
127
  required_rubygems_version: !ruby/object:Gem::Requirement
115
128
  none: false
116
129
  requirements:
@@ -119,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
132
  version: '0'
120
133
  segments:
121
134
  - 0
122
- hash: -2131617336908961246
135
+ hash: 2368035120879927355
123
136
  requirements: []
124
137
  rubyforge_project:
125
138
  rubygems_version: 1.8.17
@@ -136,6 +149,7 @@ test_files:
136
149
  - spec/starcraft2/status_scraper_spec.rb
137
150
  - spec/starcraft2_spec.rb
138
151
  - spec/support/achievements.html
152
+ - spec/support/failure.html
139
153
  - spec/support/league.html
140
154
  - spec/support/leagues.html
141
155
  - spec/support/load_fakeweb.rb