steamprofile 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ README.rdoc
2
+ Rakefile
3
+ lib/steamprofile.rb
4
+ Manifest
File without changes
@@ -0,0 +1,15 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('steamprofile','0.0.1') do |p|
6
+ p.description = "Loads a given steam profile in ruby"
7
+ p.url = "http://www.arcath.net"
8
+ p.author = "Adam \"Arcath\" Laycock"
9
+ p.email = "adam@arcath.net"
10
+ p.ignore_pattern= ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ p.runtime_dependencies = ["nokogiri >=1.4.0"]
13
+ end
14
+
15
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,67 @@
1
+ require 'rubygems'
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ class SteamProfile
6
+ def initialize(config)
7
+ #Set caching to false unless specified
8
+ config[:cache] ||= false
9
+ #Make sure the profile url has been supplied and is valid
10
+ unless config[:profile_url]
11
+ config[:error] = "No Profile URL Specified"
12
+ else
13
+ unless config[:profile_url] =~ /^http:\/\/steamcommunity\.com\/[id|profiles]/ then
14
+ config[:error] = "Mal-Formed Profile URL"
15
+ else
16
+ config[:xml_url] = config[:profile_url] + "?xml=1"
17
+ end
18
+ end
19
+ #Instanize the config array
20
+ @config=config
21
+ #Load Up Nokogiri
22
+ unless config[:error]
23
+ @nokogiri=Nokogiri::XML::Reader(open(config[:xml_url]))
24
+ end
25
+ self.nokogiri
26
+ end
27
+
28
+ def field
29
+ return @fields
30
+ end
31
+
32
+ def nokogiri
33
+ @fields={}
34
+ @fields[:game]=[]
35
+ @fields[:game_hours_played]=[]
36
+ gi=0
37
+ ghpi=0
38
+ @nokogiri.each do |node|
39
+ if node.name == "steamID" then
40
+ @fields[:name] ||= self.stripcdata(node.inner_xml)
41
+ elsif node.name == "gameName" then
42
+ if gi != 3 && node.inner_xml != "" then
43
+ @fields[:game][gi] ||= self.stripcdata(node.inner_xml)
44
+ gi+=1
45
+ end
46
+ elsif node.name == "hoursPlayed" then
47
+ if ghpi != 3 && node.inner_xml != "" then
48
+ @fields[:game_hours_played][ghpi] ||= node.inner_xml
49
+ ghpi+=1
50
+ end
51
+ elsif node.name == "onlineState" then
52
+ @fields[:online_state] ||= node.inner_xml
53
+ elsif node.name == "stateMessage" then
54
+ @fields[:state_message] ||= self.stripcdata(node.inner_xml)
55
+ elsif node.name == "avatarIcon" then
56
+ @fields[:avatar] ||= self.stripcdata(node.inner_xml)
57
+ @fields[:avatar_med] ||= @fields[:avatar].gsub(/\.jpg/,"_medium.jpg")
58
+ @fields[:avatar_full] ||= @fields[:avatar].gsub(/\.jpg/,"_full.jpg")
59
+ end
60
+ end
61
+ end
62
+ def stripcdata(s)
63
+ s.scan(/<!\[CDATA\[(.*?)\]\]>/).join
64
+ end
65
+ end
66
+
67
+ #s=SteamProfile.new(:profile_url => "http://steamcommunity.com/profiles/76561197990531359")
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{steamprofile}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Adam \"Arcath\" Laycock"]
9
+ s.date = %q{2009-12-11}
10
+ s.description = %q{Loads a given steam profile in ruby}
11
+ s.email = %q{adam@arcath.net}
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/steamprofile.rb"]
13
+ s.files = ["README.rdoc", "Rakefile", "lib/steamprofile.rb", "Manifest", "steamprofile.gemspec"]
14
+ s.homepage = %q{http://www.arcath.net}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Steamprofile", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{steamprofile}
18
+ s.rubygems_version = %q{1.3.5}
19
+ s.summary = %q{Loads a given steam profile in ruby}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.0"])
27
+ else
28
+ s.add_dependency(%q<nokogiri>, [">= 1.4.0"])
29
+ end
30
+ else
31
+ s.add_dependency(%q<nokogiri>, [">= 1.4.0"])
32
+ end
33
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: steamprofile
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Adam "Arcath" Laycock
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-11 00:00:00 +00:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: nokogiri
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.4.0
24
+ version:
25
+ description: Loads a given steam profile in ruby
26
+ email: adam@arcath.net
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ - lib/steamprofile.rb
34
+ files:
35
+ - README.rdoc
36
+ - Rakefile
37
+ - lib/steamprofile.rb
38
+ - Manifest
39
+ - steamprofile.gemspec
40
+ has_rdoc: true
41
+ homepage: http://www.arcath.net
42
+ licenses: []
43
+
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --line-numbers
47
+ - --inline-source
48
+ - --title
49
+ - Steamprofile
50
+ - --main
51
+ - README.rdoc
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "1.2"
65
+ version:
66
+ requirements: []
67
+
68
+ rubyforge_project: steamprofile
69
+ rubygems_version: 1.3.5
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: Loads a given steam profile in ruby
73
+ test_files: []
74
+