Module: TriviaCrack::API::Login

Includes:
Common
Included in:
Client
Defined in:
lib/triviacrack/api/login.rb

Instance Method Summary collapse

Methods included from Common

#get, #post

Instance Method Details

#login(email, password) ⇒ Object

Public: Uses the given email and password to log in to Trivia Crack and retrieve a session id and user id.

email - Email of a Trivia Crack user. password - Password of a Trivia Crack user.

Examples

 "[email protected]", "password123"

Returns the user_id and username of the user that has logged in. Raises TriviaCrack::Errors::RequestError if the request fails.



24
25
26
27
28
29
30
31
# File 'lib/triviacrack/api/login.rb', line 24

def (email, password)
  response = post "/api/login", parameters: { email: email,
                                              password: password,
                                              language: "en"
                                            }.to_json

  @session = TriviaCrack::Parsers::SessionParser.parse response.body
end