Class: Rsteamshot::User

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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


22
23
24
25
26
# 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

Instance Attribute Details

#per_pageObject

Public: Returns the number of screenshots that will be fetched per page for this user.



15
16
17
# File 'lib/rsteamshot/user.rb', line 15

def per_page
  @per_page
end

#user_nameObject (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.



37
38
39
40
41
42
# 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