steam-api 1.0.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  module Steam
3
2
  # A Ruby DSL for communicating with the Steam Web API.
4
3
  # @see https://developer.valvesoftware.com/wiki/Steam_Web_API
@@ -7,14 +6,16 @@ module Steam
7
6
  # Get Owned Games
8
7
  # @param [Hash] params Parameters to pass to the API
9
8
  # @option params [Fixnum] :steamid The 64 bit ID of the player. (Optional)
10
- # @option params [Boolean] :include_appinfo (false) Whether or not to include additional
11
- # details of apps - name and images.
12
- # @option params [Boolean] :include_played_free_games (false) Whether or not to list
13
- # free-to-play games in the results.
14
- # @option params [Array] :appids_filter You can optionally filter the list to a set of appids.
15
- # Note that these cannot be passed as a URL parameter, instead you must use the JSON format
16
- # described in Steam_Web_API#Calling_Service_interfaces. The expected input is an array of
17
- # integers (in JSON: "appids_filter: [ 440, 500, 550 ]" )
9
+ # @option params [Integer] :include_appinfo (0) Whether or not to include
10
+ # additional details of apps - name and images.
11
+ # @option params [Boolean] :include_played_free_games (false) Whether or
12
+ # not to list free-to-play games in the results.
13
+ # @option params [Array] :appids_filter You can optionally filter the list
14
+ # to a set of appids.
15
+ # Note that these cannot be passed as a URL parameter, instead you must
16
+ # use the JSON format described in
17
+ # Steam_Web_API#Calling_Service_interfaces. The expected input is an
18
+ # array of integers (in JSON: "appids_filter: [ 440, 500, 550 ]" )
18
19
  # @see http://wiki.teamfortress.com/wiki/WebAPI/GetOwnedGames
19
20
  def self.owned_games(steamid, params: {})
20
21
  params[:steamid] = steamid
@@ -25,8 +26,9 @@ module Steam
25
26
  # Get Recently Played Games
26
27
  # @param [Hash] params Parameters to pass to the API
27
28
  # @option params [String] :steamid The SteamID of the account.
28
- # @option params [String] :count Optionally limit to a certain number of games (the number of
29
- # games a person has played in the last 2 weeks is typically very small)
29
+ # @option params [String] :count Optionally limit to a certain number of
30
+ # games (the number of games a person has played in the last 2 weeks is
31
+ # typically very small)
30
32
  # @see http://wiki.teamfortress.com/wiki/WebAPI/GetRecentlyPlayedGames
31
33
  def self.recently_played_games(steamid, params: {})
32
34
  params[:steamid] = steamid
@@ -64,8 +66,6 @@ module Steam
64
66
  .parse_key('quests')
65
67
  end
66
68
 
67
- private
68
-
69
69
  def self.client
70
70
  build_client 'IPlayerService'
71
71
  end
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  module Steam
3
2
  # A Ruby DSL for communicating with the Steam Web API.
4
3
  # @see https://developer.valvesoftware.com/wiki/Steam_Web_API
@@ -29,8 +28,6 @@ module Steam
29
28
  response
30
29
  end
31
30
 
32
- private
33
-
34
31
  def self.client
35
32
  build_client 'ISteamRemoteStorage'
36
33
  end
@@ -0,0 +1,20 @@
1
+ module Steam
2
+ # A Ruby DSL for communicating with the Steam Web API.
3
+ # @see https://developer.valvesoftware.com/wiki/Steam_Web_API
4
+ # @since 1.0.0
5
+ module Store
6
+ # Get App Details
7
+ # @param String appid The UUID of the Steam Application
8
+ # @see https://wiki.teamfortress.com/wiki/User:RJackson/StorefrontAPI#appdetails
9
+ def self.app_details(appid)
10
+ response = client.get 'appdetails', params: { appids: appid }
11
+ response
12
+ end
13
+
14
+ private
15
+
16
+ def self.client
17
+ build_client '', base_url: Steam::Helpers::STORE_API_BASE_URL
18
+ end
19
+ end
20
+ end
@@ -5,7 +5,7 @@ module Steam
5
5
  # @since 1.0.0
6
6
  module User
7
7
  # Get User's Friend List
8
- # @param [String] steamid
8
+ # @param [String] steamid
9
9
  # @param [String] relationship Relationship filter.
10
10
  # Possibles values: all, friend.
11
11
  # @return [Hash] A hash object resulting from the API call; should
@@ -81,8 +81,6 @@ module Steam
81
81
  response.parse_key('steamid')
82
82
  end
83
83
 
84
- private
85
-
86
84
  def self.client
