stew 0.5.3 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: 477197e65d28b16f161bb00fda87456f4c8dd060
4
- data.tar.gz: cc4b12947017d09abe8709ce409f7bcd29a13b95
5
- !binary "U0hBNTEy":
6
- metadata.gz: a906dfe2d3fd1b5f153d8ff917d4d607928a53c743fee15a7b0525592f0eaa1db3654e331783e25359efdf19de3291c5f20c12643f282266a2acf5cac819de4d
7
- data.tar.gz: 225ef1f2c16bd40c24ed9e0d8573ed5f33ceb224dbed1b0485aba612429dd3d157c5c6030c7aca9980fd123ab7506a2774e3e100e7109fe478c9d4a3f4236d08
2
+ SHA1:
3
+ metadata.gz: 5166e1a3081ff40e7ca4827980ccc913b3429540
4
+ data.tar.gz: 5584edb934679444c212d2f1bf74bd5f84f8dfdc
5
+ SHA512:
6
+ metadata.gz: 00dfa4a38b304d64d3bd270e2e5ce73efb0158201df457b07debe73538d1e24da3475db4ec27a14e3f3abb60f88e1260f85a89b458a2eb1dbc56fa1b5cb4e31a
7
+ data.tar.gz: 7cd14ea29660021199471306c78df32d1f4a26a66461bd472223aae68aca5c7c1541c6aa356a7c503acb59a0a8e70eb02d6d3b29cc79f97bc3dcef8482deb7dc
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
+ spec/config.yml
6
7
  Gemfile.lock
7
8
  InstalledFiles
8
9
  _yardoc
@@ -8,12 +8,9 @@ require 'money'
8
8
 
9
9
  require "stew/version"
10
10
 
11
- require 'stew/community/xml_client/xml_client'
12
- require 'stew/community/xml_client/xml_client_response_profile'
13
- require 'stew/community/xml_client/xml_client_response_games'
14
- require 'stew/community/xml_client/xml_client_response_friends'
15
-
16
- require 'stew/community/community_client'
11
+ require 'stew/community/steam_id_resolver'
12
+ require 'stew/community/web_client'
13
+ require 'stew/community/web_api_client'
17
14
  require 'stew/community/steam_id'
18
15
  require 'stew/community/profile'
19
16
  require 'stew/community/profile_friends'
@@ -34,11 +31,11 @@ module Stew
34
31
  Money.assume_from_symbol = true
35
32
 
36
33
  @config = {
37
- :default_community_client => Community::CommunityClient,
34
+ :default_community_client => Community::WebApiClient,
38
35
  :default_store_client => Store::StoreClient,
39
- :default_xml_client => Community::XmlClient,
40
36
  :default_web_client => Store::WebClient,
41
- :default_region => :us
37
+ :default_region => :us,
38
+ :steam_api_key => nil
42
39
  }
43
40
 
44
41
  @valid_config_keys = @config.keys
@@ -15,8 +15,8 @@ module Stew
15
15
  private
16
16
 
17
17
  def set_data(data)
18
- @id = data['steamID64'].to_i
19
- @nickname = data['steamID']
18
+ @id = data['steamid'].to_i
19
+ @nickname = data['personaname']
20
20
  end
21
21
  end
22
22
  end
@@ -7,7 +7,7 @@ module Stew
7
7
  include Enumerable
8
8
 
9
9
  def initialize(data)
10
- @friends = data.map {|friend| SteamId.new(friend)}
10
+ @friends = data.map {|friend| SteamId.new(friend['steamid'])}
11
11
  end
12
12
 
13
13
  def each(&block)
@@ -11,17 +11,34 @@ module Stew
11
11
 
12
12
  attr_reader :store_link
13
13
 
14
- attr_reader :hours_last_2_weeks
14
+ attr_reader :playtime_2weeks
15
15
 
16
- attr_reader :hours_on_record
16
+ attr_reader :playtime_forever
17
17
 
18
18
  def initialize(hash)
19
- @app_id = hash['appID'].to_i
19
+ @app_id = hash['appid'].to_i
20
20
  @name = hash['name']
21
21
  @logo = hash['logo']
