stew 0.5.3 → 0.6.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 (42) hide show
  1. checksums.yaml +6 -6
  2. data/.gitignore +1 -0
  3. data/lib/stew.rb +6 -9
  4. data/lib/stew/community/profile.rb +2 -2
  5. data/lib/stew/community/profile_friends.rb +1 -1
  6. data/lib/stew/community/profile_game.rb +23 -6
  7. data/lib/stew/community/steam_id.rb +6 -21
  8. data/lib/stew/community/steam_id_resolver.rb +34 -0
  9. data/lib/stew/community/web_api_client.rb +29 -0
  10. data/lib/stew/community/web_client.rb +29 -0
  11. data/lib/stew/version.rb +1 -1
  12. data/spec/config.yml.example +1 -0
  13. data/spec/fixtures/profiles/76561197992917668.json +24 -0
  14. data/spec/fixtures/profiles/friends/76561197992917668.json +167 -0
  15. data/spec/fixtures/profiles/friends/76561197994486912.json +8 -0
  16. data/spec/fixtures/profiles/games/76561197992917668.json +789 -0
  17. data/spec/fixtures/profiles/games/76561197994486912.json +5 -0
  18. data/spec/fixtures/profiles/vanity/Phucked.json +6 -0
  19. data/spec/integration/community_web_api_integration_spec.rb +32 -0
  20. data/spec/lib/stew/community/profile_friends_spec.rb +3 -24
  21. data/spec/lib/stew/community/profile_game_spec.rb +20 -12
  22. data/spec/lib/stew/community/profile_games_spec.rb +2 -3
  23. data/spec/lib/stew/community/profile_spec.rb +2 -2
  24. data/spec/lib/stew/community/steam_id_resolver_spec.rb +82 -0
  25. data/spec/lib/stew/community/steam_id_spec.rb +22 -83
  26. data/spec/lib/stew/community/web_api_client_spec.rb +61 -0
  27. data/spec/lib/stew/community/web_client_spec.rb +17 -0
  28. data/spec/spec_helper.rb +12 -0
  29. data/stew.gemspec +7 -5
  30. metadata +98 -92
  31. data/lib/stew/community/community_client.rb +0 -53
  32. data/lib/stew/community/xml_client/xml_client.rb +0 -50
  33. data/lib/stew/community/xml_client/xml_client_response_friends.rb +0 -20
  34. data/lib/stew/community/xml_client/xml_client_response_games.rb +0 -20
  35. data/lib/stew/community/xml_client/xml_client_response_profile.rb +0 -14
  36. data/spec/fixtures/profiles/friends/76561197992917668.yml +0 -36
  37. data/spec/fixtures/profiles/friends/76561197994486912.yml +0 -5
  38. data/spec/fixtures/profiles/games/76561197992917668.yml +0 -616
  39. data/spec/fixtures/profiles/games/76561197994486912.yml +0 -5
  40. data/spec/integration/community_integration_spec.rb +0 -50
  41. data/spec/lib/stew/community/community_client_spec.rb +0 -118
  42. data/spec/lib/stew/community/xml_client/xml_client_spec.rb +0 -36
@@ -0,0 +1,5 @@
1
+ {
2
+ "response": {
3
+ "game_count": 0
4
+ }
5
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "response": {
3
+ "steamid": "76561198013177911",
4
+ "success": 1
5
+ }
6
+ }
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Community Access through the Web API", :vcr do
4
+ describe "Creation of a steam profile with data" do
5
+ subject{Stew::Community::SteamId.new(76561197992917668)}
6
+
7
+ describe "profile" do
8
+ it "sets the nickname" do
9
+ subject.profile.nickname.should eq 'MrCheese'
10
+ end
11
+ end
12
+
13
+ describe "games" do
14
+ it "creates games" do
15
+ subject.games.collect(&:name).include?('Shank').should be_true
16
+ subject.games.collect(&:app_id).include?(17460).should be_true
17
+ end
18
+ end
19
+
20
+ describe "friends" do
21
+ it "creates friends" do
22
+ subject.friends.collect(&:id).include?(76561197972211787).should be_true
23
+ end
24
+ end
25
+ end
26
+
27
+ describe "Attempted creation of a non-existing Steam ID" do
28
+ it "raises a Stew::XmlClient::ObjectNotFoundError" do
29
+ expect{Stew::Community::SteamId.new("www.google.com/nisse")}.to raise_error(Stew::Community::SteamIdNotFoundError)
30
+ end
31
+ end
32
+ end
@@ -2,37 +2,16 @@ require 'spec_helper'
2
2
 
