steam_api 0.1.0

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.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +31 -0
  7. data/Rakefile +2 -0
  8. data/lib/steam_api/client.rb +47 -0
  9. data/lib/steam_api/i_player_service.rb +65 -0
  10. data/lib/steam_api/i_steam_user.rb +53 -0
  11. data/lib/steam_api/i_steam_user_stats.rb +52 -0
  12. data/lib/steam_api/urls.rb +116 -0
  13. data/lib/steam_api/version.rb +4 -0
  14. data/lib/steam_api.rb +14 -0
  15. data/spec/fixtures/vcr_cassettes/client_get.yml +38 -0
  16. data/spec/fixtures/vcr_cassettes/get_badges.yml +77 -0
  17. data/spec/fixtures/vcr_cassettes/get_badges_private.yml +38 -0
  18. data/spec/fixtures/vcr_cassettes/get_community_badge_progress.yml +64 -0
  19. data/spec/fixtures/vcr_cassettes/get_community_badge_progress_private.yml +64 -0
  20. data/spec/fixtures/vcr_cassettes/get_community_badge_progress_specific_badge.yml +64 -0
  21. data/spec/fixtures/vcr_cassettes/get_friend_list_not_found.yml +46 -0
  22. data/spec/fixtures/vcr_cassettes/get_friend_list_private.yml +39 -0
  23. data/spec/fixtures/vcr_cassettes/get_friend_list_public.yml +92 -0
  24. data/spec/fixtures/vcr_cassettes/get_global_achievement_percentages_for_app.yml +230 -0
  25. data/spec/fixtures/vcr_cassettes/get_global_achievement_percentages_for_app_not_found.yml +39 -0
  26. data/spec/fixtures/vcr_cassettes/get_number_of_current_players.yml +37 -0
  27. data/spec/fixtures/vcr_cassettes/get_number_of_current_players_not_found.yml +36 -0
  28. data/spec/fixtures/vcr_cassettes/get_owned_games.yml +261 -0
  29. data/spec/fixtures/vcr_cassettes/get_owned_games_all_args.yml +1302 -0
  30. data/spec/fixtures/vcr_cassettes/get_owned_games_include_appinfo.yml +1286 -0
  31. data/spec/fixtures/vcr_cassettes/get_owned_games_include_played_free_games.yml +264 -0
  32. data/spec/fixtures/vcr_cassettes/get_owned_games_private.yml +38 -0
  33. data/spec/fixtures/vcr_cassettes/get_player_achievements.yml +205 -0
  34. data/spec/fixtures/vcr_cassettes/get_player_achievements_game_no_stats.yml +37 -0
  35. data/spec/fixtures/vcr_cassettes/get_player_achievements_private.yml +37 -0
  36. data/spec/fixtures/vcr_cassettes/get_player_achievements_user_not_found.yml +37 -0
  37. data/spec/fixtures/vcr_cassettes/get_player_bans_not_found.yml +36 -0
  38. data/spec/fixtures/vcr_cassettes/get_player_bans_public.yml +38 -0
  39. data/spec/fixtures/vcr_cassettes/get_player_bans_public_private.yml +40 -0
  40. data/spec/fixtures/vcr_cassettes/get_player_summaries_multiple.yml +50 -0
  41. data/spec/fixtures/vcr_cassettes/get_player_summaries_not_found.yml +36 -0
  42. data/spec/fixtures/vcr_cassettes/get_player_summaries_single.yml +44 -0
  43. data/spec/fixtures/vcr_cassettes/get_recently_played_games.yml +47 -0
  44. data/spec/fixtures/vcr_cassettes/get_recently_played_games_count.yml +44 -0
  45. data/spec/fixtures/vcr_cassettes/get_recently_played_games_private.yml +38 -0
  46. data/spec/fixtures/vcr_cassettes/get_schema_for_game.yml +1205 -0
  47. data/spec/fixtures/vcr_cassettes/get_schema_for_game_not_found.yml +39 -0
  48. data/spec/fixtures/vcr_cassettes/get_steam_level.yml +38 -0
  49. data/spec/fixtures/vcr_cassettes/get_steam_level_private.yml +38 -0
  50. data/spec/fixtures/vcr_cassettes/get_user_group_list_not_found.yml +46 -0
  51. data/spec/fixtures/vcr_cassettes/get_user_group_list_private.yml +37 -0
  52. data/spec/fixtures/vcr_cassettes/get_user_group_list_public.yml +39 -0
  53. data/spec/fixtures/vcr_cassettes/get_user_stats_for_game.yml +407 -0
  54. data/spec/fixtures/vcr_cassettes/get_user_stats_for_game_game_not_found.yml +39 -0
  55. data/spec/fixtures/vcr_cassettes/get_user_stats_for_game_private.yml +46 -0
  56. data/spec/fixtures/vcr_cassettes/get_user_stats_for_game_user_not_found.yml +39 -0
  57. data/spec/fixtures/vcr_cassettes/resolve_vanity_url_not_found.yml +36 -0
  58. data/spec/fixtures/vcr_cassettes/resolve_vanity_url_private.yml +37 -0
  59. data/spec/fixtures/vcr_cassettes/resolve_vanity_url_public.yml +37 -0
  60. data/spec/spec_helper.rb +98 -0
  61. data/spec/steam_api/client_spec.rb +30 -0
  62. data/spec/steam_api/i_player_service_spec.rb +127 -0
  63. data/spec/steam_api/i_steam_user_spec.rb +163 -0
  64. data/spec/steam_api/i_steam_user_stats_spec.rb +143 -0
  65. data/spec/steam_api/urls_spec.rb +36 -0
  66. data/spec/steam_api/version_spec.rb +7 -0
  67. data/spec/steam_api_spec.rb +0 -0
  68. data/steam_api.gemspec +28 -0
  69. metadata +263 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 063ef00144fd07b6dd09f40dfe93e96f30ddc461