22
- @store_link = hash['storeLink']
23
- @hours_last_2_weeks = hash['hoursLast2Weeks'].to_f
24
- @hours_on_record = hash['hoursOnRecord'].to_f
22
+ @playtime_2weeks = hash['playtime_2weeks'].to_i
23
+ @playtime_forever = hash['playtime_forever'].to_i
24
+ @img_logo_url = hash['img_logo_url']
25
+ @img_icon_url = hash['img_icon_url']
26
+ end
27
+
28
+ def store_url
29
+ "http://store.steampowered.com/app/#{@app_id}"
30
+ end
31
+
32
+ def community_url
33
+ "http://steamcommunity.com/app/#{@app_id}"
34
+ end
35
+
36
+ def icon
37
+ "http://media.steampowered.com/steamcommunity/public/images/apps/#{@app_id}/#{@img_icon_url}.jpg"
38
+ end
39
+
40
+ def logo
41
+ "http://media.steampowered.com/steamcommunity/public/images/apps/#{@app_id}/#{@img_logo_url}.jpg"
25
42
  end
26
43
  end
27
44
  end
@@ -13,36 +13,21 @@ module Stew
13
13
 
14
14
  attr_reader :id
15
15
 
16
- def self.create(data)
17
- return self.new($1.to_i) if data =~ /steamcommunity.com\/profiles\/([0-9]+)/
18
- return self.new($1) if data =~ /steamcommunity.com\/id\/([a-zA-Z0-9]+)/
19
- return self.new(data) if data.to_s.match /^[0-9A-Za-z]+$/
20
- raise SteamIdNotFoundError
21
- end
22
-
23
- def initialize(steam_id,opts={})
24
- @id = steam_id
25
- @client = opts[:client] || self.class.client_with_options(steam_id)
16
+ def initialize(data,opts={})
17
+ @client = opts[:client] || Stew.config[:default_community_client].new
18
+ @id = SteamIdResolver.new(@client).steam_id(data)
26
19
  end
27
20
 
28
21
  def profile
29
- @profile ||= @client.profile @id
22
+ @profile ||= Profile.new(@client.profile(@id))
30
23
  end
31
24
 
32
25
  def games
33
- @games ||= @client.profile_games @id
26
+ @games ||= ProfileGames.new @client.profile_games(@id)
34
27
  end
35
28
 
36
29
  def friends
37
- @friends ||= @client.profile_friends @id
38
- end
39
-
40
- private
41
-
42
- def self.client_with_options(steam_id)
43
- klass = Stew.config[:default_community_client]
44
- return klass.new if steam_id.to_s.match /^[0-9]+$/
45
- return klass.new({:base_path => 'id'})
30
+ @friends ||= ProfileFriends.new @client.profile_friends(@id)
46
31
  end
47
32
  end
48
33
 