3
3
  describe "Stew::Community::ProfileFriends" do
4
4
  let(:id){76561197992917668}
5
- let(:response){YAML.load_file('spec/fixtures/profiles/friends/76561197992917668.yml')['friendsList']['friends']['friend']}
5
+ let(:response){JSON.parse(IO.read('spec/fixtures/profiles/friends/76561197992917668.json'))['friendslist']['friends']}
6
6
 
7
7
  let(:subject){Stew::Community::ProfileFriends.new(response)}
8
8
 
9
9
  describe ".entries" do
10
10
  it "sets the friends" do
11
11
  response.each do |friend|
12
- Stew::Community::SteamId.should_receive(:new).with(friend)
12
+ Stew::Community::SteamId.should_receive(:new).with(friend['steamid'])
13
13
  end
14
- subject.entries.count.should eq 30
14
+ subject.entries.count.should eq 32
15
15
  end
16
16
  end
17
-
18
- describe ".each" do
19
- let(:subject){Stew::Community::ProfileFriends.new(response)}
20
-
21
- it "invokes the given block for each object returned by the friends method" do
22
- friend1 = double(:name => 'Half-Life 2')
23
- friend2 = double(:name => 'Shank')
24
- friends = [friend1,friend2]
25
-
26
- friend1.should_receive(:name)
27
- friend2.should_receive(:name)
28
- subject.instance_eval do
29
- @friends = friends
30
- end
31
-
32
- subject.each do |friend|
33
- friend.name
34
- end
35
- end
36
- end
37
-
38
17
  end
@@ -1,37 +1,45 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe "Stew::Community::ProfileGame" do
4
- let(:response){YAML.load_file('spec/fixtures/profiles/games/76561197992917668.yml')}
4
+ let(:response){JSON.parse(IO.read('spec/fixtures/profiles/games/76561197992917668.json'))}
5
5
  let(:subject){Stew::Community::ProfileGames.new(76561197992917668)}
6
6
 
7
7
  describe ".initialize" do
8
8
  before :each do
9
- data = YAML.load_file('spec/fixtures/profiles/games/76561197992917668.yml')
10
- @profile_game = Stew::Community::ProfileGame.new(data['gamesList']['games']['game'].first)
9
+ data = JSON.parse(IO.read('spec/fixtures/profiles/games/76561197992917668.json'))
10
+ @profile_game = Stew::Community::ProfileGame.new(data['response']['games'].first)
11
11
  end
12
12
 
13
13
  it "sets the app id" do
14
- @profile_game.app_id.should eq 211420
14
+ @profile_game.app_id.should eq 17460
15
15
  end
16
16
 
17
17
  it "sets the name" do
18
- @profile_game.name.should eq "Dark Souls: Prepare to Die Edition"
18
+ @profile_game.name.should eq "Mass Effect"
19
19
  end
20
20
 
21
21
  it "sets the logo url" do
22
- @profile_game.logo.should eq "http://media.steampowered.com/steamcommunity/public/images/apps/211420/d293c8e38f56de2c7097b2c7a975caca49029a8b.jpg"
22
+ @profile_game.logo.should eq "http://media.steampowered.com/steamcommunity/public/images/apps/17460/7501ea5009533fa5c017ec1f4b94725d67ad4936.jpg"
23
23
  end
24
24
 
25
- it "sets the store link" do
26
- @profile_game.store_link.should eq "http://steamcommunity.com/app/211420"
25
+ it "sets the icon url" do
26
+ @profile_game.icon.should eq "http://media.steampowered.com/steamcommunity/public/images/apps/17460/57be81f70afa48c65437df93d75ba167a29687bc.jpg"
27
27
  end
28
28
 
29
- it "sets the hours_last_2_weeks" do
30
- @profile_game.hours_last_2_weeks.should eq 16.9
29
+ it "sets the store url" do
30
+ @profile_game.store_url.should eq "http://store.steampowered.com/app/17460"
31
31
  end
32
32
 
33
- it "sets the hours_on_record" do
34
- @profile_game.hours_on_record.should eq 16.9
33
+ it "sets the community url" do
34
+ @profile_game.community_url.should eq "http://steamcommunity.com/app/17460"
35
+ end
36
+
37
+ it "sets the playertime_2weeks" do
38
+ @profile_game.playtime_2weeks.should eq 0
39
+ end
40
+
41
+ it "sets the playertime_forever" do
42
+ @profile_game.playtime_forever.should eq 3173
35
43
  end