4
+ data.tar.gz: 3b6ad37f1b1057ccec851d4322bcfb432d1ea880
5
+ SHA512:
6
+ metadata.gz: f26081b62e0ae8cdc4b5138d66c0d9c9129404e867b13e5b80e3071a9261f06a26287072ba28e62dcc4c284597c3108d2f3d93d3060e1e57a00733bac4d61fe7
7
+ data.tar.gz: 19ba4f3b1fa7f9899c6955ebbed5ff14a078eb7ecc42bcba12e1d6a2d4e4d15dc53455e1fd250e5eed6febc20be208ec02593fe9a9309aa6c1c2504a954aaf2c
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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in steam_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Yusef Ouda
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # SteamApi
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'steam_api'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install steam_api
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/steam_api/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,47 @@
1
+ module SteamApi
2
+ # This Client class is to be used as the entry point to the rest of the program. A client object should be initialized
3
+ # and with that object comes the ability to use any of the methods which call the Steam API.
4
+ class Client
5
+ include SteamApi::ISteamUser
6
+ include SteamApi::ISteamUserStats
7
+ include SteamApi::IPlayerService
8
+
9
+ attr_reader :api_key
10
+ # This method is the entry point to use the API. It is initialized with an API key. Only one instance of this
11
+ # class should exist to interface with the API
12
+ # @param api_key [String] The API key for Steam API (can be gotten from https://steamcommunity.com/dev/apikey)
13
+ def initialize(api_key)
14
+ @api_key = api_key
15
+ end
16
+
17
+ # This method is a helper method which many other methods rely on to call the Steam API
18
+ # @param url [String] This should be the base url for the desired API call
19
+ # @param key_needed [Boolean] This is a boolean value which is used to decide
20
+ # whether a specific API call needs to have a key interpolated into the URL
21
+ # @return [Hash] The return value is a hash, but its contents depends on the success
22
+ # or lack thereof, of the api call. If it was successful, it returns the JSON as a
23
+ # hash. Otherwise, it returns a hash with an error message.
24
+ def get(url, key_needed: true)
25
+ url = add_key url if key_needed
26
+ begin
27
+ uri = URI(url)
28
+ response = Net::HTTP.get_response(uri)
29
+ parsed = JSON.parse(response.body)
30
+ return parsed
31
+ rescue JSON::ParserError
32
+ return {
33
+ "error" => "There was an internal server error."
34
+ }
35
+ rescue URI::InvalidURIError
36
+ return {
37
+ "error" => "bad URI(is not URI?)"
38
+ }
39
+ end
40
+ end
41
+
42
+ private
43
+ def add_key(url)
44
+ url + "&key=" + @api_key
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,65 @@
1
+ module SteamApi
2
+ # This module is for interacting with the IPlayerService interface of the Steam Web API.
3
+ # More information about this interface can be found at https://wiki.teamfortress.com/wiki/WebAPI
4
+ module IPlayerService
5
+ # Gets a list of users recently played games.
6
+ # @param userid [String] A user's steam id 64
7
+ # @param count [Fixnum] The number of games to return
8
+ # @return [Hash] Contains a hash which has information about a users recently played games (if the profile is public)
9
+ # More information can be found at https://wiki.teamfortress.com/wiki/WebAPI/GetRecentlyPlayedGames
10
+ def get_recently_played_games(userid, count=0)
11
+ url = SteamApi::Urls.recently_played_games(userid, count)
12
+ response = get(url, key_needed: true)
13
+ end
14
+
15
+ # Gets a list of all the users owned games.
16
+ # @param userid [String] A user's steam id 64
17
+ # @param include_appinfo [Boolean] (Optional) A boolean indicating whether to include information about the game (name, pictures, playtime)
18
+ # @param include_played_free_games [Boolean] (Optional) A boolean indicating whether to include free to play games
19
+ # @return [Hash] Contains a hash which has information about the list of users games (if the profile is public)
20
+ # More information can be found at https://wiki.teamfortress.com/wiki/WebAPI/GetOwnedGames
21
+ def get_owned_games(userid, include_appinfo: false, include_played_free_games: false)
22
+ include_appinfo = bool_to_int(include_appinfo)
23
+ include_played_free_games = bool_to_int(include_played_free_games)
24
+ url = SteamApi::Urls.owned_games(userid, include_appinfo, include_played_free_games)
25
+ response = get(url, key_needed: true)
26
+ end
27
+
28
+ # Gets a users Steam level
29
+ # @param userid [String] A user's steam id 64
30
+ # @return [Hash] Contains a hash which has the users Steam level
31
+ # More information can be found at https://wiki.teamfortress.com/wiki/WebAPI/GetSteamLevel
32
+ def get_steam_level(userid)
33
+ url = SteamApi::Urls.steam_level(userid)
34
+ response = get(url, key_needed: true)
35
+ end
36
+
37
+ # Gets info about a single users badge completion
38
+ # @param userid [String] A user's steam id 64
39
+ # @return [Hash] Contains a hash which has the users badges
40
+ # More information can be found at https://wiki.teamfortress.com/wiki/WebAPI/GetBadges
41
+ def get_badges(userid)
42
+ url = SteamApi::Urls.badges(userid)
43
+ response = get(url, key_needed: true)
44
+ end
45
+
46
+ # Gets info about a single users progress towards community badges
47
+ # @param userid [String] A user's steam id 64
48
+ # @param badge_id [String] (Optional) A specific badge id to look for
49
+ # @return [Hash] Contains a hash which has the users progress
50
+ # More information can be found at https://wiki.teamfortress.com/wiki/WebAPI/GetCommunityBadgeProgress
51
+ def get_community_badge_progress(userid, badge_id: 0)
52
+ url = SteamApi::Urls.community_badge_progress(userid, badge_id)
53
+ response = get(url, key_needed: true)
54
+ end
55
+
56
+ private
57
+ # A method to map a boolean value to an integer
58
+ # @param bool [Boolean] A boolean value
59
+ # @return [Fixnum] The mapped-to Fixnum
60
+ def bool_to_int(bool)
61
+ return 1 if bool
62
+ return 0
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,53 @@
1
+ module SteamApi
2
+ # This module is for interacting with the ISteamUser interface of the Steam Web API.
3
+ # More information about this interface can be found at https://wiki.teamfortress.com/wiki/WebAPI
4
+ module ISteamUser
5
+ # Gets a Steam user's friends list.
6
+ # @param steamid [String] The users steam_id_64
7
+ # @return [Hash] Contains a hash containing friends list if user exists.
8
+ # In the case the user has a private profile, a hash will still be returned but it will empty
9
+ # More information can be found at https://wiki.teamfortress.com/wiki/WebAPI/GetFriendList
10
+ def get_friend_list(steamid, relationship="friend")
11
+ url = SteamApi::Urls.friend_list(steamid, relationship)
12
+ response = get(url, key_needed: true)
13
+ end
14
+
15
+ # Gets information about a Steam user (or users) ban history.
16
+ # @param steamids [*String] The user (or users) steam_id_64.
17
+ # @return [Hash] Contains a hash with information about the users ban history.
18
+ # More information can be found at https://wiki.teamfortress.com/wiki/WebAPI/GetPlayerBans
19
+ def get_player_bans(*steamids)
20
+ stringified_ids = steamids.join(',')
21
+ url = SteamApi::Urls.player_bans(stringified_ids)
22
+ response = get(url, key_needed: true)
23
+ end
24
+
25
+ # Gets player summary(or summaries) about a Steam user (or users).
26
+ # @param steamids [*String] The user (or users) steam_id_64.
27
+ # @return [Hash] Contains a hash with player summaries for each passed in ID.
28
+ # More information can be found at https://wiki.teamfortress.com/wiki/WebAPI/GetPlayerSummaries
29
+ def get_player_summaries(*steamids)
30
+ stringified_ids = steamids.join(',')
31
+ url = SteamApi::Urls.player_summaries(stringified_ids)
32
+ response = get(url, key_needed: true)
33
+ end
34
+
35
+ # Gets a list of users groups if the user has a public profile.
36
+ # @param steamid [String] The user's steam_id_64
37
+ # @return [Hash] Contains a hash with a list of the users groups
38
+ # More information can be found at https://wiki.teamfortress.com/wiki/WebAPI/GetUserGroupList
39
+ def get_user_group_list(steamid)
40
+ url = SteamApi::Urls.user_group_list(steamid)
41
+ response = get(url, key_needed: true)
42
+ end
43
+
44
+ # Gets a users steam_id_64 from vanity url.
45
+ # @param vanity_url [String] Contains the vanity URL of a user
46
+ # @return [Hash] Contains a hash which has the steam_id_64 of the given user (if it exists)
47
+ # More information can be found at https://wiki.teamfortress.com/wiki/WebAPI/ResolveVanityURL
48
+ def resolve_vanity_url(vanity_url)
49
+ url = SteamApi::Urls.vanity_url(vanity_url)
50
+ response = get(url, key_needed: true)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,52 @@
1
+ module SteamApi
2
+ # This module is for interacting with the ISteamUserStats interface of the Steam Web API.
3
+ # More information about this interface can be found at https://wiki.teamfortress.com/wiki/WebAPI
4
+ module ISteamUserStats
5
+ # Gets information about achievement percentages for a certain app.
6
+ # @param gameid [String] A specific Steam app id
7
+ # @return [Hash] Contains a hash with information about percentage completion
8
+ # More information can be found at https://wiki.teamfortress.com/wiki/WebAPI/GetGlobalAchievementPercentagesForApp
9
+ def get_global_achievement_percentages_for_app(gameid)
10
+ url = SteamApi::Urls.global_achievement_percentages_for_app(gameid)
11
+ response = get(url, key_needed: false)
12
+ end
13
+
14
+ # Gets information about number of current players for a certain app.
15
+ # @param gameid [String] A specific Steam app id
16
+ # @return [Hash] Contains a hash with information about number of current players
17
+ # More information can be found at https://wiki.teamfortress.com/wiki/WebAPI/GetNumberOfCurrentPlayers
18
+ def get_number_of_current_players(gameid)
19
+ url = SteamApi::Urls.number_of_current_players(gameid)
20
+ response = get(url, key_needed: false)
21
+ end
22
+
23
+ # Gets information about a players achievements for a specific app.
24
+ # @param userid [String] A specific user's steam id 64
25
+ # @param gameid [String] A specific game's steam id 64
26
+ # @return [Hash] Contains a hash with information about the achievement completion if the user and game exist. The user must also be public
27
+ # More information can be found at https://wiki.teamfortress.com/wiki/WebAPI/GetPlayerAchievements
28
+ def get_player_achievements(userid, gameid)
29
+ url = SteamApi::Urls.player_achievements(userid, gameid)
30
+ response = get(url, key_needed: true)
31
+ end
32
+
33
+ # Gets information about the schema for a game for a specific id.
34
+ # @param gameid [String] A specific game's steam id 64
35
+ # @return [Hash] Contains a hash with information about the schema for a game. (if the game was found)
36
+ # More information can be found at https://wiki.teamfortress.com/wiki/WebAPI/GetSchemaForGame
37
+ def get_schema_for_game(gameid)
38
+ url = SteamApi::Urls.schema_for_game(gameid)
39
+ response = get(url, key_needed: true)
40
+ end
41
+
42
+ # Gets information about the users stats for a certain game
43
+ # @param userid [String] A specific user's steam id 64
44
+ # @param gameid [String] A specific game's steam id 64
45
+ # @return [Hash] Contains a hash with information about the users stats for a game (if the game was found and profile is public)
46
+ # More information can be found at https://wiki.teamfortress.com/wiki/WebAPI/GetUserStatsForGame
47
+ def get_user_stats_for_game(userid, gameid)
48
+ url = SteamApi::Urls.user_stats_for_game(userid, gameid)
49
+ response = get(url, key_needed: true)
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,116 @@
1
+ module SteamApi
2
+ # This module is a container for all of the different URL's for the Steam Web API
3
+ module Urls
4
+ # A helper method which gets the base url for friend list API call
5
+ # @param id [String] The users steam_id_64
6
+ # @param relationship [String] The given relationship to look for (either friend or all)
7
+ # @return [String] An interpolated string for the API call to get a users friends list.
8
+ # It contains the users ID, but not the API key
9
+ def self.friend_list(id, relationship)
10
+ "http://API.steampowered.com/ISteamUser/GetFriendList/v0001/?steamid=" + id + "&relationship=" + relationship
11
+ end
12
+
13
+ # A helper method which gets the base url for API call to get info about player bans
14
+ # @param ids [String] A string containing a single steam_id_64 or multiple comma delimited steam_id_64s
15
+ # @return [String] An interpolated string for the API call (without the API key)
16
+ def self.player_bans(ids)
17
+ "http://api.steampowered.com/ISteamUser/GetPlayerBans/v1?&steamids=" + ids
18
+ end
19
+
20
+ # A helper method which gets the base url for API call to get info about player summaries
21
+ # @param ids [String] A string containing a single steam_id_64 or multiple comma delimited steam_id_64s
22
+ # @return [String] An interpolated string for the API call (without the API key)
23
+ def self.player_summaries(ids)
24
+ "http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?&steamids=" + ids
25
+ end
26
+
27
+ # A helper method which gets the base url for API call to get info about a players groups
28
+ # @param id [String] A single users steam_id_64
29
+ # @return [String] An interpolated string for the API call (without the API key)
30
+ def self.user_group_list(id)
31
+ "http://api.steampowered.com/ISteamUser/GetUserGroupList/v1?steamid=" + id
32
+ end
33
+
34
+ # A helper method which gets the base url for API call to get a users steam_id_64
35
+ # @param vanity_url [String] A single users vanity url
36
+ # @return [String] An interpolated string for the API call (without the API key)
37
+ def self.vanity_url(vanity_url)
38
+ "http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?&vanityurl=" + vanity_url
39
+ end
40
+
41
+ # A helper method which gets the base url for API call to get global achievement percentages for app
42
+ # @param id [String] A single Steam app id
43
+ # @return [String] An interpolated string for the API call (without the API key)
44
+ def self.global_achievement_percentages_for_app(id)
45
+ "http://api.steampowered.com/ISteamUserStats/GetGlobalAchievementPercentagesForApp/v0002/?&gameid=" + id
46
+ end
47
+
48
+ # A helper method which gets the base url for API call to get current number of players for an app
49
+ # @param id [String] A single Steam app id
50
+ # @return [String] An interpolated string for the API call (without the API key)
51
+ def self.number_of_current_players(id)
52
+ "http://api.steampowered.com/ISteamUserStats/GetNumberOfCurrentPlayers/v1/?appid=" + id
53
+ end
54
+
55
+ # A helper method which gets the base url for API call to get achievement completion for a player and app
56
+ # @param userid [String] A single user steam id 64
57
+ # @param appid [String] A single Steam app id
58
+ # @return [String] An interpolated string for the API call (without the API key)
59
+ def self.player_achievements(userid, appid)
60
+ "http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v1/?&steamid=" + userid + '&appid=' + appid
61
+ end
62
+
63
+ # A helper method which gets the base url for API call to get a schema for a game
64
+ # @param appid [String] A single game steam id
65
+ # @return [String] An interpolated string for the API call (without the API key)
66
+ def self.schema_for_game(appid)
67
+ "http://api.steampowered.com/ISteamUserStats/GetSchemaForGame/v2/?&appid=" + appid
68
+ end
69
+
70
+ # A helper method which gets the base url for API call to get users stats for a game
71
+ # @param userid [String] A single user id 64
72
+ # @param appid [String] A single game steam id
73
+ # @return [String] An interpolated string for the API call (without the API key)
74
+ def self.user_stats_for_game(userid, appid)
75
+ "http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v2/?&appid=" + appid + "&steamid=" + userid
76
+ end
77
+
78
+ # A helper method which gets the base url for API call to get info about users recently played games
79
+ # @param userid [String] A single user id 64
80
+ # @param count [Fixnum] The max number of games to find
81
+ # @return [String] An interpolated string for the API call (without the API key)
82
+ def self.recently_played_games(userid, count)
83
+ "http://api.steampowered.com/IPlayerService/GetRecentlyPlayedGames/v1?&steamid=" + userid + "&count=#{count}"
84
+ end
85
+
86
+ # A helper method which gets the base url for API call to get a list of users owned games
87
+ # @param userid [String] A single user id 64
88
+ # @param include_appinfo [Boolean] (Optional) A boolean indicating whether to include information about the game (name, pictures, playtime)
89
+ # @param include_played_free_games [Boolean] (Optional) A boolean indicating whether to include free to play games
90
+ # @return [String] An interpolated string for the API call (without the API key)
91
+ def self.owned_games(userid, include_appinfo, include_played_free_games)
92
+ "http://api.steampowered.com/IPlayerService/GetOwnedGames/v1?&steamid=" + userid + "&include_played_free_games=#{include_played_free_games}&include_appinfo=#{include_appinfo}"
93
+ end
94
+
95
+ # A helper method which gets the base url for API call to get a users Steam level
96
+ # @param userid [String] A single user Steam id 64
97
+ # @return [String] An interpolated string for the API call (without the API key)
98
+ def self.steam_level(userid)
99
+ "http://api.steampowered.com/IPlayerService/GetSteamLevel/v1?&steamid=" + userid
100
+ end
101
+
102
+ # A helper method which gets the base url for API call to get users badges
103
+ # @param userid [String] A single user Steam id 64
104
+ # @return [String] An interpolated string for the API call (without the API key)
105
+ def self.badges(userid)
106
+ "http://api.steampowered.com/IPlayerService/GetBadges/v1?&steamid=" + userid
107
+ end
108
+
109
+ # A helper method which gets the base url for API call to get users badges
110
+ # @param userid [String] A single user Steam id 64
111
+ # @return [String] An interpolated string for the API call (without the API key)
112
+ def self.community_badge_progress(userid, badge_id)
113
+ "http://api.steampowered.com/IPlayerService/GetCommunityBadgeProgress/v1?&steamid=" + userid + "&badgeid=#{badge_id}"
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,4 @@
1
+ module SteamApi
2
+ # The current version
3
+ VERSION = "0.1.0"
4
+ end
data/lib/steam_api.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "steam_api/version"
2
+ require "steam_api/i_steam_user"
3
+ require "steam_api/i_steam_user_stats"
4
+ require "steam_api/i_player_service"
5
+ require "steam_api/client"
6
+ require "steam_api/urls"
7
+ require "net/http"
8
+ require "pry-byebug"
9
+ require "json"
10
+
11
+ # The base module for all other modules and classes
12
+ module SteamApi
13
+
14
+ end
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.steampowered.com/ISteamUser/GetPlayerBans/v1?key=<API_KEY>&steamids=76561198002572492
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - '*/*'
14
+ User-Agent:
15
+ - Ruby
16
+ Host:
17
+ - api.steampowered.com
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Date:
24
+ - Thu, 30 Oct 2014 17:15:01 GMT
25
+ Expires:
26
+ - Thu, 30 Oct 2014 17:15:01 GMT
27
+ Content-Type:
28
+ - application/json; charset=UTF-8
29
+ Content-Length:
30
+ - '192'
31
+ body:
32
+ encoding: UTF-8
33
+ string: "{\n\t\"players\": [\n\t\t{\n\t\t\t\"SteamId\": \"76561198002572492\",\n\t\t\t\"CommunityBanned\":
34
+ false,\n\t\t\t\"VACBanned\": false,\n\t\t\t\"NumberOfVACBans\": 0,\n\t\t\t\"DaysSinceLastBan\":
35
+ 0,\n\t\t\t\"EconomyBan\": \"none\"\n\t\t}\n\t]\n\t\n}"
36
+ http_version:
37
+ recorded_at: Thu, 30 Oct 2014 17:15:03 GMT
38
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,77 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.steampowered.com/IPlayerService/GetBadges/v1?key=<API_KEY>&steamid=76561197995163285
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - '*/*'
14
+ User-Agent:
15
+ - Ruby
16
+ Host:
17
+ - api.steampowered.com
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ X-Eresult:
24
+ - '1'
25
+ Date:
26
+ - Thu, 30 Oct 2014 17:15:29 GMT
27
+ Expires:
28
+ - Thu, 30 Oct 2014 17:15:29 GMT
29
+ Content-Type:
30
+ - application/json; charset=UTF-8
31
+ Content-Length:
32
+ - '2495'
33
+ body:
34
+ encoding: UTF-8
35
+ string: "{\n\t\"response\": {\n\t\t\"badges\": [\n\t\t\t{\n\t\t\t\t\"badgeid\":
36
+ 16,\n\t\t\t\t\"level\": 51,\n\t\t\t\t\"completion_time\": 1404061200,\n\t\t\t\t\"xp\":
37
+ 150,\n\t\t\t\t\"scarcity\": 32668\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"badgeid\":
38
+ 2,\n\t\t\t\t\"level\": 2,\n\t\t\t\t\"completion_time\": 1393211265,\n\t\t\t\t\"xp\":
39
+ 200,\n\t\t\t\t\"scarcity\": 2041165\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"badgeid\":
40
+ 15,\n\t\t\t\t\"level\": 2,\n\t\t\t\t\"completion_time\": 1380128986,\n\t\t\t\t\"xp\":
41
+ 150,\n\t\t\t\t\"scarcity\": 421848\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"badgeid\":
42
+ 8,\n\t\t\t\t\"level\": 1,\n\t\t\t\t\"completion_time\": 1356749036,\n\t\t\t\t\"xp\":
43
+ 100,\n\t\t\t\t\"scarcity\": 741879\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"badgeid\":
44
+ 7,\n\t\t\t\t\"level\": 3,\n\t\t\t\t\"completion_time\": 1342125512,\n\t\t\t\t\"xp\":
45
+ 100,\n\t\t\t\t\"scarcity\": 261763\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"badgeid\":
46
+ 6,\n\t\t\t\t\"level\": 1,\n\t\t\t\t\"completion_time\": 1324883068,\n\t\t\t\t\"xp\":
47
+ 51,\n\t\t\t\t\"scarcity\": 2746859\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"badgeid\":
48
+ 13,\n\t\t\t\t\"level\": 223,\n\t\t\t\t\"completion_time\": 1198539183,\n\t\t\t\t\"xp\":
49
+ 468,\n\t\t\t\t\"scarcity\": 419910\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"badgeid\":
50
+ 1,\n\t\t\t\t\"level\": 6,\n\t\t\t\t\"completion_time\": 1198539183,\n\t\t\t\t\"xp\":
51
+ 300,\n\t\t\t\t\"scarcity\": 21469632\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"badgeid\":
52
+ 1,\n\t\t\t\t\"appid\": 245070,\n\t\t\t\t\"level\": 2,\n\t\t\t\t\"completion_time\":
53
+ 1374423868,\n\t\t\t\t\"xp\": 200,\n\t\t\t\t\"communityitemid\": \"81812935\",\n\t\t\t\t\"border_color\":
54
+ 0,\n\t\t\t\t\"scarcity\": 269923\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"badgeid\":
55
+ 1,\n\t\t\t\t\"appid\": 224480,\n\t\t\t\t\"level\": 1,\n\t\t\t\t\"completion_time\":
56
+ 1393210832,\n\t\t\t\t\"xp\": 100,\n\t\t\t\t\"communityitemid\": \"586935365\",\n\t\t\t\t\"border_color\":
57
+ 0,\n\t\t\t\t\"scarcity\": 15254\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"badgeid\": 1,\n\t\t\t\t\"appid\":
58
+ 730,\n\t\t\t\t\"level\": 5,\n\t\t\t\t\"completion_time\": 1393223879,\n\t\t\t\t\"xp\":
59
+ 500,\n\t\t\t\t\"communityitemid\": \"586937296\",\n\t\t\t\t\"border_color\":
60
+ 0,\n\t\t\t\t\"scarcity\": 469278\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"badgeid\":
61
+ 1,\n\t\t\t\t\"appid\": 219890,\n\t\t\t\t\"level\": 1,\n\t\t\t\t\"completion_time\":
62
+ 1393212575,\n\t\t\t\t\"xp\": 100,\n\t\t\t\t\"communityitemid\": \"586964497\",\n\t\t\t\t\"border_color\":
63
+ 0,\n\t\t\t\t\"scarcity\": 36592\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"badgeid\": 1,\n\t\t\t\t\"appid\":
64
+ 218060,\n\t\t\t\t\"level\": 1,\n\t\t\t\t\"completion_time\": 1393223411,\n\t\t\t\t\"xp\":
65
+ 100,\n\t\t\t\t\"communityitemid\": \"587109828\",\n\t\t\t\t\"border_color\":
66
+ 0,\n\t\t\t\t\"scarcity\": 24579\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"badgeid\": 1,\n\t\t\t\t\"appid\":
67
+ 303700,\n\t\t\t\t\"level\": 5,\n\t\t\t\t\"completion_time\": 1403970168,\n\t\t\t\t\"xp\":
68
+ 500,\n\t\t\t\t\"communityitemid\": \"879428508\",\n\t\t\t\t\"border_color\":
69
+ 0,\n\t\t\t\t\"scarcity\": 116562\n\t\t\t},\n\t\t\t{\n\t\t\t\t\"badgeid\":
70
+ 1,\n\t\t\t\t\"appid\": 35140,\n\t\t\t\t\"level\": 1,\n\t\t\t\t\"completion_time\":
71
+ 1404513401,\n\t\t\t\t\"xp\": 100,\n\t\t\t\t\"communityitemid\": \"943525488\",\n\t\t\t\t\"border_color\":
72
+ 0,\n\t\t\t\t\"scarcity\": 114081\n\t\t\t}\n\t\t]\n\t\t,\n\t\t\"player_xp\":
73
+ 3119,\n\t\t\"player_level\": 20,\n\t\t\"player_xp_needed_to_level_up\": 181,\n\t\t\"player_xp_needed_current_level\":
74
+ 3000\n\t}\n}"
75
+ http_version:
76
+ recorded_at: Thu, 30 Oct 2014 17:15:31 GMT
77
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.steampowered.com/IPlayerService/GetBadges/v1?key=<API_KEY>&steamid=76561198002572492
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - '*/*'
14
+ User-Agent:
15
+ - Ruby
16
+ Host:
17
+ - api.steampowered.com
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ X-Eresult:
24
+ - '15'
25
+ Date:
26
+ - Thu, 30 Oct 2014 17:15:29 GMT
27
+ Expires:
28
+ - Thu, 30 Oct 2014 17:15:29 GMT
29
+ Content-Type:
30
+ - application/json; charset=UTF-8
31
+ Content-Length:
32
+ - '22'
33
+ body:
34
+ encoding: UTF-8
35
+ string: "{\n\t\"response\": {\n\n\t}\n}"
36
+ http_version:
37
+ recorded_at: Thu, 30 Oct 2014 17:15:31 GMT
38
+ recorded_with: VCR 2.9.3