Class: Rsteamshot::User
- Inherits:
-
Object
- Object
- Rsteamshot::User
- Defined in:
- lib/rsteamshot/user.rb
Overview
Public: Represents a Steam user. Used to fetch the user’s screenshots they have uploaded to Steam.
Constant Summary collapse
- VALID_ORDERS =
Public: How to sort screenshots when they are being retrieved.
%w[newestfirst score oldestfirst].freeze
- STEAM_PER_PAGE =
Public: How many screenshots are shown on a user’s profile per page.
50
Instance Attribute Summary collapse
-
#user_name ⇒ Object
readonly
Public: Returns a String user name from a Steam user’s public profile.
Instance Method Summary collapse
-
#initialize(user_name, per_page: 10) ⇒ User
constructor
Public: Initialize a Steam user with the given user name.
-
#screenshots(order: nil, page: 1, app_id: 0) ⇒ Object
Public: Fetch a list of the user’s newest uploaded screenshots.
Constructor Details
#initialize(user_name, per_page: 10) ⇒ User
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
19 20 21 22 23 24 25 26 27 |
# File 'lib/rsteamshot/user.rb', line 19 def initialize(user_name, per_page: 10) @user_name = user_name 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 |
Instance Attribute Details
#user_name ⇒ Object (readonly)
Public: Returns a String user name from a Steam user’s public profile.
12 13 14 |
# File 'lib/rsteamshot/user.rb', line 12 def user_name @user_name end |
Instance Method Details
#screenshots(order: nil, page: 1, app_id: 0) ⇒ Object
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.
38 39 40 41 42 43 |
# File 'lib/rsteamshot/user.rb', line 38 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 |