steam_stats 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.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/LICENSE +22 -0
- data/README.md +50 -0
- data/Rakefile +9 -0
- data/lib/steam_stats/user.rb +71 -0
- data/lib/steam_stats/version.rb +3 -0
- data/lib/steam_stats.rb +9 -0
- data/spec/data/games.html +329 -0
- data/spec/data/user.html +789 -0
- data/spec/spec_helper.rb +85 -0
- data/spec/user_spec.rb +49 -0
- data/steam_stats.gemspec +26 -0
- metadata +134 -0
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
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
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
|
+
[](https://travis-ci.org/neonowy/steam-stats)
|
4
|
+
[](https://gemnasium.com/neonowy/steam-stats)
|
5
|
+
[](https://codeclimate.com/github/neonowy/steam-stats)
|
6
|
+
[](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,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
|