Git Product home page Git Product logo

challongephp's Introduction

ChallongePHP

Test Latest Version Downloads

PSR-18 compliant package for interfacing with the Challonge API.

Installation

Refer to the table for PHP version compatibility:

ChallongePHP Ver. Compatible PHP
^5.0 8.1 - 8.2
^4.0 8.0 - 8.1
^3.0 7.4 - 8.0
^2.1 7.4
^2.0 7.4
^1.0 7.0 - 7.4

Install via composer:

composer require team-reflex/challonge-php:version

Usage

As the package is PSR-18 compliant, it does not come with an HTTP client by default.

You can use a client such as Guzzle, and pass an instance of it when instantiating:

$http = new GuzzleHttp\Client();
$challonge = new Challonge($http, 'api_key_here', true);

By default, the package maps the keys of any input, as Challonge requires its input to be in a format such as:

$tournament = $challonge->createTournament([
    'tournament[name]' => 'test'
]);

Which means you are able to use the package without prefixing your keys:

$tournament = $challonge->createTournament([
    'name' => 'test'
]);

You can change the third argument to false to disable this mapping if you would prefer to do it yourself.

Now you're ready to make requests:

$tournament = $challonge->fetchTournament('challongephptest');

API Updates

Challonge does not lock their API and has been consistently adding new fields to objects, thus breaking strongly typed DTOs.

As of 3.0.4, all three DTOs have been marked to ignore missing fields. If Challonge adds a new field, it will no longer throw a DataTransferObjectError, but the DTO will also however not contain that new field.

Documentation

As the package is fully type-hinted, everything should be self documenting, however there is documentation in the wiki.

Contact

challongephp's People

Contributors

apfelwurm avatar clamburger avatar dependabot[bot] avatar kylekz avatar xkairu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

challongephp's Issues

Spatie\DataTransferObject\DataTransferObjectError

I couldn't get this to work until i added

public ?string $team_size_range; public ?string $toxic; public ?string $use_new_style; public array $optional_display_data;
to vendor\team-reflex\challonge-php\src\Challonge\DTO\Tournament.php

Is it just me or does challonge not lock api versions?
I feel like this will break often in the future..

version 3.0.3

Library is not compatible with all PSR-18 clients

The following lines in ClientWrapper.php use a Guzzle-specific call that does not work with a standard PSR-18 client:

$response = $this->client->request($method, $base_uri, [
'query' => ['api_key' => $this->getKey()],
'form_params' => $content,
'headers' => $this->buildHeaders(),
'http_errors' => false,
'verify' => false,
]);

For example, when used with the Symfony HTTP client, I receive this error:
Attempted to call an undefined method named "request" of class "Symfony\Component\HttpClient\Psr18Client".

The best approach would be to pass down a RequestFactoryInterface (as defined in PSR-17) in order to construct a PSR-7 request. This might require a breaking change to the Challonge class, so an alternative option could be to add a dependency on a specific PSR-7 implementation and construct the request object directly. In both cases, you would then pass that request object to $this->client->sendRequest().

bulkAddParticipant

bulkAddParticipant

what is the syntax for this ? this is what i have tried:

        $postSquads[] = $comp->addParticipant(['participant[name]' => $team->name, 'participant[seed]' => $key + 1, 'participant[misc]' => $team->id]);


        // 'participant[][name]'=>1, 'participant[][seed]'=>1, 'participant[][misc]'=>'team_id', 'participant[][email]'=>'[email protected]',


    // $postSquads = $comp->bulkAddParticipant([
    // 'participant[][name]'=>1, 'participant[][seed]'=>1, 'participant[][misc]'=>'team_id', 'participant[][email]'=>'[email protected]',
    // 	// 'participant[][name]'=>2, 'participant[][seed]'=>2, 'participant[][misc]'=>'team_id',
    // 	// 'participant[][name]'=>3, 'participant[][seed]'=>3, 'participant[][misc]'=>'team_id',
    // 	// 'participant[][name]'=>4, 'participant[][seed]'=>4, 'participant[][misc]'=>'team_id',
    // 	// 'participant[][name]'=>5, 'participant[][seed]'=>5, 'participant[][misc]'=>'team_id',
    // 	// 'participant[][name]'=>6, 'participant[][seed]'=>6, 'participant[][misc]'=>'team_id',
    // 	// 'participant[][name]'=>7, 'participant[][seed]'=>7, 'participant[][misc]'=>'team_id'
    // ]);

any examples?

/**
 * Bulk add participants to a tournament (up until it is started).
 * @param array $options
 * @return Collection
 * @throws \JsonException
 * @throws \Reflex\Challonge\Exceptions\InvalidFormatException
 * @throws \Reflex\Challonge\Exceptions\NotFoundException
 * @throws \Reflex\Challonge\Exceptions\ServerException
 * @throws \Reflex\Challonge\Exceptions\UnauthorizedException
 * @throws \Reflex\Challonge\Exceptions\UnexpectedErrorException
 * @throws \Reflex\Challonge\Exceptions\ValidationException
 */
public function bulkAddParticipant(array $options = []): Collection
{
    $response = $this->client->request('POST', "tournaments/{$this->id}/participants/bulk_add", $this->client->mapOptions($options, 'participant'));
    return Collection::make($response)
        ->map(fn (array $participant) => Participant::fromResponse($this->client, $participant['participant']));
}

Please add a simple use case

A quick glance of your source suggests that it is in working order, but a simple source would be appreciated, just to give an entry point and perhaps a warning about how not to use it.

Timeouts?

Hi,

My dev site is working fine, however having network level issue on production, timeout permanent error.

anyone else having issues with connecting to api?

yes i have contacted support a few months back

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.