psn_trophies 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,17 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- psn_trophies (0.0.1)
4
+ psn_trophies (0.0.2)
5
5
  nokogiri (~> 1.5.0)
6
6
 
7
7
  GEM
8
8
  remote: http://rubygems.org/
9
9
  specs:
10
+ ansi (1.3.0)
11
+ fakeweb (1.3.0)
12
+ minitest (2.6.1)
13
+ minitest-reporters (0.4.0)
14
+ ansi
15
+ minitest (~> 2.0)
16
+ ruby-progressbar
10
17
  nokogiri (1.5.0)
18
+ ruby-progressbar (0.0.10)
11
19
 
12
20
  PLATFORMS
13
21
  ruby
14
22
 
15
23
  DEPENDENCIES
16
- nokogiri (~> 1.5.0)
24
+ fakeweb
25
+ minitest
26
+ minitest-reporters
17
27
  psn_trophies!
data/README.md CHANGED
@@ -16,6 +16,7 @@ Usage
16
16
  require "psn_trophies"
17
17
 
18
18
  client = PsnTrophies::Client.new
19
- played_games = client.trophies("psn_id") # ex. LeiteBR
19
+ played_games = client.trophies("valid_psn_id") # ex. LeiteBR
20
20
  played_games.map(&:title) #=> ["Dragon Age II", "GTA IV", ... etc.]
21
21
 
22
+ client.trophies("invalid_psn_id") # => raises PsnTrophies::NoUserProfileError
data/Rakefile CHANGED
@@ -1,2 +1,14 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+
1
4
  require 'bundler'
2
5
  Bundler::GemHelper.install_tasks
6
+
7
+ desc "Run tests"
8
+ Rake::TestTask.new do |t|
9
+ t.libs << "test"
10
+ t.test_files = FileList['test/**/*.rb']
11
+ t.verbose = true
12
+ end
13
+
14
+ task :default => :test
@@ -4,13 +4,17 @@ require "uri"
4
4
 
5
5
  module PsnTrophies
6
6
 
7
+ class NoUserProfileError < StandardError; end
8
+
7
9
  class Client
8
10
 
9
11
  def trophies(profile_id)
10
- body = get_body("http://us.playstation.com/playstation/psn/profile/#{profile_id}/get_ordered_trophies_data")
12
+ check_profile_id(profile_id)
13
+ body = get_body("http://us.playstation.com/playstation/psn/profile/#{profile_id}/get_ordered_trophies_data",
14
+ "http://us.playstation.com/publictrophy/index.htm?onlinename=#{profile_id}/trophies")
11
15
 
12
16
  games = []
13
- doc = Nokogiri::HTML(body)
17
+ doc = Nokogiri::HTML.fragment(body)
14
18
  doc.css('.slotcontent').each do |container|
15
19
  logo = container.at_css('.titlelogo img')["src"]
16
20
  title = container.at_css('.gameTitleSortField').content
@@ -24,7 +28,17 @@ module PsnTrophies
24
28
 
25
29
  private
26
30
 
27
- def get_body(uri)
31
+ def check_profile_id(profile_id)
32
+ body = get_body("http://us.playstation.com/playstation/psn/profiles/#{profile_id}",
33
+ "http://us.playstation.com/publictrophy/index.htm?onlinename=#{profile_id}")
34
+ doc = Nokogiri::HTML(body)
35
+ error_section = doc.at_css('.errorSection')
36
+ unless error_section.nil?
37
+ raise NoUserProfileError.new("No User Profile for #{profile_id}")
38
+ end
39
+ end
40
+
41
+ def get_body(uri, referer)
28
42
  uri = URI.parse(uri)
29
43
  http = Net::HTTP.new(uri.host, uri.port)
30
44
 
@@ -35,7 +49,7 @@ module PsnTrophies
35
49
  request["Accept-Language"] = "en-us,en;q=0.5"
36
50
  request["Accept-Charset"] = "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
37
51
  request["Connection"] = "keep-alive"