36
44
  end
37
45
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe "Stew::Community::ProfileGames" do
4
4
  let(:id){76561197992917668}
5
- let(:response){YAML.load_file('spec/fixtures/profiles/games/76561197992917668.yml')['gamesList']['games']['game']}
5
+ let(:response){JSON.parse(IO.read('spec/fixtures/profiles/games/76561197992917668.json'))['response']['games']}
6
6
 
7
7
  let(:subject){Stew::Community::ProfileGames.new(response)}
8
8
 
@@ -11,7 +11,7 @@ describe "Stew::Community::ProfileGames" do
11
11
  response.each do |game|
12
12
  Stew::Community::ProfileGame.should_receive(:new).with(game)
13
13
  end
14
- subject.entries.count.should eq 102
14
+ subject.entries.count.should eq 106
15
15
  end
16
16
  end
17
17
 
@@ -32,5 +32,4 @@ describe "Stew::Community::ProfileGames" do
32
32
  end
33
33
  end
34
34
  end
35
-
36
35
  end
@@ -2,13 +2,13 @@ require 'spec_helper'
2
2
 
3
3
  describe "Stew::Community::Profile" do
4
4
  let(:id){76561197992917668}
5
- let(:response){YAML.load_file('spec/fixtures/profiles/76561197992917668.yml')['profile']}
5
+ let(:response){YAML.load_file('spec/fixtures/profiles/76561197992917668.json')['response']['players'].first}
6
6
 
7
7
  subject{Stew::Community::Profile.new(response)}
8
8
 
9
9
  describe "attributes" do
10
10
  it "sets the id" do
11
- subject.id.should eq id
11
+ subject.id.should eq id
12
12
  end
13
13
 
14
14
  it "sets the nickname" do
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+
3
+ describe Stew::Community::SteamIdResolver do
4
+ let(:client){double}
5
+ subject{Stew::Community::SteamIdResolver.new(client)}
6
+
7
+ describe ".initialize" do
8
+ context "when given a client" do
9
+ let(:client){double}
10
+
11
+ it "sets the client" do
12
+ Stew::Community::SteamIdResolver.new(client).client.should eq client
13
+ end
14
+ end
15
+
16
+ context "with no client given" do
17
+ it "creates a new default client" do
18
+ Stew::Community::WebApiClient.should_receive(:new)
19
+ Stew::Community::SteamIdResolver.new
20
+ end
21
+ end
22
+ end
23
+
24
+ describe ".steam_id" do
25
+ context "when the given data is a number" do
26
+ let(:data){"12345"}
27
+ let(:expected_steam_id){12345}
28
+
29
+ it "returns the number" do
30
+ subject.steam_id(data).should eq expected_steam_id
31
+ end
32
+ end
33
+
34
+ context "when the given data is a vanity name" do
35
+ let(:data){'foobar20'}
36
+ let(:expected_steam_id){12345}
37
+
38
+ it "resolves the vanity name and sets the id" do
39
+ client.should_receive(:vanity_url_to_steam_id).with(data).and_return(expected_steam_id)
40
+ subject.steam_id(data).should eq expected_steam_id
41
+ end
42
+ end
43
+
44
+ context "when the given data is a vanity url" do
45
+ let(:data){'steamcommunity.com/id/foobar20'}
46
+ let(:expected_steam_id){12345}
47
+
48
+ it "resolves the vanity url and sets the id" do
49
+ client.should_receive(:vanity_url_to_steam_id).with(data).and_return(expected_steam_id)
50
+ subject.steam_id(data).should eq expected_steam_id
51
+ end
52
+ end
53
+
54
+ context "when the given data is a steamcommunity url" do
55
+ let(:data){'steamcommunity.com/profiles/12345'}
56
+ let(:expected_steam_id){12345}
57
+
58
+ it "extracts the id from the url and sets the id" do
59
+ subject.steam_id(data).should eq expected_steam_id
60
+ end
61
+ end
62
+
63
+ context "when the given data is a steamcommunity url with extra at the end" do
64
+ let(:data){'steamcommunity.com/profiles/12345/friends'}
65
+ let(:expected_steam_id){12345}
66
+
67
+ it "extracts the id from the url and sets the id" do
68
+ subject.steam_id(data).should eq expected_steam_id
69
+ end
70
+ end
71
+
72
+ context "when no steam id can be found or resolved from the string" do
73
+ let(:data){'foobar'}
74
+ let(:expected_steam_id){12345}
75
+
76
+ it "raises a Stew::Community::SteamIdNotFoundError" do
77
+ client.should_receive(:vanity_url_to_steam_id).with(data).and_return(nil)
78
+ expect{subject.steam_id(data)}.to raise_error(Stew::Community::SteamIdNotFoundError)
79
+ end
80
+ end
81
+ end
82
+ end
@@ -2,113 +2,52 @@ require 'spec_helper'
2
2
 
