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
@@ -0,0 +1,37 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/?key=<API_KEY>&vanityurl=youda
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:39 GMT
25
+ Expires:
26
+ - Thu, 30 Oct 2014 17:15:39 GMT
27
+ Content-Type:
28
+ - application/json; charset=UTF-8
29
+ Content-Length:
30
+ - '70'
31
+ body:
32
+ encoding: UTF-8
33
+ string: "{\n\t\"response\": {\n\t\t\"steamid\": \"76561197995163285\",\n\t\t\"success\":
34
+ 1\n\t}\n}"
35
+ http_version:
36
+ recorded_at: Thu, 30 Oct 2014 17:15:40 GMT
37
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,98 @@
1
+ require 'vcr'
2
+ require 'steam_api'
3
+
4
+ VCR.configure do |c|
5
+ c.filter_sensitive_data("<API_KEY>") { ENV["STEAM_KEY"] }
6
+ c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
7
+ c.hook_into :webmock
8
+ end
9
+
10
+ # This file was generated by the `rspec --init` command. Conventionally, all
11
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
12
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
13
+ # file to always be loaded, without a need to explicitly require it in any files.
14
+ #
15
+ # Given that it is always loaded, you are encouraged to keep this file as
16
+ # light-weight as possible. Requiring heavyweight dependencies from this file
17
+ # will add to the boot time of your test suite on EVERY test run, even for an
18
+ # individual file that may not need all of that loaded. Instead, consider making
19
+ # a separate helper file that requires the additional dependencies and performs
20
+ # the additional setup, and require it from the spec files that actually need it.
21
+ #
22
+ # The `.rspec` file also contains a few flags that are not defaults but that
23
+ # users commonly want.
24
+ #
25
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
26
+ RSpec.configure do |config|
27
+ # rspec-expectations config goes here. You can use an alternate
28
+ # assertion/expectation library such as wrong or the stdlib/minitest
29
+ # assertions if you prefer.
30
+ config.expect_with :rspec do |expectations|
31
+ # This option will default to `true` in RSpec 4. It makes the `description`
32
+ # and `failure_message` of custom matchers include text for helper methods
33
+ # defined using `chain`, e.g.:
34
+ # be_bigger_than(2).and_smaller_than(4).description
35
+ # # => "be bigger than 2 and smaller than 4"
36
+ # ...rather than:
37
+ # # => "be bigger than 2"
38
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
39
+ end
40
+
41
+ # rspec-mocks config goes here. You can use an alternate test double
42
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
43
+ config.mock_with :rspec do |mocks|
44
+ # Prevents you from mocking or stubbing a method that does not exist on
45
+ # a real object. This is generally recommended, and will default to
46
+ # `true` in RSpec 4.
47
+ mocks.verify_partial_doubles = true
48
+ end
49
+
50
+ # The settings below are suggested to provide a good initial experience
51
+ # with RSpec, but feel free to customize to your heart's content.
52
+ =begin
53
+ # These two settings work together to allow you to limit a spec run
54
+ # to individual examples or groups you care about by tagging them with
55
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
56
+ # get run.
57
+ config.filter_run :focus
58
+ config.run_all_when_everything_filtered = true
59
+
60
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
61
+ # For more details, see:
62
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
63
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
64
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
65
+ config.disable_monkey_patching!
66
+
67
+ # This setting enables warnings. It's recommended, but in some cases may
68
+ # be too noisy due to issues in dependencies.
69
+ config.warnings = true
70
+
71
+ # Many RSpec users commonly either run the entire suite or an individual
72
+ # file, and it's useful to allow more verbose output when running an
73
+ # individual spec file.
74
+ if config.files_to_run.one?
75
+ # Use the documentation formatter for detailed output,
76
+ # unless a formatter has already been configured
77
+ # (e.g. via a command-line flag).
78
+ config.default_formatter = 'doc'
79
+ end
80
+
81
+ # Print the 10 slowest examples and example groups at the
82
+ # end of the spec run, to help surface which specs are running
83
+ # particularly slow.
84
+ config.profile_examples = 10
85
+
86
+ # Run specs in random order to surface order dependencies. If you find an
87
+ # order dependency and want to debug it, you can fix the order by providing
88
+ # the seed, which is printed after each run.
89
+ # --seed 1234
90
+ config.order = :random
91
+
92
+ # Seed global randomization in this process using the `--seed` CLI option.
93
+ # Setting this allows you to use `--seed` to deterministically reproduce
94
+ # test failures related to randomization by passing the same `--seed` value
95
+ # as the one that triggered the failure.
96
+ Kernel.srand config.seed
97
+ =end
98
+ end
@@ -0,0 +1,30 @@
1
+ describe SteamApi::Client do
2
+ describe '#initialize' do
3
+ it 'should initialize a Client object with a steam API key' do
4
+ key = '1uih1341iu23g4'
5
+ client = SteamApi::Client.new(key)
6
+ expect(client).to be_a(SteamApi::Client)
7
+ expect(client.api_key).to eq(key)
8
+ end
9
+ end
10
+
11
+ describe '#get' do
12
+ it 'should call the Steam API using the given URL and return a hash' do
13
+ VCR.use_cassette('client_get') do
14
+ client = SteamApi::Client.new(ENV["STEAM_KEY"])
15
+ url = "http://api.steampowered.com/ISteamUser/GetPlayerBans/v1?steamids=76561198002572492"
16
+ result = client.get(url, key_needed: true)
17
+ expect(result["players"]).to_not be_nil
18
+ end
19
+ end
20
+
21
+ it 'should return a hash with an error message if the api_key is invalid' do
22
+ VCR.use_cassette('client_get_invalid') do
23
+ client = SteamApi::Client.new("9a8sf769ds9f7 7f9asd")
24
+ url = "http://api.steampowered.com/ISteamUser/GetPlayerBans/v1?steamids=76561198002572492"
25
+ result = client.get(url, key_needed: true)
26
+ expect(result["error"]).to_not be_nil
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,127 @@
1
+ describe SteamApi::IPlayerService do
2
+ before(:all) do
3
+ @public_id = '76561197995163285'
4
+ @private_id = '76561198002572492'
5
+ @game_id = '730'
6
+ @notfound_game_id = '12345'
7
+ @invalid_game_id = '123 45'
8
+ @notfound_id = '67734658237465083465238745693'
9
+ @invalid_id = '76561199623423 72348002572492'
10
+ @client = SteamApi::Client.new(ENV["STEAM_KEY"])
11
+ end
12
+
13
+ describe '#get_recently_played_games' do
14
+ it 'returns a hash about the users recently played games' do
15
+ VCR.use_cassette('get_recently_played_games') do
16
+ result = @client.get_recently_played_games(@public_id)
17
+ expect(result["response"]["games"]).to_not be_nil
18
+ end
19
+ end
20
+
21
+ it 'also takes an optional count argument' do
22
+ VCR.use_cassette('get_recently_played_games_count') do
23
+ result = @client.get_recently_played_games(@public_id, 2)
24
+ expect(result["response"]["games"].size).to eq(2)
25
+ end
26
+ end
27
+
28
+ it 'returns a hash when profile is private (with no data)' do
29
+ VCR.use_cassette('get_recently_played_games_private') do
30
+ result = @client.get_recently_played_games(@private_id)
31
+ expect(result["response"].size).to eq(0)
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '#get_owned_games' do
37
+ it 'returns a hash which contains the users owned games' do
38
+ VCR.use_cassette('get_owned_games') do
39
+ result = @client.get_owned_games(@public_id)
40
+ expect(result["response"]["games"]).to_not be_nil
41
+ end
42
+ end
43
+
44
+ it 'returns an empty hash if the user has a private profile' do
45
+ VCR.use_cassette('get_owned_games_private') do
46
+ result = @client.get_owned_games(@private_id)
47
+ expect(result["response"]["games"]).to be_nil
48
+ end
49
+ end
50
+
51
+ it 'can take an optional "include_appinfo parameter"' do
52
+ VCR.use_cassette('get_owned_games_include_appinfo') do
53
+ result = @client.get_owned_games(@public_id, include_appinfo: true)
54
+ expect(result["response"]["games"].first["name"]).to_not be_nil
55
+ end
56
+ end
57
+
58
+ it 'can take an optional "include_played_free_games" parameter"' do
59
+ VCR.use_cassette('get_owned_games_include_played_free_games') do
60
+ result = @client.get_owned_games(@public_id, include_played_free_games: true)
61
+ expect(result["response"]["games"]).to_not be_nil
62
+ end
63
+ end
64
+
65
+ it 'can take all the optional arguments' do
66
+ VCR.use_cassette('get_owned_games_all_args') do
67
+ result = @client.get_owned_games(@public_id, include_appinfo: true, include_played_free_games: true)
68
+ expect(result["response"]["games"].first["name"]).to_not be_nil
69
+ end
70
+ end
71
+ end
72
+
73
+ describe '#get_steam_level' do
74
+ it 'returns a hash containing the users steam level' do
75
+ VCR.use_cassette('get_steam_level') do
76
+ result = @client.get_steam_level(@public_id)
77
+ expect(result["response"]["player_level"]).to_not be_nil
78
+ end
79
+ end
80
+
81
+ it 'returns a hash containing the users steam level (with private profile)' do
82
+ VCR.use_cassette('get_steam_level_private') do
83
+ result = @client.get_steam_level(@private_id)
84
+ expect(result["response"]["player_level"]).to_not be_nil
85
+ end
86
+ end
87
+ end
88
+
89
+ describe '#get_badges' do
90
+ it 'returns a hash containing info about the users badges' do
91
+ VCR.use_cassette('get_badges') do
92
+ result = @client.get_badges(@public_id)
93
+ expect(result["response"]["badges"].size).to be > 0
94
+ end
95
+ end
96
+
97
+ it 'returns an empty hash if the user has a private profile' do
98
+ VCR.use_cassette('get_badges_private') do
99
+ result = @client.get_badges(@private_id)
100
+ expect(result["response"].size).to eq(0)
101
+ end
102
+ end
103
+ end
104
+
105
+ describe '#get_community_badge_progress' do
106
+ it 'returns a hash containing information about the users comunnity badge progress' do
107
+ VCR.use_cassette('get_community_badge_progress') do
108
+ result = @client.get_community_badge_progress(@public_id)
109
+ expect(result["response"]["quests"]).to_not be_nil
110
+ end
111
+ end
112
+
113
+ it 'returns a hash containing information about the users comunnity badge progress for private users' do
114
+ VCR.use_cassette('get_community_badge_progress_private') do
115
+ result = @client.get_community_badge_progress(@private_id)
116
+ expect(result["response"]["quests"]).to_not be_nil
117
+ end
118
+ end
119
+
120
+ it 'can also take an optional paramater to look at a specific badge id' do
121
+ VCR.use_cassette('get_community_badge_progress_specific_badge') do
122
+ result = @client.get_community_badge_progress(@public_id, badge_id: 2)
123
+ expect(result["response"]["quests"]).to_not be_nil
124
+ end
125
+ end
126
+ end
127
+ end
@@ -0,0 +1,163 @@
1
+ describe SteamApi::ISteamUser do
2
+ before(:all) do
3
+ key = ENV['STEAM_KEY']
4
+ @public_id = '76561197995163285'
5
+ @public_vanity = "youda"
6
+ @private_vanity = "blitzcat"
7
+ @notfound_vanity = "abcdefuhasadfdfujkad"
8
+ @private_id = '76561198002572492'
9
+ @notfound_id = '67734658237465083465238745693'
10
+ @invalid_id = '76561199623423 72348002572492'
11
+ @client = SteamApi::Client.new(key)
12
+ end
13
+
14
+ describe '#get_friend_list' do
15
+ it "returns a hash containing the user's friends" do
16
+ VCR.use_cassette('get_friend_list_public') do
17
+ result = @client.get_friend_list(@public_id)
18
+ expect(result).to be_a(Hash)
19
+ expect(result["friendslist"]).to_not be_nil
20
+ end
21
+ end
22
+
23
+ it "returns a hash when the user has a private profile" do
24
+ VCR.use_cassette('get_friend_list_private') do
25
+ result = @client.get_friend_list(@private_id)
26
+ expect(result["friendslist"]).to be_nil
27
+ end
28
+ end
29
+
30
+ it "returns a hash containing error message when user is not found" do
31
+ VCR.use_cassette('get_friend_list_not_found') do
32
+ result = @client.get_friend_list(@notfound_id)
33
+ expect(result).to be_a(Hash)
34
+ expect(result["friendslist"]).to be_nil
35
+ expect(result["error"]).to be_a(String)
36
+ end
37
+ end
38
+
39
+ it "returns a hash containing error message when it is an invalid id" do
40
+ VCR.use_cassette('get_friend_list_invalid') do
41
+ result = @client.get_friend_list(@invalid_id)
42
+ expect(result).to be_a(Hash)
43
+ expect(result["friendslist"]).to be_nil
44
+ expect(result["error"]).to be_a(String)
45
+ end
46
+ end
47
+ end
48
+
49
+ describe '#get_player_bans' do
50
+ it "returns a hash containing information about a players ban history" do
51
+ VCR.use_cassette('get_player_bans_public') do
52
+ result = @client.get_player_bans(@public_id)
53
+ expect(result["players"]).to_not be_nil
54
+ end
55
+ end
56
+
57
+ it "returns a hash containing information when multiple ids are passed in" do
58
+ VCR.use_cassette('get_player_bans_public_private') do
59
+ result = @client.get_player_bans(@public_id, @private_id)
60
+ expect(result["players"].size).to eq(2)
61
+ end
62
+ end
63
+
64
+ it "returns a hash containing error message when user not found" do
65
+ VCR.use_cassette('get_player_bans_not_found') do
66
+ result = @client.get_player_bans(@notfound_id)
67
+ expect(result["players"].size).to eq(0)
68
+ end
69
+ end
70
+
71
+ it "returns a hash containing error message when it is invalid id" do
72
+ VCR.use_cassette('get_player_bans_invalid') do
73
+ result = @client.get_player_bans(@invalid_id)
74
+ expect(result["error"]).to be_a(String)
75
+ end
76
+ end
77
+ end
78
+
79
+ describe '#get_player_summaries' do
80
+ it 'returns a hash containing a single players summary' do
81
+ VCR.use_cassette('get_player_summaries_single') do
82
+ result = @client.get_player_summaries(@public_id)
83
+ expect(result["response"]["players"]).to_not be_nil
84
+ end
85
+ end
86
+
87
+ it 'returns a hash containing multiple players summaries' do
88
+ VCR.use_cassette('get_player_summaries_multiple') do
89
+ result = @client.get_player_summaries(@public_id, @private_id)
90
+ expect(result["response"]["players"]).to_not be_nil
91
+ expect(result["response"]["players"].length).to eq(2)
92
+ end
93
+ end
94
+
95
+ it 'returns a hash from the API when the user is not found' do
96
+ VCR.use_cassette('get_player_summaries_not_found') do
97
+ result = @client.get_player_summaries(@notfound_id)
98
+ expect(result["response"]["players"].length).to eq(0)
99
+ end
100
+ end
101
+
102
+ it 'returns a hash from the API when an invalid id is passed in' do
103
+ VCR.use_cassette('get_player_summaries_invalid') do
104
+ result = @client.get_player_summaries(@invalid_id)
105
+ expect(result["error"]).to_not be_nil
106
+ end
107
+ end
108
+ end
109
+
110
+ describe '#get_user_group_list' do
111
+ it 'returns a hash which contains the users list of groups (public)' do
112
+ VCR.use_cassette('get_user_group_list_public') do
113
+ result = @client.get_user_group_list(@public_id)
114
+ expect(result["response"]["groups"]).to_not be_nil
115
+ end
116
+ end
117
+
118
+ it 'returns a hash which has success: false if the user is private' do
119
+ VCR.use_cassette('get_user_group_list_private') do
120
+ result = @client.get_user_group_list(@private_id)
121
+ expect(result["response"]["success"]).to be false
122
+ end
123
+ end
124
+
125
+ it 'returns a hash with an error message if the user was not found' do
126
+ VCR.use_cassette('get_user_group_list_not_found') do
127
+ result = @client.get_user_group_list(@notfound_id)
128
+ expect(result["error"]).to_not be_nil
129
+ end
130
+ end
131
+
132
+ it 'returns a hash with an error message if there was an invalid id' do
133
+ VCR.use_cassette('get_user_group_list_not_found') do
134
+ result = @client.get_user_group_list(@invalid_id)
135
+ expect(result["error"]).to_not be_nil
136
+ end
137
+ end
138
+ end
139
+
140
+ describe '#resolve_vanity_url' do
141
+ it 'returns a hash containing the users steam_id_64 (public user)' do
142
+ VCR.use_cassette('resolve_vanity_url_public') do
143
+ result = @client.resolve_vanity_url(@public_vanity)
144
+ expect(result["response"]["steamid"]).to_not be_nil
145
+ end
146
+ end
147
+
148
+ it 'returns a hash containing the users steam_id_64 (private user)' do
149
+ VCR.use_cassette('resolve_vanity_url_private') do
150
+ result = @client.resolve_vanity_url(@private_vanity)
151
+ expect(result["response"]["steamid"]).to_not be_nil
152
+ end
153
+ end
154
+
155
+ it 'returns a hash with success of 42 which means user was not found' do
156
+ VCR.use_cassette('resolve_vanity_url_not_found') do
157
+ result = @client.resolve_vanity_url(@notfound_id)
158
+ expect(result["response"]["success"]).to eq(42)
159
+ expect(result["response"]["message"]).to eq("No match")
160
+ end
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,143 @@
1
+ describe SteamApi::ISteamUserStats do
2
+ before(:all) do
3
+ @public_id = '76561197995163285'
4
+ @private_id = '76561198002572492'
5
+ @game_id = '730'
6
+ @notfound_game_id = '12345'
7
+ @invalid_game_id = '123 45'
8
+ @notfound_id = '67734658237465083465238745693'
9
+ @invalid_id = '76561199623423 72348002572492'
10
+ @client = SteamApi::Client.new(ENV["STEAM_KEY"])
11
+ end
12
+
13
+ describe '#get_global_achievement_percentages_for_app' do
14
+ it 'returns a hash containing achievements and their global percentage completion for an app' do
15
+ VCR.use_cassette('get_global_achievement_percentages_for_app') do
16
+ result = @client.get_global_achievement_percentages_for_app(@game_id)
17
+ expect(result["achievementpercentages"]["achievements"]).to_not be_nil
18
+ end
19
+ end
20
+
21
+ it 'returns an empty hash when the app is not found' do
22
+ VCR.use_cassette('get_global_achievement_percentages_for_app_not_found') do
23
+ result = @client.get_global_achievement_percentages_for_app(@notfound_game_id)
24
+ expect(result["achievementpercentages"]).to be_nil
25
+ end
26
+ end
27
+
28
+ it 'returns an empty hash when an invalid id is inputted' do
29
+ VCR.use_cassette('get_global_achievement_percentages_for_app_invalid') do
30
+ result = @client.get_global_achievement_percentages_for_app(@invalid_game_id)
31
+ expect(result["achievementpercentages"]).to be_nil
32
+ end
33
+ end
34
+ end
35
+
36
+ describe '#get_global_achievement_percentages_for_game' do
37
+ xit 'returns a hash which contains global stats about a specific game' do
38
+
39
+ end
40
+ end
41
+
42
+ describe '#get_number_of_current_players' do
43
+ it 'returns a hash which contains number of current players' do
44
+ VCR.use_cassette('get_number_of_current_players') do
45
+ result = @client.get_number_of_current_players(@game_id)
46
+ expect(result["response"]["result"]).to eq(1)
47
+ end
48
+ end
49
+
50
+ it 'returns a hash which contains result of 42 if app id does not exist' do
51
+ VCR.use_cassette('get_number_of_current_players_not_found') do
52
+ result = @client.get_number_of_current_players(@notfound_game_id)
53
+ expect(result["response"]["result"]).to eq(42)
54
+ end
55
+ end
56
+ end
57
+
58
+ describe '#get_player_achievements' do
59
+ it 'returns a hash containing info about players achievement completion' do
60
+ VCR.use_cassette('get_player_achievements') do
61
+ result = @client.get_player_achievements(@public_id, @game_id)
62
+ expect(result["playerstats"]["achievements"]).to_not be_nil
63
+ end
64
+ end
65
+
66
+ it 'returns a hash containing an error message if user is private' do
67
+ VCR.use_cassette('get_player_achievements_private') do
68
+ result = @client.get_player_achievements(@private_id, @game_id)
69
+ expect(result["playerstats"]["error"]).to_not be_nil
70
+ expect(result["playerstats"]["success"]).to be false
71
+ end
72
+ end
73
+
74
+ it 'returns a hash containing an error message if user does not exist' do
75
+ VCR.use_cassette('get_player_achievements_user_not_found') do
76
+ result = @client.get_player_achievements(@notfound_id, @game_id)
77
+ expect(result["playerstats"]["error"]).to_not be_nil
78
+ expect(result["playerstats"]["success"]).to be false
79
+ end
80
+ end
81
+
82
+ it 'returns a hash containing an error message if the game does not have stats (or does not exist)' do
83
+ VCR.use_cassette('get_player_achievements_game_no_stats') do
84
+ result = @client.get_player_achievements(@public_id, @notfound_game_id)
85
+ expect(result["playerstats"]["error"]).to_not be_nil
86
+ expect(result["playerstats"]["success"]).to be false
87
+ end
88
+ end
89
+ end
90
+
91
+ describe '#get_schema_for_game' do
92
+ it 'returns a hash containing the schema for a game' do
93
+ VCR.use_cassette('get_schema_for_game') do
94
+ result = @client.get_schema_for_game(@game_id)
95
+ expect(result["game"]).to_not be_nil
96
+ end
97
+ end
98
+
99
+ it 'returns an empty hash if the game does not exist' do
100
+ VCR.use_cassette('get_schema_for_game_not_found') do
101
+ result = @client.get_schema_for_game(@notfound_game_id)
102
+ expect(result["game"]).to be_nil
103
+ end
104
+ end
105
+
106
+ it 'returns an empty hash if it is an invalid game id' do
107
+ VCR.use_cassette('get_schema_for_game_invalid') do
108
+ result = @client.get_schema_for_game(@invalid_game_id)
109
+ expect(result["game"]).to be_nil
110
+ end
111
+ end
112
+ end
113
+
114
+ describe '#get_user_stats_for_game' do
115
+ it 'returns a hash containing the users stats for a certain game' do
116
+ VCR.use_cassette('get_user_stats_for_game') do
117
+ result = @client.get_user_stats_for_game(@public_id, @game_id)
118
+ expect(result["playerstats"]).to_not be_nil
119
+ end
120
+ end
121
+
122
+ it 'returns a hash with an error message if the profile is private' do
123
+ VCR.use_cassette('get_user_stats_for_game_private') do
124
+ result = @client.get_user_stats_for_game(@private_id, @game_id)
125
+ expect(result["error"]).to_not be_nil
126
+ end
127
+ end
128
+
129
+ it 'returns an empty hash if the user was not found' do
130
+ VCR.use_cassette('get_user_stats_for_game_user_not_found') do
131
+ result = @client.get_user_stats_for_game(@notfound_id, @game_id)
132
+ expect(result.size).to eq(0)
133
+ end
134
+ end
135
+
136
+ it 'returns an empty hash if the game was not found' do
137
+ VCR.use_cassette('get_user_stats_for_game_game_not_found') do
138
+ result = @client.get_user_stats_for_game(@public_id, @notfound_game_id)
139
+ expect(result.size).to eq(0)
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,36 @@
1
+ describe SteamApi::Urls do
2
+ describe '.friend_list' do
3
+ it 'returns the base url for getting users friends list (with passed in id)' do
4
+ result = SteamApi::Urls.friend_list('938457325', 'all')
5
+ expect(result).to be_a(String)
6
+ end
7
+ end
8
+
9
+ describe '.player_bans' do
10
+ it 'returns the base url for getting info about player bans (passed in id)' do
11
+ result = SteamApi::Urls.player_bans('938457325')
12
+ expect(result).to be_a(String)
13
+ end
14
+ end
15
+
16
+ describe '.player_summaries' do
17
+ it 'returns the base url for getting info about player summaries (passed in ids)' do
18
+ result = SteamApi::Urls.player_summaries('938457325')
19
+ expect(result).to be_a(String)
20
+ end
21
+ end
22
+
23
+ describe '.user_group_list' do
24
+ it 'returns the base url for getting info about groups for a player' do
25
+ result = SteamApi::Urls.user_group_list('938457325')
26
+ expect(result).to be_a(String)
27
+ end
28
+ end
29
+
30
+ describe '.vanity_url' do
31
+ it 'returns the base url for getting info about a player\'s steam id' do
32
+ result = SteamApi::Urls.vanity_url('youda')
33
+ expect(result).to be_a(String)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ describe SteamApi::VERSION do
2
+ it 'should return the version number as a string' do
3
+ version = SteamApi::VERSION
4
+ expect(version).to_not be_nil
5
+ expect(version).to be_a(String)
6
+ end
7
+ end
File without changes
data/steam_api.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'steam_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "steam_api"
8
+ spec.version = SteamApi::VERSION
9
+ spec.authors = ["Yusef Ouda"]
10
+ spec.email = ["yiouda92@gmail.com"]
11
+ spec.summary = %q{A gem for interacting with the Steam Web API}
12
+ # spec.description = %q{TODO: Write a longer description. Optional.}
13
+ spec.homepage = "http://github.com/YusefOuda/steam-api"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.1.0"
24
+ spec.add_development_dependency "yard"
25
+ spec.add_development_dependency "pry-byebug"
26
+ spec.add_development_dependency "vcr"
27
+ spec.add_development_dependency "webmock"
28
+ end