Giter Club home page Giter Club logo

gamejolt-api's Introduction

Gamejolt API PHP Library

CircleCI

https://gamejolt.com

This library provides full (except batching) coverage of Game Jolt's API (Trophies, Scores, Sessions, etc...) At the moment this library is written and tested for v1.2 of Game Jolt's API.

Installation

$ composer require "harrk/gamejolt-api"

Usage

Create an instance of GamejoltApi and provide a GamejoltConfig to begin making API calls to Game Jolt.

$gameId = 0; // Your game's ID
$gamePrivaykey = "Your game's private key";

$api = new GamejoltApi(new GamejoltConfig(
    $gameId,
    $gamePrivaykey
));

Endpoints

Below are examples of how you would interact with each endpoint. Bare in mind that these are only examples, and may not use all parameter options.

Refer to the Game Jolt API Documentation or the source code for more options.

Data Store

The Data Store API can be used to store/retrieve data in the cloud.

// Fetch the value for my-key
$api->dataStore()->fetch('my-key');

// Set the value for my-key to my-value
$api->dataStore()->set('my-key', 'my-value');

// Update player-logins by 1
$api->dataStore()->update('player-logins', DataStore::OPERATION_ADD, 1);

// Remove my-key
$api->dataStore()->remove('my-key');

// Fetch all keys
$api->dataStore()->getKeys();

Friends

The Friends API can only be used to find the friend IDs of the user currently.

// Fetch all friend ids for the user
$api->friends()->fetch('username', 'user-token');

Scores

//Fetch scores
$api->scores()->fetch();

//Fetch all score tables
$api->scores()->tables();

//Add a gamejolt user's score to the table
$api->scores()->addUserScore('username', 'user_token', '100 Jumps', 100);

//Add a guest's score to the table
$api->scores()->addGuestScore('Mr Guest', '50 jumps', 50);

//Get score rank
$api->scores()->getRank(60);

Sessions

//Open a session for the given user
$api->sessions()->open('username', 'user_token');

//Let GJ know the user session is still active
$api->sessions()->ping('username', 'user_token', Sessions::STATUS_ACTIVE);

//Check if the session is still open for user
$api->sessions()->check('username', 'user_token');

//Close the session for user
$api->sessions()->close('username', 'user_token');

Time

//Get GJ's server time
$api->time()->fetch();

Trophies

//Get all trophies
$api->trophies()->fetch('username', 'user_token');

//User has achieved a trophy with ID 1
$api->trophies()->addAchieved('username', 'user_token', 1);

//User unachieved trophy with ID 1
$api->trophies()->removeAchieved('username', 'user_token', 1);

Users

//Fetch data on user
$api->users()->fetch('username', 'user_token');

//Verify if the user's credentials are correct
$api->users()->auth('username', 'user_token');

Catching Exceptions

Here is a example on how to catch exceptions:

try {
    $auth = $api->users()->auth('username', 'user_token');
} catch (TimeOutException $e) {
    return redirect()->route('home')->with('error', $e->getMessage());
}

Testing

Two commands have been provided to simplify the running of tests.

Run Unit Tests

$ composer test

Run Static Code Analysis

$ composer analyse

Todo

  • Allow POST method on endpoints
  • Increase coverage of Unit Tests

License

MIT License

gamejolt-api's People

Contributors

dsbilling avatar harrk avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

dsbilling

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.