87
85
  build_client 'ISteamUser'
88
86
  end
@@ -1,4 +1,3 @@
1
- # -*- encoding: utf-8 -*-
2
1
  module Steam
3
2
  # A Ruby DSL for communicating with the Steam Web API.
4
3
  # @see https://developer.valvesoftware.com/wiki/Steam_Web_API
@@ -6,8 +5,8 @@ module Steam
6
5
  module UserStats
7
6
  # Get Global Achievement Percentages for App
8
7
  # @param [Fixnum] appid The ID of the game or application
9
- # @return [Hash] The hash object of information on the global achievements overview of
10
- # a specific game in percentages.
8
+ # @return [Hash] The hash object of information on the global achievements
9
+ # overview of a specific game in percentages.
11
10
  # @see http://wiki.teamfortress.com/wiki/WebAPI/GetGlobalAchievementPercentagesForApp
12
11
  def self.achievement_percentages(appid)
13
12
  response = client.get 'GetGlobalAchievementPercentagesForApp/v2',
@@ -21,12 +20,14 @@ module Steam
21
20
  # @param [Fixnum] appid The ID of the game or application
22
21
  # @param [Hash] params Parameters to pass to the API
23
22
  # @option params [Fixnum] :count Number of stats to get data for.
24
- # @option params [String] :name[0] Names of the stats to get. For more than one value, use
25
- # a parameter for each request. (name[0], name[1], ...) Not all stats are globally
26
- # aggregated. The developer of the game must mark the stat as globally aggregated.
23
+ # @option params [String] :name[0] Names of the stats to get. For more than
24
+ # one value, use a parameter for each request. (name[0], name[1], ...)
25
+ # Not all stats are globally aggregated. The developer of the game must
26
+ # mark the stat as globally aggregated.
27
27
  # @option params [String] :startdate Start date for daily totals
28
28
  # (unix epoch timestamp). (Optional)
29
- # @option params [String] :enddate End date for daily totals (unix epoch timestamp). (Optional)
29
+ # @option params [String] :enddate End date for daily totals (unix epoch
30
+ # timestamp). (Optional)
30
31
  # @return [Hash] A hash containing the API response
31
32
  # @see http://wiki.teamfortress.com/wiki/WebAPI/GetGlobalStatsForGame
32
33
  def self.global_for_game(appid, params: {})
@@ -53,7 +54,7 @@ module Steam
53
54
  # @see http://wiki.teamfortress.com/wiki/WebAPI/GetNumberOfCurrentPlayers
54
55
  def self.player_count(appid)
55
56
  response = client.get 'GetNumberOfCurrentPlayers/v1',
56
- params: { appid: appid }
57
+ params: { appid: appid }
57
58
  response.parse_key('response')
58
59
  .parse_key('player_count')
59
60
  end
@@ -61,8 +62,8 @@ module Steam
61
62
  # Get Player Achievements
62
63
  # @param [Fixnum] steamid 64 bit Steam ID to return Achievements list for.
63
64
  # @param [Fixnum] appid AppID to get achievements for
64
- # @param [String] language Language. If specified, it will return language data for
65
- # the requested language. (Optional)
65
+ # @param [String] language Language. If specified, it will return language
66
+ # data for the requested language. (Optional)
66
67
  # @return [Hash] A hash containing the API response
67
68
  # @see http://wiki.teamfortress.com/wiki/WebAPI/GetPlayerAchievements
68
69
  def self.player_achievements(appid, steamid, language: nil)
@@ -75,7 +76,16 @@ module Steam
75
76
  response
76
77
  end
77
78
 
78
- private
79
+ # Get User Stats for Game
80
+ # @param [Fixnum] appid AppID to get stats for.
81
+ # @param [Fixnum] steamid 64 bit Steam ID to return stats for.
82
+ # @return [Hash] A hash containing the API response.
83
+ # @see https://developer.valvesoftware.com/wiki/Steam_Web_API#GetUserStatsForGame_.28v0002.29
84
+ def self.player_stats(appid, steamid)
85
+ params = { appid: appid, steamid: steamid }
86
+ response = client.get 'GetUserStatsForGame/v2', params: params
87
+ response.parse_key('playerstats')
88
+ end
79
89
 
80
90
  def self.client
81
91
  build_client('ISteamUserStats')
@@ -1,5 +1,4 @@
1
- # -*- encoding: utf-8 -*-
2
1
  # Versioning Info
3
2
  module Steam
4
- VERSION = '1.0.0'
3
+ VERSION = '1.2.0'.freeze
5
4
  end
@@ -1,10 +1,4 @@
1
- require 'coveralls'
2
1
  require 'simplecov'
