Sha256: 6246a54f115b84345490376c76f84adb448b2a4ad58e1bb472c3b678d32ff858

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require 'triviacrack/api/common'

# Public: Interface to the Trivia Crack Profile API.
module TriviaCrack
  module API
    module Profile
      include TriviaCrack::API::Common

      # Public: Uses the Trivia Crack API to get the profile of the user with
      # the given user id.
      #
      # user_id  - The unique identifier of the user.
      #
      # Examples
      #
      #   profile = client.get_profile 123
      #
      # Returns the TriviaCrack::Profile for the given user.
      # Raises TriviaCrack::Errors::RequestError if the request fails.
      def get_profile(user_id)
        response = get "/api/users/#{@session.user_id}/profiles/#{user_id}"

        TriviaCrack::Parsers::ProfileParser.parse response
      end

      # Public: Uses the Trivia Crack API to get the profile of current user.
      #
      # Examples
      #
      #   profile = client.get_my_profile
      #
      # Returns the TriviaCrack::Profile for the current user.
      # Raises TriviaCrack::Errors::RequestError if the request fails.
      def get_my_profile # rubocop:disable Naming/AccessorMethodName
        response =
          get "/api/users/#{@session.user_id}/profiles/#{@session.user_id}"

        TriviaCrack::Parsers::ProfileParser.parse response
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
triviacrack-0.8.0 lib/triviacrack/api/profile.rb
triviacrack-0.7.0 lib/triviacrack/api/profile.rb