steam_stats 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b81709fab244b097f8bd693192319e6dacbfd30f
4
+ data.tar.gz: df9bddd533e5cb741f657da6020b85d6ccb767ce
5
+ SHA512:
6
+ metadata.gz: 084a01c5ff321fd9ed044e39d921045c8de845fa8faa7f870a9e9145a3f11c18994b0f87be28e74a2d911ab9ab1aaa507ee1c639a8a62c36de9ba1a63ad385d0
7
+ data.tar.gz: d81ea93fe0427380bac6168508d05a28dcdff6a86405ff3182bf3be3be028f6b5a3c7955e3101245e77a1284592ae977e68adf8f030ec08a1027d18c084d2800
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ - 2.1.6
5
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'coveralls', require: false
4
+
5
+ # Specify your gem's dependencies in steam_stats.gemspec
6
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Krzysztof Zbudniewek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ # SteamStats
2
+
3
+ [![Build Status](https://travis-ci.org/neonowy/steam-stats.svg?branch=master)](https://travis-ci.org/neonowy/steam-stats)
4
+ [![Dependency Status](https://gemnasium.com/neonowy/steam-stats.svg)](https://gemnasium.com/neonowy/steam-stats)
5
+ [![Code Climate](https://codeclimate.com/github/neonowy/steam-stats/badges/gpa.svg)](https://codeclimate.com/github/neonowy/steam-stats)
6
+ [![Coverage Status](https://coveralls.io/repos/neonowy/steam-stats/badge.svg?branch=master)](https://coveralls.io/r/neonowy/steam-stats?branch=master)
7
+
8
+ Get Steam player's info and games stats.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'steam_stats'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install steam_stats
25
+
26
+ ## Usage
27
+
28
+ 1. Find user by ID (you have to get it by yourself by looking at URL in browser)
29
+ ```ruby
30
+ user = Steam.user '76561198041851025'
31
+ ```
32
+
33
+ 2. Get array of played games
34
+ ```ruby
35
+ games = user.games #=> [{ name: 'Team Fortress 2', played_hours: 93 }, { name: 'Sniper Elite V2', played_hours: 2.4 }]
36
+ ```
37
+
38
+ 3. And now you have your stats, have fun with it!
39
+ ```ruby
40
+ hours_in_tf2 = games[0].played_hours
41
+ ```
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( https://github.com/neonowy/steam_stats/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Code, code, code :computer: :computer:
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'rake'
2
+ require 'rspec/core/rake_task'
3
+ require 'bundler/gem_tasks'
4
+
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.pattern = Dir.glob('spec/**/*_spec.rb')
7
+ end
8
+
9
+ task :default => :spec
@@ -0,0 +1,71 @@
1
+ module SteamStats
2
+ class User
3
+ attr_reader :name, :real_name, :avatar, :country, :level, :games
4
+
5
+ def initialize(user_id)
6
+ @id = user_id
7
+
8
+ @user_url = get_user_url
9
+ @games_url = get_games_url
10
+
11
+ @user_page = Nokogiri::HTML(open(@user_url))
12
+ @games_page = Nokogiri::HTML(open(@games_url))
13
+
14
+ @games = []
15
+
16
+ fetch_info
17
+ fetch_games
18
+ end
19
+
20
+ def is_online?
21
+ @online
22
+ end
23
+
24
+ private
25
+ def fetch_info
26
+ @name = @user_page.css('.actual_persona_name')[0].text
27
+ @real_name = @user_page.css('.header_real_name.ellipsis bdi')[0].text
28
+ @avatar = @user_page.css('.playerAvatar img')[0]['src']
29
+ @country = @user_page.css('.profile_flag')[0]['src'][-6..-5].upcase
30
+ @level = @user_page.css('.persona_name .friendPlayerLevelNum').text.to_i
31
+
32
+ if @user_page.css('.profile_in_game_header').nil?
33
+ @online = true
34
+ else
35
+ @online = false
36
+ end
37
+ end
38
+
39
+ def fetch_games
40
+ @games_js = @games_page.css('script[language=javascript]')[0].text
41
+ @games_json = /rgGames = (\[.+\]);/.match(@games_js)[1]
42
+ @games_raw = JSON.parse(@games_json)
43
+
44
+ JSON.parse(@games_json).each do |element|
45
+ played_hours = element['hours_forever'].to_f
46
+ name = element['name']
47
+
48
+ game = { name: name, played_hours: played_hours }
49
+
50
+ @games.push(game)
51
+ end
52
+ end
53
+
54
+ def get_user_url
55
+ if is_number?(@id)
56
+ "http://steamcommunity.com/profiles/#{@id}"
57
+ else
58
+ "http://steamcommunity.com/id/#{@id}"
59
+ end
60
+ end
61
+
62
+ # Warning! Call only after get_user_url
63
+ def get_games_url
64
+ "#{@user_url}/games/?tab=all"
65
+ end
66
+
67
+ def is_number?(string)
68
+ true if Float(string) rescue false
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,3 @@
1
+ module SteamStats
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+ require 'json'
4
+
5
+ require "steam_stats/version"
6
+ require "steam_stats/user"
7
+
8
+ module SteamStats
9
+ end