0.0
Low commit activity in last 3 years
No release in over a year
A Ruby interface to the Trivia Crack API.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3.0
~> 2.3.18
~> 2.5.1
~> 13.0.6
~> 3.11.0
~> 0.21.2
~> 1.31.2

Runtime

~> 2.3.0
~> 2.6.2
 Project Readme

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 "user@example.com", "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://github.com/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