module TriviaCrack::API::User
Public Instance Methods
get_user()
click to toggle source
Public: Uses the Trivia Crack API
to retrieve the user data.
Returns a TriviaCrack::User
representing the current user. Raises TriviaCrack::Errors::RequestError
if the request fails
# File lib/triviacrack/api/user.rb, line 48 def get_user response = get "/api/users/#{@session.user_id}" TriviaCrack::Parsers::UserParser.parse response.body end
get_user_id(username)
click to toggle source
Public: Uses the Trivia Crack Search API
to find the numeric user id of the user identified by the given username.
username - Trivia Crack username of a user (e.g. “@example”).
Examples
get_user_id "@example"
Returns the user id of the user. Raises TriviaCrack:Errors::RequestError if the request fails.
# File lib/triviacrack/api/user.rb, line 23 def get_user_id(username) # Trim the @ character from the start of the username if username.start_with? "@" username = username[1..-1] end response = get "/api/search?username=#{username}" body = response.body user_id = false body["list"].each do |user| if user["username"] == username user_id = user["id"] break end end user_id end