psn_trophies 0.0.1

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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in psn_trophies.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,17 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ psn_trophies (0.0.1)
5
+ nokogiri (~> 1.5.0)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ nokogiri (1.5.0)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ nokogiri (~> 1.5.0)
17
+ psn_trophies!
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Roger Leite, http://github.com/rogerleite/psn_trophies
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ PsnTrophies
2
+ ===========
3
+
4
+ A Ruby API for http://us.playstation.com/psn/trophies
5
+ Simply parses html from PSN Public Trophies.
6
+
7
+ Installation
8
+ ------------
9
+
10
+ gem install psn_trophies
11
+
12
+ Usage
13
+ -----
14
+
15
+ require "rubygems"
16
+ require "psn_trophies"
17
+
18
+ client = PsnTrophies::Client.new
19
+ played_games = client.trophies("psn_id") # ex. LeiteBR
20
+ played_games.map(&:title) #=> ["Dragon Age II", "GTA IV", ... etc.]
21
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,54 @@
1
+ require "nokogiri"
2
+ require "net/http"
3
+ require "uri"
4
+
5
+ module PsnTrophies
6
+
7
+ class Client
8
+
9
+ def trophies(profile_id)
10
+ body = get_body("http://us.playstation.com/playstation/psn/profile/#{profile_id}/get_ordered_trophies_data")
11
+
12
+ games = []
13
+ doc = Nokogiri::HTML(body)
14
+ doc.css('.slotcontent').each do |container|
15
+ logo = container.at_css('.titlelogo img')["src"]
16
+ title = container.at_css('.gameTitleSortField').content
17
+ progress = container.at_css('.gameProgressSortField').content
18
+ trophies = container.at_css('.gameTrophyCountSortField').content.strip
19
+
20
+ games << PlayedGame.new(:image_url => logo, :title => title, :progress => progress, :trophy_count => trophies)
21
+ end
22
+ games
23
+ end
24
+
25
+ private
26
+
27
+ def get_body(uri)
28
+ uri = URI.parse(uri)
29
+ http = Net::HTTP.new(uri.host, uri.port)
30
+
31
+ request = Net::HTTP::Get.new(uri.request_uri)
32
+ request["Host"] = "us.playstation.com"
33
+ request["User-Agent"] = "Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"
34
+ request["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
35
+ request["Accept-Language"] = "en-us,en;q=0.5"
36
+ request["Accept-Charset"] = "ISO-8859-1,utf-8;q=0.7,*;q=0.7"
37
+ request["Connection"] = "keep-alive"
38
+ request["Referer"] = "http://us.playstation.com/publictrophy/index.htm?onlinename=LeiteBR/trophies"
39
+
40
+ response = http.request(request)
41
+ response.body
42
+ end
43
+
44
+ end
45
+
46
+ class PlayedGame
47
+ attr_accessor :image_url, :title, :progress, :trophy_count
48
+
49
+ def initialize(attrs = {})
50
+ attrs.each { |attr, value| self.send(:"#{attr}=", value) }
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,3 @@
1
+ module PsnTrophies
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "psn_trophies/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "psn_trophies"
7
+ s.version = PsnTrophies::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Roger Leite"]
10
+ s.email = ["roger.barreto@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Parser for PSN Trophies site}
13
+ s.description = %q{Parser for PSN Trophies site}
14
+
15
+ s.rubyforge_project = "psn_trophies"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency('nokogiri', '~> 1.5.0')
23
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: psn_trophies
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Roger Leite
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-09 00:00:00 -03:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: nokogiri
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 1
32
+ - 5
33
+ - 0
34
+ version: 1.5.0
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ description: Parser for PSN Trophies site
38
+ email:
39
+ - roger.barreto@gmail.com
40
+ executables: []
41
+
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .gitignore
48
+ - Gemfile
49
+ - Gemfile.lock
50
+ - MIT-LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - lib/psn_trophies.rb
54
+ - lib/psn_trophies/version.rb
55
+ - psn_trophies.gemspec
56
+ has_rdoc: true
57
+ homepage: ""
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options: []
62
+
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ hash: 3
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ requirements: []
84
+
85
+ rubyforge_project: psn_trophies
86
+ rubygems_version: 1.4.1
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Parser for PSN Trophies site
90
+ test_files: []
91
+