38
- request["Referer"] = "http://us.playstation.com/publictrophy/index.htm?onlinename=LeiteBR/trophies"
52
+ request["Referer"] = referer
39
53
 
40
54
  response = http.request(request)
41
55
  response.body
@@ -1,3 +1,3 @@
1
1
  module PsnTrophies
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -20,4 +20,8 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ["lib"]
21
21
 
22
22
  s.add_dependency('nokogiri', '~> 1.5.0')
23
+
24
+ s.add_development_dependency('minitest')
25
+ s.add_development_dependency('minitest-reporters')
26
+ s.add_development_dependency('fakeweb')
23
27
  end
@@ -0,0 +1,402 @@
1
+ HTTP/1.1 200 OK
2
+ Date: Mon, 10 Oct 2011 02:12:53 GMT
3
+ Server: Apache
4
+ Content-Length: 11754
5
+ Set-Cookie: JSESSIONID=L8MxTSJFtnG3Zwmtd1jQhtRVp39jQXWWnvn6Xl4vKXqgyTc1fLqf!1198684090; path=/
6
+ Content-Language: en-US
7
+ X-Powered-By: Servlet/2.5 JSP/2.1
8
+ Content-Type: text/html; charset=UTF-8
9
+ Set-Cookie: SONYCOOKIE1=577022144.20480.0000; path=/
10
+
11
+
12
+
13
+
14
+
15
+ <?xml version="1.0" encoding="UTF-8"?>
16
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
17
+
18
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
19
+
20
+
21
+
22
+
23
+
24
+
25
+ <head>
26
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
27
+ <link rel="shortcut icon" href="http://webassets.scea.com/playstation/assets/favicon.ico"/ type="image/x-icon">
28
+ <link rel="stylesheet" href="http://webassets.scea.com/playstation/assets/css/reset.css" type="text/css" media="screen" charset="utf-8"/>
29
+ <link rel="stylesheet" href="http://webassets.scea.com/playstation/assets/css/global.css" type="text/css" media="screen" charset="utf-8"/>
30
+ <link rel="stylesheet" href="http://webassets.scea.com/playstation/assets/css/modules.css" type="text/css" media="screen" charset="utf-8"/>
31
+ <link rel="stylesheet" href="http://webassets.scea.com/playstation/assets/css/additional.css" type="text/css" media="screen" charset="utf-8"/>
32
+ <!--[if lte IE 7]>
33
+ <link rel="stylesheet" href="http://webassets.scea.com/playstation/assets/css/ie.css" type="text/css" media="screen" charset="utf-8"/>
34
+ <link rel="stylesheet" href="http://webassets.scea.com/playstation/assets/css/additionalie.css" type="text/css" media="screen" charset="utf-8"/>
35
+ <![endif]-->
36
+
37
+ <link rel="stylesheet" href="http://webassets.scea.com/playstation/assets/css/temp.css" type="text/css" media="screen" charset="utf-8"/>
38
+
39
+ <link rel="stylesheet" type="text/css" media="all" href="http://webassets.scea.com/playstation/stylesheets/lightview.css"/>
40
+ <link rel="stylesheet" type="text/css" media="all" href="http://webassets.scea.com/playstation/stylesheets/prototip.css"/>
41
+ <link rel="stylesheet" type="text/css" media="all" href="http://webassets.scea.com/playstation/stylesheets/trophies.css"/>
42
+
43
+ <!--[if lt IE 7]>
44
+ <link rel="stylesheet" type="text/css" media="all" href="http://webassets.scea.com/playstation/stylesheets/bie6.css"/>
45
+ <![endif]-->
46
+ <!--[if (gte IE 7)]>
47
+ <link rel="stylesheet" type="text/css" media="all" href="http://webassets.scea.com/playstation/stylesheets/bie7.css"/>
48
+ <![endif]-->
49
+
50
+ <script type="text/javascript" charset="utf-8" src="http://webassets.scea.com/playstation/assets/js/swfobject.js"></script>
51
+ <script type="text/javascript" src="http://webassets.scea.com/playstation/javascripts/protoaculous.1.8.2.p1.6.1_rc3.min_patch.js"></script>
52
+ <script type="text/javascript" src="http://webassets.scea.com/playstation/javascripts/lightview.js"></script>
53
+ <script type="text/javascript" src="http://webassets.scea.com/playstation/javascripts/prototip.js"></script>
54
+ <script type="text/javascript" src="http://webassets.scea.com/playstation/javascripts/livepipe/livepipe.js"></script>
55
+ <script type="text/javascript" src="http://webassets.scea.com/playstation/javascripts/livepipe/scrollbar.js"></script>
56
+
57
+ <script type="text/javascript" src="http://webassets.scea.com/playstation/javascripts/application.js"></script>
58
+
59
+ <script src="http://webassets.scea.com/playstation/assets/js/AC_RunActiveContent.js" type="text/javascript"></script>
60
+ <title>PlayStation.com - Public Profile - LeiteBR</title>
61
+
62
+ <script type="text/javascript">
63
+ var busyPath = "/playstation/pages/busy.html";
64
+ </script>
65
+ </head>
66
+ <body>
67
+ <!-- /main -->
68
+ <div id="main" name="main" class="clearfix">
69
+ <!-- breadcrumb -->
70
+
71
+
72
+
73
+ <div id="breadcrumb">
74
+ <h3 style="font-size:18px;">
75
+
76
+
77
+
78
+
79
+ LeiteBR's Trophies
80
+
81
+
82
+
83
+ </h3>
84
+ </div>
85
+
86
+
87
+
88
+
89
+
90
+ <!-- /breadcrumb -->
91
+ <!-- <div class="share">
92
+ <a href="#" id="overlayShare" onclick="alert('implement')"><span>Share this</span></a>
93
+ </div> -->
94
+ <!-- content -->
95
+ <div id="trophiescontent">
96
+
97
+
98
+
99
+
100
+
101
+
102
+ <script type="text/javascript" src="http://webassets.scea.com/playstation/javascripts/application.js"></script>
103
+
104
+ <div id="reset_title_section" style="overflow:hidden">
105
+ <!-- <h5 style="font-size:12px; float:left; padding:5px 0 0 0; color:#555555">
106
+
107
+
108
+
109
+
110
+ LeiteBR's Trophies
111
+
112
+
113
+
114
+
115
+
116
+ </h5> -->
117
+ <a class="reset_title" href="javascript:resetView();">Reset View </a>
118
+ <a class="backLink_title" href="javascript:history.go(-1);">Back to Previous
119
+ </a></div>
120
+
121
+ <div class="trophiescontainer">
122
+ <div class="trophiesinnermodule">
123
+
124
+
125
+
126
+
127
+ <div class="summaryslot">
128
+ <div class="profileLogo">
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+ <div class="badge-full">
137
+
138
+ <div id="id-avatar">
139
+ <img width="57" height="57" border="0" alt="" src="/uwps/GetAvtarImage?avtar=http://static-resource.np.community.playstation.net/avatar_s/WWS_E/E0002_s.png" title="LeiteBR"/>
140
+ </div>
141
+ <div id="id-handle">
142
+ LeiteBR
143
+ </div>
144
+
145
+
146
+
147
+
148
+
149
+ <div id="id-compare" onClick="profileSignIn();">
150
+ <a href="javascript:void();">Compare With
151
+
152
+
153
+ My Friends
154
+
155
+
156
+ </a>
157
+ </div>
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+ </div>
166
+
167
+ <script type="text/javascript">
168
+ function profileSignIn() {
169
+ parent.document.getElementById("black_overlay1").style.display="block";
170
+ parent.document.getElementById("overlayLogin").style.display="block";
171
+ parent.document.getElementById("signin-iframe").src="https://store.playstation.com/external/index.vm?returnURL=http://" + location.host + "/uwps/PSNTicketRetrievalGenericServlet";
172
+ }
173
+ </script>
174
+
175
+ </div>
176
+
177
+
178
+
179
+ <div id="trophysummary">
180
+
181
+ <div id="levelprogress">
182
+ <div class="stitle"><strong>LEVEL</strong></div>
183
+ <div id="starline">
184
+ </div>
185
+ <div id="leveltext"> 7</div>
186
+ </div>
187
+
188
+ <div id="totaltrophies">
189
+ <div class="stitle"><strong>TROPHIES</strong></div>
190
+ <div id="text">
191
+ 334
192
+ </div>
193
+ </div>
194
+ <div style="clear:both"></div>
195
+
196
+ <div id="barline">
197
+ <div id="progressbar" class="progress_bar" style="width: 2.98px"></div>
198
+ </div>
199
+ <div class="progresstext">
200
+ 2%
201
+ </div>
202
+ </div>
203
+ <div class="podium">
204
+ <div class="text platinum">0 Platinum</div>
205
+ <div class="text gold">6 Gold</div>
206
+ <div class="text silver">39 Silver</div>
207
+ <div class="text bronze">289 Bronze</div>
208
+ </div>
209
+ </div>
210
+ </div>
211
+ </div>
212
+ <div class="trophiescontainer mainlist">
213
+ <div class="trophiesinnermodule">
214
+
215
+
216
+
217
+
218
+ <div class="topslot">
219
+ <div id="topcontent">
220
+
221
+ <div class="topslotCol1">
222
+
223
+ <div class="colHeader topslotCol1a">
224
+ <div class="columntext">
225
+
226
+ TITLE
227
+ </div>
228
+ </div>
229
+
230
+ <div class="headerSeparator"></div>
231
+
232
+
233
+ <div class="colHeader topslotCol1b">
234
+ <div class="columntext">
235
+
236
+ COMPARE<br /> FRIENDS
237
+ </div>
238
+ </div>
239
+ <div class="headerSeparator"></div>
240
+ </div>
241
+ <div class="colHeader topslotCol2">
242
+ <div class="columntext">
243
+
244
+ PROGRESS
245
+
246
+ </div>
247
+ </div>
248
+
249
+ <div class="headerSeparator"></div>
250
+
251
+ <div class="colHeader topslotCol3">
252
+ <div class="columntext">
253
+
254
+ TROPHIES
255
+ </div>
256
+ </div>
257
+
258
+ <div class="headerSeparator"></div>
259
+
260
+
261
+ <div class="colHeader topslotCol4">
262
+ <div class="trophyholder">
263
+ <div class="trophyimage bronze"></div>
264
+ <div class="trophyimage silver"></div>
265
+ <div class="trophyimage gold"></div>
266
+ <div class="trophyimage platinum"></div>
267
+ </div>
268
+ </div>
269
+ </div>
270
+ </div>
271
+
272
+
273
+
274
+ <div id="slots_container" class="scrollbar_container">
275
+ <div id="scrollbar_up_arrow" class="scrollbar_up_arrow" style="display:none"></div>
276
+ <div id="scrollbar_down_arrow" class="scrollbar_down_arrow" style="display:none"></div>
277
+ <div id="scrollbar_track" class="scrollbar_track" style="display:none"><div id="scrollbar_handle" class="scrollbar_handle"></div></div>
278
+ <div id="theMainSlot">
279
+ <div id="spacer"></div>
280
+
281
+
282
+
283
+ <SCRIPT src="http://webassets.scea.com/playstation/javascripts/s_code.js" type=text/javascript></SCRIPT>
284
+ <script type="text/javascript" language="JavaScript">
285
+ function getOrderedData() {
286
+ var url = "/playstation/psn/profile/LeiteBR/get_ordered_trophies_data";
287
+ new Ajax.Updater('theMainSlot', url,
288
+ {
289
+ asynchronous:true,
290
+ onFailure: reportError,
291
+ onComplete: setupSortCheck,
292
+ on503: redirectToBusy,
293
+ on403: redirectToLogin,
294
+ method: 'get'
295
+ });
296
+ }
297
+ function setupSortCheck() {
298
+ if ($('theMainSlot').down() == null) {
299
+ if (true) {
300
+ $('theMainSlot').innerHTML='<div class="noDataMessage">' +
301
+ 'You do not currently have any trophies in your list. You must use your PLAYSTATION<sup>&reg;</sup> 3 console to add trophies.' +
302
+ '</div>';
303
+ } else {
304
+ $('theMainSlot').innerHTML='<div class="noDataMessage">' +
305
+ 'No Trophies' +
306
+ '</div>';
307
+ }
308
+ } else {
309
+ setupSort();
310
+ }
311
+ }
312
+
313
+ var sortFunction = sortOn;
314
+ var sortSpec = {'topslotCol1a':{'sortField':'gameTitle','extractor': textContentExtractor, 'comparator': stringCompare},
315
+ 'topslotCol2':{'sortField':'gameProgress', 'extractor': textContentExtractor, 'comparator': integerCompare},
316
+ 'topslotCol3':{'sortField':'gameTrophyCount', 'extractor': textContentExtractor, 'comparator': integerCompare}};
317
+
318
+ document.observe("dom:loaded", function() {
319
+ //var defaultSort = "progress_desc";
320
+ getOrderedData();
321
+ //setupSort();
322
+ });
323
+
324
+ function setIFrameHeightToCookie1(iframeId){
325
+ var formHeight = document.getElementById('main').offsetHeight;
326
+ var iFrame = window.parent.document.getElementById(iframeId);
327
+ if (formHeight != null && iFrame !=null){
328
+ iFrame.height = eval(formHeight) ;
329
+ if(iFrame.style.height=='Nan' || iFrame.style.height=='0'){
330
+ iFrame.style.height = '600px';
331
+ }
332
+ }
333
+ else if (iFrame !=null) {
334
+ iFrame.height = '600px';
335
+ }
336
+ }
337
+ function profileSignIn() {
338
+ parent.document.getElementById("black_overlay1").style.display="block";
339
+ parent.document.getElementById("overlayLogin").style.display="block";
340
+ parent.document.getElementById("signin-iframe").src="https://store.playstation.com/external/index.vm?returnURL=http://" + location.host + "/uwps/PSNTicketRetrievalGenericServlet";
341
+ }
342
+ function ClickOmniTrack(obj,eventVal,secName) {
343
+ s.events=eventVal;
344
+ s.linkTrackEvents=eventVal;
345
+ s.linkTrackVars='events';
346
+ s.pageName = secName;
347
+ s.tl(obj,'o',secName);
348
+ }
349
+ function compareTrophy(title){
350
+ var da = title.split('/');
351
+ var s=s_gi('sceaplaystationprod');
352
+ s.linkTrackVars='prop26';
353
+ s.prop26=da[5];
354
+ s.tl(this,'o','trophyCompare/ps/mytrophies');
355
+ }
356
+ if(parent.document.getElementById('loading')!=null) {
357
+ parent.document.getElementById('loading').style.display='none';
358
+ }
359
+ </script>
360
+
361
+ </div>
362
+ </div>
363
+
364
+
365
+
366
+ </div>
367
+ </div>
368
+
369
+ <script type="text/javascript" language="JavaScript">
370
+ function backPage() {
371
+ if(navigator.appName == "Microsoft Internet Explorer")
372
+ {
373
+ if(window.location.pathname=='/playstation/psn/profile/trophies' || window.location.pathname=='/playstation/psn/profile/friends'){
374
+ history.go(-1);
375
+ } else {
376
+ history.go(-1);
377
+ return;
378
+ }
379
+ }
380
+ history.go(-1);
381
+ }
382
+ function resetView() {
383
+ window.location.reload();
384
+ }
385
+ </script>
386
+ </div><!-- /content -->
387
+
388
+
389
+
390
+ <p class="profile_note">Note: The above information is dependent on the proper functioning of the PlayStation®Network. Information is not updated in real time.</p>
391
+
392
+ <div id="tipHolder" style="display:none;"></div>
393
+ </div>
394
+ <!-- /main -->
395
+ </body>
396
+
397
+ <script>
398
+ if(parent.document.getElementById('profileFrame')!=null){
399
+ }
400
+ </script>
401
+ </html>
402
+