class Rsteamshot::User
Public: Represents a Steam user. Used to fetch the user's screenshots they have uploaded to Steam.
Constants
- STEAM_PER_PAGE
Public: How many screenshots are shown on a user's profile per page.
- VALID_ORDERS
Public: How to sort screenshots when they are being retrieved.
Attributes
Public: Returns the number of screenshots that will be fetched per page for this user.
Public: Returns a String user name from a Steam user's public profile.
Public Class Methods
Public: Initialize a Steam user with the given user name.
user_name
- a String per_page
- how many screenshots to get in each page; defaults to 10; valid range: 1-50;
Integer
# File lib/rsteamshot/user.rb, line 22 def initialize(user_name, per_page: 10) @user_name = user_name @per_page = per_page initialize_paginator end
Public Instance Methods
Public: Set how many screenshots should be fetched at a time for this user.
value - an Integer
Returns nothing.
# File lib/rsteamshot/user.rb, line 49 def per_page=(value) @per_page = value initialize_paginator end
Public: Fetch a list of the user's newest uploaded screenshots.
order - String specifying which screenshots should be retrieved; choose from newestfirst,
score, and oldestfirst; defaults to newestfirst
page - which page of results to fetch; defaults to 1; Integer app_id - optional Steam app ID as an Integer or String, to get screenshots from this user for
the specified app; defaults to including all apps
Returns an Array of Rsteamshot::Screenshots.
# File lib/rsteamshot/user.rb, line 37 def screenshots(order: nil, page: 1, app_id: 0) return [] unless user_name url = steam_url(order, app_id) @paginator.screenshots(page: page, url: url) end
Private Instance Methods
# File lib/rsteamshot/user.rb, line 56 def initialize_paginator process_html = ->(html) do links_from(html).map { |link| screenshot_from(link) } end @paginator = ScreenshotPaginator.new(process_html, max_per_page: STEAM_PER_PAGE, per_page: per_page, steam_per_page: STEAM_PER_PAGE) end
# File lib/rsteamshot/user.rb, line 64 def links_from(html) html.search('#image_wall .imageWallRow .profile_media_item') end
# File lib/rsteamshot/user.rb, line 68 def screenshot_from(link) details_url = link['href'] description = link.at('.imgWallHoverDescription') title = description ? description.text.strip : nil Screenshot.new(title: title, details_url: details_url) end
# File lib/rsteamshot/user.rb, line 86 def sort_param(order) if VALID_ORDERS.include?(order) order else VALID_ORDERS.first end end
# File lib/rsteamshot/user.rb, line 75 def steam_url(order, app_id = 0) params = [ "appid=#{URI.escape(app_id.to_s)}", "sort=#{sort_param(order)}", 'browsefilter=myfiles', 'view=grid' ] user_param = URI.escape(user_name) "http://steamcommunity.com/id/#{user_param}/screenshots/?" + params.join('&') end