3
-
4
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
- SimpleCov::Formatter::HTMLFormatter,
6
- Coveralls::SimpleCov::Formatter
7
- ]
8
2
  SimpleCov.start
9
3
 
10
4
  if File::exist? File.join(File.dirname(__FILE__), "secret.rb")
@@ -2,54 +2,73 @@ require 'spec_helper'
2
2
 
3
3
  describe Steam::Apps do
4
4
  describe '.get_all' do
5
- it 'should allow users to look up a list of all apps' do
6
- Steam::Apps.get_all
7
- .should_not be_nil
5
+ let(:result) { Steam::Apps.get_all }
6
+
7
+ it 'returns a list of apps' do
8
+ expect(result).to_not be_nil
9
+ end
10
+
11
+ it 'returns an appid for each game' do
12
+ expect(result.first).to have_key 'appid'
8
13
  end
9
14
 
10
- it 'should allow users to look up a list of all apps' do
11
- game = Steam::Apps.get_all.first
12
- game.should have_key 'appid'
13
- game.should have_key 'name'
15
+ it 'returns a name for each game' do
16
+ expect(result.first).to have_key 'name'
14
17
  end
15
18
  end
16
19
 
17
20
  describe '.get_servers' do
18
- it 'should allow users to look up a list of servers at an ip' do
19
- Steam::Apps.get_servers(addr: '192.168.1.1')
20
- .should_not be_nil
21
+ let(:result) { Steam::Apps.get_servers(addr: '192.168.1.1') }
22
+
23
+ it 'returns a valid response' do
24
+ expect(result).to_not be_nil
21
25
  end
22
26
 
23
- it 'should allow users to look up a list of servers at an ip' do
24
- Steam::Apps.get_servers(addr: '192.168.1.1')
25
- .should == []
27
+ it 'returns an empty array for an ip with no servers' do
28
+ expect(result).to eq([])
26
29
  end
27
30
  end
28
31
 
29
32
  describe '.up_to_date' do
30
- it 'should allow users to look up version info' do
31
- Steam::Apps.up_to_date(appid: 440, version: 10)
32
- .should_not be_nil
33
- end
33
+ context 'when looking up out of date version info' do
34
+ let(:result) { Steam::Apps.up_to_date(appid: 440, version: 10) }
35
+
36
+ it 'does not return a nil response' do
37
+ expect(result).to_not be_nil
38
+ end
34
39
 
35
- it 'should return a false up to date value if the verion is out of date' do
36
- check = Steam::Apps.up_to_date(appid: 440, version: 10)
37
- check['up_to_date'].should be_false
38
- check['version_is_listable'].should be_false
39
- check.should have_key('required_version')
40
- check['message'].should == 'Your server is out of date, please upgrade'
40
+ it "returns a false value for 'up_to_date'" do
41
+ expect(result['up_to_date']).to be_falsey
42
+ end
43
+
44
+ it "returns a false value for 'version_is_listable'" do
45
+ expect(result['version_is_listable']).to be_falsey
46
+ end
47
+
48
+ it 'returns a required_version' do
49
+ expect(result).to have_key('required_version')
50
+ end
51
+
52
+ it 'returns an error message' do
53
+ expect(result['message']).to eq('Your server is out of date, please upgrade')
54
+ end
41
55
  end
42
56
 
43
- it 'should return a positive up to date value if the version is correct' do
44
- current = Steam::Apps.up_to_date(appid: 440, version: 10)['required_version']
45
- check = Steam::Apps.up_to_date(appid: 440, version: current)
46
- check['up_to_date'].should be_true
47
- check['version_is_listable'].should be_true
57
+ context 'when looking up current version info' do
58
+ let(:current) { Steam::Apps.up_to_date(appid: 440, version: 10)['required_version'] }
59
+ let(:check) { Steam::Apps.up_to_date(appid: 440, version: current) }
60
+
61
+ it 'returns a positive up to date value' do
62
+ expect(check['up_to_date']).to be_truthy
63
+ end
64
+
65
+ it 'returns a positive version_is_listable value' do
66
+ expect(check['version_is_listable']).to be_truthy
67
+ end
48
68
  end
49
69
 
50
70
  it 'should capture json errors' do
51
- lambda { Steam::Apps.up_to_date(appid: nil, version: 'foo') }
52
- .should raise_error
71
+ expect { Steam::Apps.up_to_date(appid: nil, version: 'foo') }.to raise_error(Steam::JSONError)
53
72
  end
54
73
  end
55
74
  end
@@ -2,46 +2,42 @@ require 'spec_helper'
2
2
 