@@ -0,0 +1,34 @@
1
+ module Stew
2
+ module Community
3
+
4
+ #Resolves steam ids from numbers, urls and vanity names
5
+ class SteamIdResolver
6
+ attr_reader :client
7
+
8
+ def initialize(client = Stew.config[:default_community_client].new)
9
+ @client = client
10
+ end
11
+
12
+ def steam_id(data)
13
+ data_string = data.to_s
14
+ return data.to_i if /^[0-9]+$/ === data_string
15
+
16
+ matches = (/steamcommunity.com\/(id|profiles|)\/([a-z0-9]+)/i).match(data_string)
17
+ steam_id = steam_id_from_matches(data,matches)
18
+ return steam_id unless steam_id.nil?
19
+ raise Stew::Community::SteamIdNotFoundError
20
+ end
21
+
22
+ private
23
+ def steam_id_from_matches(data, matches)
24
+ if matches.nil?
25
+ return @client.vanity_url_to_steam_id(data) unless data.include?('/')
26
+ elsif matches[1] != 'profiles'
27
+ return @client.vanity_url_to_steam_id(data)
28
+ else
29
+ return matches[2].to_i
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,29 @@
1
+ module Stew
2
+ module Community
3
+ class WebApiClient
4
+ BASE_URI = 'http://api.steampowered.com'
5
+
6
+ def initialize(client = WebClient.new(BASE_URI), opts={})
7
+ @api_key = opts[:steam_api_key] || Stew.config[:steam_api_key]
8
+ @client = client
9
+ end
10
+
11
+ def vanity_url_to_steam_id(vanity_url)
12
+ vanity_name = vanity_url.split('/').last
13
+ @client.get("/ISteamUser/ResolveVanityURL/v0001/?key=#{@api_key}&vanityurl=#{vanity_name}")['response']['steamid'].to_i
14
+ end
15
+
16
+ def profile(steam_id)
17
+ @client.get("/ISteamUser/GetPlayerSummaries/v0002/?key=#{@api_key}&steamids=#{steam_id}")['response']['players'].first
18
+ end
19
+
20
+ def profile_games(steam_id)
21
+ @client.get("/IPlayerService/GetOwnedGames/v0001/?key=#{@api_key}&steamid=#{steam_id}&include_appinfo=1")['response']['games']
22
+ end
23
+
24
+ def profile_friends(steam_id)
25
+ @client.get("/ISteamUser/GetFriendList/v0001/?key=#{@api_key}&steamid=#{steam_id}&relationship=friend")['friendslist']['friends']
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,29 @@
1
+ module Stew
2
+ module Community
3
+ class WebClient
4
+ def initialize(uri)
5
+ @connection = self.class.connection(uri)
6
+ end
7
+
8
+ def get(uri)
9
+ request(uri).body
10
+ end
11
+
12
+ private
13
+
14
+ def request(path)
15
+ @connection.get path
16
+ end
17
+
18
+ def self.connection(uri)
19
+ Faraday.new uri do |conn|
20
+ conn.request :json
21
+ conn.request :retry
22
+ conn.response :json, :content_type => /\bjson$/
23
+ conn.use FaradayMiddleware::FollowRedirects
24
+ conn.adapter Faraday.default_adapter
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module Stew
2
- VERSION = "0.5.3"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -0,0 +1 @@
1
+ steam_api_key: YOUR STEAM API KEY
@@ -0,0 +1,24 @@
1
+ {
2
+ "response": {
3
+ "players": [
4
+ {
5
+ "steamid": "76561197992917668",
6
+ "communityvisibilitystate": 3,
7
+ "profilestate": 1,
8
+ "personaname": "MrCheese",
9
+ "lastlogoff": 1366670468,
10
+ "profileurl": "http://steamcommunity.com/profiles/76561197992917668/",
11
+ "avatar": "http://media.steampowered.com/steamcommunity/public/images/avatars/3f/3fa6fcddcca7825ee0a77f4f4b8f4e10543a13cd.jpg",
12
+ "avatarmedium": "http://media.steampowered.com/steamcommunity/public/images/avatars/3f/3fa6fcddcca7825ee0a77f4f4b8f4e10543a13cd_medium.jpg",
13
+ "avatarfull": "http://media.steampowered.com/steamcommunity/public/images/avatars/3f/3fa6fcddcca7825ee0a77f4f4b8f4e10543a13cd_full.jpg",
14
+ "personastate": 0,
15
+ "primaryclanid": "103582791429591238",
16
+ "timecreated": 1190821006,
17
+ "loccountrycode": "SE",
18
+ "locstatecode": "27",
19
+ "loccityid": 43726
20
+ }
21
+ ]
22
+
23
+ }
24
+ }
@@ -0,0 +1,167 @@
1
+ {
2
+ "friendslist": {
3
+ "friends": [
4
+ {
5
+ "steamid": "76561197960889223",
6
+ "relationship": "friend",
7
+ "friend_since": 1359412028
8
+ },
9
+ {
10
+ "steamid": "76561197965950613",
11
+ "relationship": "friend",
12
+ "friend_since": 0
13
+ },
14
+ {
15
+ "steamid": "76561197967840183",
16
+ "relationship": "friend",
17
+ "friend_since": 1268471108
18
+ },
19
+ {
20
+ "steamid": "76561197969785267",
21
+ "relationship": "friend",
22
+ "friend_since": 1305879987
23
+ },
24
+ {
25
+ "steamid": "76561197970357192",
26
+ "relationship": "friend",
27
+ "friend_since": 1298409788
28
+ },
29
+ {
30
+ "steamid": "76561197971313256",
31
+ "relationship": "friend",
32
+ "friend_since": 1275244941
33
+ },
34
+ {
35
+ "steamid": "76561197972211787",
36
+ "relationship": "friend",
37
+ "friend_since": 1274393267
38
+ },
39
+ {
40
+ "steamid": "76561197973308537",
41
+ "relationship": "friend",
42
+ "friend_since": 0
43
+ },
44
+ {
45
+ "steamid": "76561197984753904",
46
+ "relationship": "friend",
47
+ "friend_since": 0
48
+ },
49
+ {
50
+ "steamid": "76561197986383225",
51
+ "relationship": "friend",
52
+ "friend_since": 1275316731
53
+ },
54
+ {
55
+ "steamid": "76561197989970207",
56
+ "relationship": "friend",
57
+ "friend_since": 1355787283
58
+ },
59
+ {
60
+ "steamid": "76561197990381282",
61
+ "relationship": "friend",
62
+ "friend_since": 1355816720
63
+ },
64
+ {
65
+ "steamid": "76561197992896557",
66
+ "relationship": "friend",
67
+ "friend_since": 0
68
+ },
69
+ {
70
+ "steamid": "76561197993006661",
71
+ "relationship": "friend",
72
+ "friend_since": 1313313231
73
+ },
74
+ {
75
+ "steamid": "76561197993202125",
76
+ "relationship": "friend",
77
+ "friend_since": 1314895927
78
+ },
79
+ {
80
+ "steamid": "76561197993600452",
81
+ "relationship": "friend",
82
+ "friend_since": 1298573833
83
+ },
84
+ {
85
+ "steamid": "76561197994132576",
86
+ "relationship": "friend",
87
+ "friend_since": 1261943962
88
+ },
89
+ {
90
+ "steamid": "76561197996738173",
91
+ "relationship": "friend",
92
+ "friend_since": 1280061358
93
+ },
94
+ {
95
+ "steamid": "76561197997794911",
96
+ "relationship": "friend",
97
+ "friend_since": 1297707551
98
+ },
99
+ {
100
+ "steamid": "76561197999278598",
101
+ "relationship": "friend",
102
+ "friend_since": 1280579010
103
+ },
104
+ {
105
+ "steamid": "76561197999580320",
106
+ "relationship": "friend",
107
+ "friend_since": 1317242856
108
+ },
109
+ {
110
+ "steamid": "76561198005505133",
111
+ "relationship": "friend",
112
+ "friend_since": 1299011024
113
+ },
114
+ {
115
+ "steamid": "76561198005611690",
116
+ "relationship": "friend",
117
+ "friend_since": 1280131917
118
+ },
119
+ {
120
+ "steamid": "76561198005665154",
121
+ "relationship": "friend",
122
+ "friend_since": 1310909994
123
+ },
124
+ {
125
+ "steamid": "76561198006604638",
126
+ "relationship": "friend",
127
+ "friend_since": 1314895928
128
+ },
129
+ {
130
+ "steamid": "76561198009417084",
131
+ "relationship": "friend",
132
+ "friend_since": 1322376998
133
+ },
134
+ {
135
+ "steamid": "76561198011470861",
136
+ "relationship": "friend",
137
+ "friend_since": 1332093028
138
+ },
139
+ {
140
+ "steamid": "76561198013177911",
141
+ "relationship": "friend",
142
+ "friend_since": 1358963405
143
+ },
144
+ {
145
+ "steamid": "76561198038197496",
146
+ "relationship": "friend",
147
+ "friend_since": 1297818296
148
+ },
149
+ {
150
+ "steamid": "76561198038245915",
151
+ "relationship": "friend",
152
+ "friend_since": 1302029464
153
+ },
154
+ {
155
+ "steamid": "76561198052700918",
156
+ "relationship": "friend",
157
+ "friend_since": 1322508339
158
+ },
159
+ {
160
+ "steamid": "76561198067660255",
161
+ "relationship": "friend",
162
+ "friend_since": 1345894791
163
+ }
164
+ ]
165
+
166
+ }
167
+ }