3
3
  describe "Stew::Community::SteamId" do
4
4
  let(:id){76561197992917668}
5
- let(:community_client){double('community_client')}
5
+ let(:steam_id){12345}
6
+ let(:client){double('client')}
7
+ let(:resolver){double}
6
8
 
7
- subject{Stew::Community::SteamId.new(id,{:client => community_client})}
9
+ subject{Stew::Community::SteamId.new(id, client: client)}
8
10
 
9
- describe "#create" do
10
- context "when the parameter is an integer" do
11
- it "creates a steam_id with the given integer as id" do
12
- Stew::Community::SteamId.create(id).id.should eq id
13
- end
14
- end
15
-
16
- context "when the parameter is a steamcommunity url" do
17
- let(:url){"http://steamcommunity.com/profiles/#{id}"}
18
-
19
- it "creates a steam_id with the id in the given string as id" do
20
- Stew::Community::SteamId.create(url).id.should eq id
21
- end
22
- end
23
-
24
- context "when the parameter is a vanity url" do
25
- let(:name){"somename"}
26
- let(:url){"http://steamcommunity.com/id/#{name}"}
27
-
28
- it "creates a steamid with the vanity name as first parameter" do
29
- Stew::Community::SteamId.should_receive(:new).with(name)
30
- Stew::Community::SteamId.create(url)
31
- end
32
- end
33
-
34
- context "when the parameter is a vanity name" do
35
- let(:name){"somename"}
36
-
37
- it "creates a steamid with the vanity name as first parameter" do
38
- Stew::Community::SteamId.should_receive(:new).with(name)
39
- Stew::Community::SteamId.create(name)
40
-
41
- end
42
- end
43
-
44
- context "when the parameter is a url that cannot be matched" do
45
- it "raises a SteamIdNotFound error" do
46
- expect{Stew::Community::SteamId.create('sdfsdf/dsfsdf/com')}.to raise_error(Stew::Community::SteamIdNotFoundError)
47
- end
48
- end
11
+ before :each do
12
+ Stew::Community::SteamIdResolver.stub(:new).and_return(resolver)
13
+ resolver.stub(:steam_id) {id}
49
14
  end
50
15
 
51
16
  describe ".initialize" do
52
-
53
- context "when the id is a number" do
54
- it "sets the id" do
55
- subject.id.should eq id
56
- end
57
-
58
- it "should create a community client with no options" do
59
- Stew::Community::CommunityClient.should_receive(:new).with()
60
- Stew::Community::SteamId.new(id)
61
- end
62
- end
63
-
64
- context "when the id is a vanity name" do
65
- let(:id){"foobar20"}
66
-
67
- it "sets the id" do
68
- subject.id.should eq id
69
- end
70
-
71
- it "should create a community client with the base_path option set to 'id'" do
72
- Stew::Community::CommunityClient.should_receive(:new).with({:base_path => 'id'})
73
- Stew::Community::SteamId.new(id)
74
- end
17
+ it "uses an instance of SteamIdResolver to get the id" do
18
+ resolver.should_receive(:steam_id).with(id).and_return(id)
19
+ subject.id.should eq id
75
20
  end
76
21
  end
77
22
 
78
23
  describe ".profile" do
79
- it "calls profile on the community_client" do
80
- community_client.should_receive(:profile).with(id)
81
- subject.profile
82
- end
24
+ let(:data){double}
83
25
 
84
- it "only calls profile on the community_client once" do
85
- community_client.should_receive(:profile).with(id).once.and_return(double('profile'))
26
+ it "returns a steam profile from the data received from the community client" do
27
+ client.should_receive(:profile).with(id).once.and_return(data)
28
+ Stew::Community::Profile.should_receive(:new).with(data).once.and_return(double)
86
29
  subject.profile
87
30
  subject.profile
88
31
  end
89
32
  end
90
33
 
91
34
  describe ".games" do
92
- it "calls profile_games on the community_client" do
93
- community_client.should_receive(:profile_games).with(id)
94
- subject.games
95
- end
35
+ let(:data){double}
96
36
 
