lib/triviacrack/api/game.rb in triviacrack-0.5.1 vs lib/triviacrack/api/game.rb in triviacrack-0.6.0
- old
+ new
@@ -1,5 +1,6 @@
+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.
@@ -19,11 +20,11 @@
# Returns a list of TriviaCrack::Game.
# Raises TriviaCrack:Errors::RequestError if the request fails.
def get_games
response = get "/api/users/#{@session.user_id}/dashboard"
- games_data = response.body["list"]
+ games_data = response["list"]
games = []
if games_data
games_data.each do |game_data|
game = TriviaCrack::Parsers::GameParser.parse game_data
@@ -46,11 +47,11 @@
# Returns the TriviaCrack::Game for the given game_id.
# Raises TriviaCrack:Errors::RequestError if the request fails.
def get_game(game_id)
response = get "/api/users/#{@session.user_id}/games/#{game_id}"
- TriviaCrack::Parsers::GameParser.parse response.body
+ TriviaCrack::Parsers::GameParser.parse response
end
# Public: Uses the Trivia Crack API to start a new game for the current
# user.
#
@@ -60,12 +61,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_s
+ parameters: { language: "EN" }.to_json
- TriviaCrack::Parsers::GameParser.parse response.body
+ TriviaCrack::Parsers::GameParser.parse response
end
end
end
end