3
3
  describe Steam::Economy do
4
4
  describe '.asset_info' do
5
- it 'should allow users to look up a list of all apps' do
6
- Steam::Economy.asset_info(440, params: { class_count: 2,
7
- classid0: 195151,
8
- classid1: 16891096 })
9
- .should_not be_nil
5
+ let(:result) { Steam::Economy.asset_info(440,
6
+ params: { class_count: 2,
7
+ classid0: 195151,
8
+ classid1: 16891096 })}
9
+
10
+ it 'returns data' do
11
+ expect(result).to_not be_nil
10
12
  end
11
13
 
12
- it 'should require class params' do
13
- lambda { Steam::Economy.asset_info(440) }
14
- .should raise_error
14
+ it 'requires class params' do
15
+ expect { Steam::Economy.asset_info(440) }.to raise_error(Steam::JSONError)
15
16
  end
16
17
 
17
- it 'should allow users to query asset info' do
18
- result = Steam::Economy.asset_info(440, params: { class_count: 2,
19
- classid0: 195151,
20
- classid1: 16891096 })
21
- result.should have_key('195151')
22
- result.should have_key('16891096')
18
+ it 'allows users to query asset info' do
19
+ expect(result).to have_key('195151')
20
+ expect(result).to have_key('16891096')
23
21
  end
24
22
  end
25
23
 
26
24
  describe '.asset_prices' do
27
- it 'should allow users to look up a list asset prices' do
28
- Steam::Economy.asset_prices(440)
29
- .should_not be_nil
25
+ let(:result) { Steam::Economy.asset_prices(440) }
26
+
27
+ it 'allows users to look up a list asset prices' do
28
+ expect(result).to_not be_nil
30
29
  end
31
30
 
32
- it 'should allow return a list of assets' do
33
- Steam::Economy.asset_prices(440)
34
- .should have_key('assets')
31
+ it 'returns a list of assets' do
32
+ expect(result).to have_key('assets')
35
33
  end
36
34
 
37
- it 'should allow return a list of asset tags' do
38
- Steam::Economy.asset_prices(440)
39
- .should have_key('tags')
35
+ it 'returns a list of asset tags' do
36
+ expect(result).to have_key('tags')
40
37
  end
41
38
 
42
- it 'should allow return a list of asset tag ids' do
43
- Steam::Economy.asset_prices(440)
44
- .should have_key('tag_ids')
39
+ it 'returns a list of asset tag ids' do
40
+ expect(result).to have_key('tag_ids')
45
41
  end
46
42
  end
47
43
  end
@@ -2,14 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe Steam::News do
4
4
  describe '.get' do
5
- it 'should allow users to look up a list news for an app' do
6
- Steam::News.get(440)
7
- .should_not be_nil
5
+ let(:result) { Steam::News.get(440) }
6
+
7
+ it 'allow users to look up a news list' do
8
+ expect(result).to_not be_nil
8
9
  end
9
10
 
10
- it 'should allow users to look up a list news for an app' do
11
- news = Steam::News.get(440)
12
- news.count.should == 20
11
+ it 'returns the first 20 articles' do
12
+ expect(result.count).to eq(20)
13
13
  end
14
14
  end
15
15
  end
@@ -1,94 +1,106 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Steam::Player do
4
+ let(:playerid) { 76561197993276293 }
5
+
4
6
  describe '.owned_games' do
5
- it 'should allow users to retrieve a list of games' do
6
- Steam::Player.owned_games(76561197993276293)
7
- .should_not be_nil
7
+ let(:result) { Steam::Player.owned_games(playerid) }
8
+
9
+ it 'allows users to retrieve a list of games' do
10
+ expect(result).to_not be_nil
8
11
  end
9
12
 
10
- it 'should allow users to retrieve a list of games' do
11
- Steam::Player.owned_games(76561197993276293)
12
- .should have_key('game_count')
13
+ it 'returns a game_count' do
14
+ expect(result).to have_key('game_count')
13
15
  end
14
16
 
15
- it 'should allow users to retrieve a list of games' do
16
- Steam::Player.owned_games(76561197993276293)
17
- .should have_key('games')
17
+ it 'returns a list of games' do
18
+ expect(result).to have_key('games')
18
19
  end
19
20
  end
20
21
 
21
22
  describe '.recently_played_games' do
22
- it 'should allow users to list a players recent games' do
23
- Steam::Player.recently_played_games(76561197993276293)
24
- .should_not be_nil
23
+ let(:result) { Steam::Player.recently_played_games(playerid) }
24
+
25
+ it 'allows users to list a players recent games' do
26
+ expect(result).to_not be_nil
27
+ end
28
+
29
+ it 'returns total_count' do
30
+ expect(result).to have_key('total_count')
31
+ end
32
+
33
+ it 'returns the list of games' do
34
+ expect(result).to have_key('games')
25
35
  end