97
- it "only calls games on the community_client once" do
98
- community_client.should_receive(:profile_games).with(id).once.and_return(double('profile_games'))
37
+ it "returns the games from the data received from the community client" do
38
+ client.should_receive(:profile_games).with(id).once.and_return(data)
39
+ Stew::Community::ProfileGames.should_receive(:new).with(data).once.and_return(double)
99
40
  subject.games
100
41
  subject.games
101
42
  end
102
43
  end
103
44
 
104
45
  describe ".friends" do
105
- it "calls profile_friends on the community_client" do
106
- community_client.should_receive(:profile_friends).with(id)
107
- subject.friends
108
- end
46
+ let(:data){double}
109
47
 
110
- it "only calls friends on the community_client once" do
111
- community_client.should_receive(:profile_friends).with(id).once.and_return(double('profile_friends'))
48
+ it "returns the friends from the data received from the community client" do
49
+ client.should_receive(:profile_friends).with(id).once.and_return(data)
50
+ Stew::Community::ProfileFriends.should_receive(:new).with(data).once.and_return(double)
112
51
  subject.friends
113
52
  subject.friends
114
53
  end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Stew::Community::WebApiClient" do
4
+ let(:client){double('xml_client')}
5
+ let(:response){JSON.parse(IO.read("spec/fixtures/profiles/#{steam_id}.json"))}
6
+ let(:steam_id){76561197992917668}
7
+ subject{Stew::Community::WebApiClient.new(client)}
8
+
9
+
10
+ describe ".vanity_url_to_steam_id" do
11
+ let(:response){JSON.parse(IO.read("spec/fixtures/profiles/vanity/#{vanity_name}.json"))}
12
+
13
+ context "when given a name" do
14
+ let(:vanity_name){'Phucked'}
15
+
16
+ it "sends the 'get' message to its client with the correct parameters" do
17
+ expected_argument = "/ISteamUser/ResolveVanityURL/v0001/?key=#{STEAM_API_KEY}&vanityurl=#{vanity_name}"
18
+ client.should_receive(:get).with(expected_argument).and_return(response)
19
+ subject.vanity_url_to_steam_id(vanity_name).should eq 76561198013177911
20
+ end
21
+ end
22
+
23
+ context "when given a url" do
24
+ let(:vanity_name){'Phucked'}
25
+ let(:vanity_url){"http://steamcommunity.com/id/#{vanity_name}"}
26
+
27
+ it "sends the 'get' message to its client with the correct parameters" do
28
+ expected_argument = "/ISteamUser/ResolveVanityURL/v0001/?key=#{STEAM_API_KEY}&vanityurl=#{vanity_name}"
29
+ client.should_receive(:get).with(expected_argument).and_return(response)
30
+ subject.vanity_url_to_steam_id(vanity_url).should eq 76561198013177911
31
+ end
32
+ end
33
+ end
34
+
35
+ describe ".profile" do
36
+ let(:response){JSON.parse(IO.read("spec/fixtures/profiles/#{steam_id}.json"))}
37
+ it "sends the 'get' message to its client with the correct parameters" do
38
+ expected_argument = "/ISteamUser/GetPlayerSummaries/v0002/?key=#{STEAM_API_KEY}&steamids=#{steam_id}"
39
+ client.should_receive(:get).with(expected_argument).and_return(response)
40
+ subject.profile(steam_id)['steamid'].to_i.should eq steam_id
41
+ end
42
+ end
43
+
44
+ describe ".profile_games" do
45
+ let(:response){JSON.parse(IO.read("spec/fixtures/profiles/games/#{steam_id}.json"))}
46
+ it "sends the 'get' message to its client with the correct parameters" do
47
+ expected_argument = "/IPlayerService/GetOwnedGames/v0001/?key=#{STEAM_API_KEY}&steamid=#{steam_id}&include_appinfo=1"
48
+ client.should_receive(:get).with(expected_argument).and_return(response)
49
+ subject.profile_games(steam_id).count.should eq 106
50
+ end
51
+ end
52
+
53
+ describe ".profile_friends" do
54
+ let(:response){JSON.parse(IO.read("spec/fixtures/profiles/friends/#{steam_id}.json"))}
55
+ it "sends the 'get' message to its client with the correct parameters" do
56
+ expected_argument = "/ISteamUser/GetFriendList/v0001/?key=#{STEAM_API_KEY}&steamid=#{steam_id}&relationship=friend"
57
+ client.should_receive(:get).with(expected_argument).and_return(response)
58
+ subject.profile_friends(steam_id).count.should eq 32
59
+ end
60
+ end
61
+ end