Sha256: 0facbd2d2a9abb888f901504cfd47d9eb7e3da9d3eb5ba571f90a7dda67c3e06

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require "json"
require "triviacrack/api/common"
require "triviacrack/parsers/session_parser"

# Public: All methods in this module make requests to the Trivia Crack login
# API.
module TriviaCrack
  module API
    module Login

      include TriviaCrack::API::Common

      # 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
      #
      #   login "user@example.com", "password123"
      #
      # Returns the user_id and username of the user that has logged in.
      # Raises TriviaCrack::Errors::RequestError if the request fails.
      def login(email, password)
        response = post "/api/login", parameters: { email: email,
                                                    password: password,
                                                    language: "en"
                                                  }.to_json

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

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
triviacrack-0.6.0 lib/triviacrack/api/login.rb