Class: SteamGroup
- Inherits:
-
Object
- Object
- SteamGroup
- Defined in:
- lib/steam/community/steam_group.rb
Overview
The SteamGroup class represents a group in the Steam Community
Constant Summary collapse
- AVATAR_URL =
'http://media.steampowered.com/steamcommunity/public/images/avatars/%s/%s%s.jpg'
Instance Attribute Summary collapse
-
#custom_url ⇒ String
readonly
Returns the custom URL of this group.
-
#group_id64 ⇒ Fixnum
readonly
Returns this group’s 64bit SteamID.
-
#headline ⇒ String
readonly
Returns this group’s headline text.
-
#name ⇒ String
readonly
Returns this group’s name.
-
#summary ⇒ String
readonly
Returns this group’s summary text.
Attributes included from Cacheable
Instance Method Summary collapse
-
#avatar_full_url ⇒ String
Returns the URL to this group’s full avatar.
-
#avatar_icon_url ⇒ String
Returns the URL to this group’s icon avatar.
-
#avatar_medium_url ⇒ String
Returns the URL to this group’s medium avatar.
-
#base_url ⇒ String
Returns the base URL for this group’s page.
-
#fetch ⇒ Object
Loads the members of this group.
-
#initialize(id, fetch = true, bypass_cache = false) ⇒ SteamGroup
constructor
Creates a new ‘SteamGroup` instance for the group with the given ID.
-
#member_count ⇒ Fixnum
Returns the number of members this group has.
-
#members ⇒ Array<SteamId>
Returns the members of this group.
Methods included from XMLData
Methods included from Cacheable
Constructor Details
#initialize(id, fetch = true, bypass_cache = false) ⇒ SteamGroup
Creates a new ‘SteamGroup` instance for the group with the given ID
56 57 58 59 60 61 62 63 |
# File 'lib/steam/community/steam_group.rb', line 56 def initialize(id) if id.is_a? Numeric @group_id64 = id else @custom_url = id.downcase end @members = [] end |
Instance Attribute Details
#custom_url ⇒ String (readonly)
Returns the custom URL of this group
The custom URL is a admin specified unique string that can be used instead of the 64bit SteamID as an identifier for a group.
29 30 31 |
# File 'lib/steam/community/steam_group.rb', line 29 def custom_url @custom_url end |
#group_id64 ⇒ Fixnum (readonly)
Returns this group’s 64bit SteamID
34 35 36 |
# File 'lib/steam/community/steam_group.rb', line 34 def group_id64 @group_id64 end |
#headline ⇒ String (readonly)
Returns this group’s headline text
39 40 41 |
# File 'lib/steam/community/steam_group.rb', line 39 def headline @headline end |
#name ⇒ String (readonly)
Returns this group’s name
44 45 46 |
# File 'lib/steam/community/steam_group.rb', line 44 def name @name end |
#summary ⇒ String (readonly)
Returns this group’s summary text
49 50 51 |
# File 'lib/steam/community/steam_group.rb', line 49 def summary @summary end |
Instance Method Details
#avatar_full_url ⇒ String
Returns the URL to this group’s full avatar
68 69 70 |
# File 'lib/steam/community/steam_group.rb', line 68 def avatar_full_url AVATAR_URL % [ @avatar_hash[0..1], @avatar_hash, '_full' ] end |
#avatar_icon_url ⇒ String
Returns the URL to this group’s icon avatar
75 76 77 |
# File 'lib/steam/community/steam_group.rb', line 75 def avatar_icon_url AVATAR_URL % [ @avatar_hash[0..1], @avatar_hash, '' ] end |
#avatar_medium_url ⇒ String
Returns the URL to this group’s medium avatar
82 83 84 |
# File 'lib/steam/community/steam_group.rb', line 82 def avatar_medium_url AVATAR_URL % [ @avatar_hash[0..1], @avatar_hash, '_medium' ] end |
#base_url ⇒ String
Returns the base URL for this group’s page
This URL is different for groups having a custom URL.
91 92 93 94 95 96 97 |
# File 'lib/steam/community/steam_group.rb', line 91 def base_url if @custom_url.nil? "http://steamcommunity.com/gid/#@group_id64" else "http://steamcommunity.com/groups/#@custom_url" end end |
#fetch ⇒ Object
Loads the members of this group
This might take several HTTP requests as the Steam Community splits this data over several XML documents if the group has lots of members.
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/steam/community/steam_group.rb', line 105 def fetch if @member_count.nil? || @member_count == @members.size page = 0 else page = 1 end begin total_pages = fetch_page(page += 1) end while page < total_pages end |
#member_count ⇒ Fixnum
Returns the number of members this group has
If the members have already been fetched the size of the member array is returned. Otherwise the the first page of the member listing is fetched and the member count and the first batch of members is stored.
124 125 126 127 128 129 130 131 |
# File 'lib/steam/community/steam_group.rb', line 124 def member_count if @member_count.nil? total_pages = fetch_page(1) @fetch_time = Time.now if total_pages == 1 end @member_count end |
#members ⇒ Array<SteamId>
Returns the members of this group
If the members haven’t been fetched yet, this is done now.
139 140 141 142 |
# File 'lib/steam/community/steam_group.rb', line 139 def members fetch if @members.size != @member_count @members end |