2017 © Pedro Peláez
 

library ght-mojang-api-client

GHT Mojang API Client

image

greenhollowtech/ght-mojang-api-client

GHT Mojang API Client

  • Monday, October 10, 2016
  • by iisisrael
  • Repository
  • 0 Watchers
  • 0 Stars
  • 56 Installations
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 14 % Grown

The README.md

GHT Mojang API Client

The Mojang API Client provides methods to access the Mojang API in PHP applications. For API methods that require it, the client also provides authentication via the Mojang Authentication API., (*1)

Installation

Get the Composer package

To install with Composer, run composer require greenhollowtech/ght-mojang-api-client., (*2)

Usage

To create an instance of the client:, (*3)

use GHT\MojangApiClient\GHTMojangApiClient;

// Instantiate the client
$client = GHTMojangApiClient::createApiClient();
$client = GHTMojangApiClient::createAuthenticationClient();
$client = GHTMojangApiClient::createSessionClient();
$client = GHTMojangApiClient::createStatusClient();

// The client can be be instantiated the long way
$targetApi = GHTMojangApiClient::SUBDOMAIN_API;
$client = GHTMojangApiClient::create($targetApi);

// Other targets
$targetApi = GHTMojangApiClient::SUBDOMAIN_OAUTH;
$targetApi = GHTMojangApiClient::SUBDOMAIN_SESSION;
$targetApi = GHTMojangApiClient::SUBDOMAIN_STATUS;

Then use the client to call any of the related methods for that client, described below., (*4)

API Methods

Basic API

$client = GHTMojangApiClient::createApiClient();

// Get all names a user has ever used
$names = $client->getNames($uuid);

// Get the UUID for the user currently or in the past using a given name
$profile = $client->getProfileForName('SomeDude');
$profile = $client->getProfileForName('SomeDude', new \DateTime('-1 month'));

// Get the UUIDs (and possibly other limited information) of a list of names
$profiles = $client->getProfilesForNames(array('SomeDude', 'SomeOtherDude'));

// Get Mojang statistics
$statistics = $client->getStatistics();
$metrics = array('item_sold_minecraft', 'item_sold_scrolls');
$statistics = $client->getStatistics($metrics);
$splitByMetric = true;
$statistics = $client->getStatistics($metrics, $splitByMetric);

Authentication API

use GHT\MojangApiClient\Exception\MojangApiException;

$authClient = GHTMojangApiClient::createAuthenticationClient();

try {
    // Client will transport the credentials to use with other API requests
    $authClient->authenticate($email, $password);

    // Authenticating with a game as the agent provides better credentials
    $authClient->authenticate($email, $password, 'Minecraft');

    // Refreshes the API token transported in the client
    $authClient->refresh();

    // Will throw an exception if not valid, otherwise returns nothing
    $authClient->validate();

    // End the authenticated session by invalidating the token
    $authClient->invalidate();

    // End the authenticated session using the login name and password
    $authClient->signOut($email, $password);
}
catch (MojangApiException $e) {
    echo $e->getMessage();
}

Basic API With Authentication

use GHT\MojangApiClient\Exception\MojangApiException;

// Use an authentication client to get the credentials for the API client
$authClient = GHTMojangApiClient::createAuthenticationClient();
try {
    $authClient->authenticate($email, $password);
}
catch (MojangApiException $e) {
    // login failed, go somewhere else
}
$client = GHTMojangApiClient::createApiClient($authClient->getCredentials());

// Change a skin
try {
    $client->changeSkin($uuid, $url, 'slim');
}
catch (MojangApiExceptin $e) {
    echo $e->getMessage();
}

// Get the current user's information
$userInfo = $client->getUserInformation();

// Reset the user's skin
try {
    $client->resetSkin($uuid);
}
catch (MojangApiExceptin $e) {
    echo $e->getMessage();
}

// Upload a skin
try {
    $client->uploadSkin($uuid, '/tmp/skinFile.png', 'slim');
}
catch (MojangApiExceptin $e) {
    echo $e->getMessage();
}

Session API

$client = GHTMojangApiClient::createSessionClient();

// Get blocked server hashes
$hashes = $client->getBlockedServerHashes();
$serverIsBlocked = in_array(sha1('*.myservername.com'), $hashes);

// Get profile data for a UUID
$profile = $client->getProfile($uuid);

Status API

// Get statuses for all services
$statuses = $client->getStatus();
$minecraftStatus = $statuses['minecraft.net'];

The Versions

10/10 2016

dev-master

9999999-dev https://bitbucket.org/greenhollowtech/ght-mojang-api-client

GHT Mojang API Client

  Sources   Download

MIT

The Requires

 

The Development Requires

api php client minecraft mojang

10/10 2016

1.1.0

1.1.0.0 https://bitbucket.org/greenhollowtech/ght-mojang-api-client

GHT Mojang API Client

  Sources   Download

MIT

The Requires

 

The Development Requires

api php client minecraft mojang

15/08 2016

1.0.2

1.0.2.0 https://bitbucket.org/greenhollowtech/ght-mojang-api-client

GHT Mojang API Client

  Sources   Download

MIT

The Requires

 

The Development Requires

api php client minecraft mojang

31/07 2016

1.0.1

1.0.1.0 https://bitbucket.org/greenhollowtech/ght-mojang-api-client

GHT Mojang API Client

  Sources   Download

MIT

The Requires

 

The Development Requires

api php client minecraft mojang

25/07 2016

1.0.0

1.0.0.0 https://bitbucket.org/greenhollowtech/ght-mojang-api-client

GHT Mojang API Client

  Sources   Download

MIT

The Requires

 

The Development Requires

api php client minecraft mojang

25/07 2016

0.1.2

0.1.2.0 https://bitbucket.org/greenhollowtech/ght-mojang-api-client

GHT Mojang API Client

  Sources   Download

MIT

The Requires

 

The Development Requires

api php client minecraft mojang

22/07 2016

0.1.1

0.1.1.0 https://bitbucket.org/greenhollowtech/ght-mojang-api-client

GHT Mojang API Client

  Sources   Download

MIT

The Requires

 

The Development Requires

api php client minecraft mojang

21/07 2016

0.1.0

0.1.0.0 https://bitbucket.org/greenhollowtech/ght-mojang-api-client

GHT Mojang API Client

  Sources   Download

MIT

The Requires

 

The Development Requires

api php client minecraft mojang