26
36
 
27
- it 'should allow users to list a players recent games' do
28
- Steam::Player.recently_played_games(76561197993276293)
29
- .should have_key 'total_count'
37
+ it 'returns the recent playtime for games' do
38
+ expect(result['games'].first).to have_key('playtime_2weeks')
30
39
  end
31
40
 
32
- it 'should allow users to list a players recent games' do
33
- Steam::Player.recently_played_games(76561197993276293)
34
- .should have_key 'games'
41
+ it 'returns the full playtime for games' do
42
+ expect(result['games'].first).to have_key('playtime_forever')
35
43
  end
36
44
  end
37
45
 
38
46
  describe '.steam_level' do
39
- it 'should allow users to retrieve a users steam level' do
40
- Steam::Player.steam_level(76561197993276293)
41
- .should_not be_nil
47
+ let(:result) { Steam::Player.steam_level(playerid) }
48
+
49
+ it 'allows users to retrieve a users steam level' do
50
+ expect(result).to_not be_nil
42
51
  end
43
52
 
44
- it 'should allow users to retrieve a users steam level' do
45
- Steam::Player.steam_level(76561197993276293)
46
- .should be_a(Fixnum)
53
+ it 'returns the level number' do
54
+ expect(result).to be_a(Integer)
47
55
  end
48
56
  end
49
57
 
50
58
  describe '.badges' do
51
- it 'should allow a user to retrieve badges for a player' do
52
- Steam::Player.badges(76561197993276293)
53
- .should_not be_nil
59
+ let(:result) { Steam::Player.badges(playerid) }
60
+
61
+ it 'allows a user to retrieve badges for a player' do
62
+ expect(result).to_not be_nil
63
+ end
64
+
65
+ it 'returns a list of badges' do
66
+ expect(result).to have_key('badges')
54
67
  end
55
68
 
56
- it 'should allow a user to retrieve badges for a player' do
57
- Steam::Player.badges(76561197993276293)
58
- .should have_key 'badges'
69
+ it 'returns the player level' do
70
+ expect(result).to have_key('player_level')
59
71
  end
60
72
 
61
- it 'should allow a user to retrieve badges for a player' do
62
- Steam::Player.badges(76561197993276293)
63
- .should have_key 'player_level'
73
+ it 'returns the player level as a number' do
74
+ expect(result['player_level']).to be_a(Integer)
64
75
  end
65
76
 
66
- it 'should allow a user to retrieve badges for a player' do
67
- Steam::Player.badges(76561197993276293)
68
- .should have_key 'player_xp'
77
+ it 'returns the players current xp' do
78
+ expect(result).to have_key('player_xp')
69
79
  end
70
80
 
71
- it 'should allow a user to retrieve badges for a player' do
72
- Steam::Player.badges(76561197993276293)
73
- .should have_key 'player_xp_needed_current_level'
81
+ it 'returns the xp a player needed to reach thier current level' do
82
+ expect(result).to have_key('player_xp_needed_current_level')
74
83
  end
75
84
 
76
- it 'should allow a user to retrieve badges for a player' do
77
- Steam::Player.badges(76561197993276293)
78
- .should have_key 'player_xp_needed_to_level_up'
85
+ it 'returns the xp a player needs to reach next level' do
86
+ expect(result).to have_key('player_xp_needed_to_level_up')
79
87
  end
80
88
  end
81
89
 
82
90
  describe '.community_badge_progress' do
83
- it 'should allow a user to retrieve community badge info for a player' do
84
- Steam::Player.community_badge_progress(76561197993276293)
85
- .should_not be_nil
91
+ let(:result) { Steam::Player.community_badge_progress(playerid) }
92
+
93
+ it 'allows a user to retrieve community badge info for a player' do
94
+ expect(result).to_not be_nil
95
+ end
96
+
97
+ it 'returns a list of quests' do
98
+ expect(result).to be_a(Array)
86
99
  end
87
100
 
88
- it 'should allow a user to retrieve community badge info for a player' do
89
- quest = Steam::Player.community_badge_progress(76561197993276293).first
90
- quest.should have_key 'questid'
91
- quest.should have_key 'completed'
101
+ it 'returns a list of quests with ids and completion status' do
102
+ expect(result.first).to have_key('questid')
103
+ expect(result.first).to have_key('completed')
92
104
  end
93
105
  end
94
106
  end