lib/triviacrack/api/game.rb in triviacrack-0.6.0 vs lib/triviacrack/api/game.rb in triviacrack-0.7.0

- old
+ new

@@ -1,15 +1,16 @@ -require "json" -require "triviacrack/api/common" -require "triviacrack/parsers/game_parser" +# frozen_string_literal: true +require 'json' +require 'triviacrack/api/common' +require 'triviacrack/parsers/game_parser' + # Public: All methods in this module make requests to the Trivia Crack games # API. module TriviaCrack module API module Game - include TriviaCrack::API::Common # Public: Uses the Trivia Crack API to fetch the list of games for the # current user. # @@ -17,21 +18,19 @@ # # get_games # # Returns a list of TriviaCrack::Game. # Raises TriviaCrack:Errors::RequestError if the request fails. - def get_games + def get_games # rubocop:disable Naming/AccessorMethodName response = get "/api/users/#{@session.user_id}/dashboard" - games_data = response["list"] + games_data = response['list'] games = [] - if games_data - games_data.each do |game_data| - game = TriviaCrack::Parsers::GameParser.parse game_data - games << game - end + games_data&.each do |game_data| + game = TriviaCrack::Parsers::GameParser.parse game_data + games << game end games end @@ -61,13 +60,12 @@ # # Returns the TriviaCrack::Game that was started. # Raises TriviaCrack::Errors::RequestError if the request fails def start_new_game response = post "/api/users/#{@session.user_id}/games", - parameters: { language: "EN" }.to_json + parameters: { language: 'EN' }.to_json TriviaCrack::Parsers::GameParser.parse response end - end end end