Skip to content

A Ruby interface to the Trivia Crack API.

License

Notifications You must be signed in to change notification settings

davidkus/triviacrack

Repository files navigation

Triviacrack Gem Version CI Code Climate Test Coverage

A Ruby interface for the Trivia Crack API.

The Trivia Crack iOS app uses an undocumented API to store / retrieve information about the game state. This Ruby library wraps that API and presents it in a clean, documented way.

Disclaimer: The Trivia Crack API is undocumented and subject to change at any time. Changes in the API may break this library.

Installation

Add this line to your application's Gemfile:

gem "triviacrack", github: "davidkus/triviacrack"

And then execute:

$ bundle install

Usage

First, create an instance of the TriviaCrack::API::Client.

require "triviacrack"

client = TriviaCrack::API::Client.new

Logging In

Use the client to log in using your Trivia Crack email and password.

client.login "[email protected]", "password123"

User Information

You can retrieve information about the currently logged in user.

user = client.get_user

puts "Hello, #{user.username}!"
 # => Hello, david!

You can also retrieve the user ID of the user with a given username.

user_id = client.get_user_id "david"

puts "david's user id is #{user_id}"
 # => david's user id is 1

User Profiles

You can retrieve additional information about a user by fetching their profile.

user_id = 123
profile = client.get_profile user_id

A user's profile contains their statistics (number of wins / losses, number of questions answered correctly, etc), among other things.

Game Information

You can retrieve the list of games available to the currently logged in user.

games = client.get_games

You can retrieve game information for a specific game (by id).

game = client.get_game 1

You can also start a new game.

game = client.start_new_game

The TriviaCrack::Game object holds information about the opponent, statistics, and current questions available to be answered.

Answering Questions

It is possible to answer questions using the Trivia Crack API.

game = client.get_game 1

client.answer_question game.id, game.question.first, 0

The answer_question also returns an updated TriviaCrack::Game object, so you can avoid making additional API calls to keep the game object up to date.

game = client.answer_question game.id, game.question.first, 0

Contributing

  1. Fork it ( https:/davidkus/triviacrack/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request