fpicosm / sportmonks-football-api by fpicosm

A Laravel/Lumen wrapper for Sportmonks Football Api
40
1
1
Package Data
Maintainer Username: fpicosm
Maintainer Contact: fpicosm@gmail.com (Fernando Picos)
Package Create Date: 2022-10-10
Package Last Update: 2023-03-16
Language: PHP
License: MIT
Last Refreshed: 2024-04-22 03:01:39
Package Statistics
Total Downloads: 40
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 1
Total Watchers: 1
Total Forks: 0
Total Open Issues: 0

Sportmonks Football Api

Installation

Require the package via composer:

composer require fpicosm/sportmonks-football-api

Configuration

Update your .env file adding:

SPORTMONKS_TOKEN=#YOUR_API_TOKEN#
SPORTMONKS_TIMEZONE=#YOUR_TIMEZONE#

SPORTMONKS_TIMEZONE is optional. If not included, it is used the APP_TIMEZONE value.

Using Laravel

  1. Register the ServiceProvider in config/app.php, inside the providers section:

    Sportmonks\FootballApi\FootballApiServiceProvider::class,
    
  2. Publish the config file

    php artisan vendor:publish --provider="Sportmonks\FootballApi\FootballApiServiceProvider"
    

Using Lumen

  1. Create the folder config at the root of the project (if not exists).

  2. Create the file config/config_path.php (if not exists) and paste:

    <?php
    
    if (!function_exists('config_path')) {
        /**
         * Get the configuration path.
         *
         * @param string $path
         * @return string
         */
        function config_path($path = '')
        {
            return app()->basePath() . '/config' . ($path ? "/$path" : $path);
        }
    }
    
  3. Create the file config/football-api.php and paste:

    <?php
    
    return [
        'token' => env('SPORTMONKS_TOKEN'),
        'timezone' => env('SPORTMONKS_TIMEZONE') ?: env('APP_TIMEZONE'),
    ];
    
  4. Add the config files in bootstrap/app.php, inside the Register Config Files section:

    $app->configure('config_path');
    $app->configure('football-api');
    
  5. Add the ServiceProvider in bootstrap/app.php, inside the Register Service Providers section:

    $app->register(Sportmonks\FootballApi\FootballApiServiceProvider::class);
    
  6. Uncomment the line $app->withFacades(); in bootstrap/app.php

Usage

When needed, add the dependency:

use Sportmonks\FootballApi\FootballApi;

Then, you can call to FootballApi::endpoint()->method($params):

Include option

To include relations in response, use the include method. Example:

FootballApi::continents()->include('countries')->all();

You can pass an array, or a comma separated string:

FootballApi::countries()->include('leagues,continent')->all();
FootballApi::countries()->include(['leagues', 'continent'])->all();

If you want nested includes, use a single-dimension array:

FootballApi::seasons()->include(['fixtures.stage', 'fixtures.round', 'fixtures.group'])->find($id);

Pagination

To set the page number, use the page method:

FootballApi::countries()->page(2)->all();

To set the page size, use the perPage method:

FootballApi::countries()->perPage(150)->all();

The page size must be between 10 and 150 (default value is 100).

Endpoints

Bookmakers

Get all bookmakers

Documentation here

FootballApi::bookmakers()->all(?$params);

Get bookmaker by id

Documentation here

FootballApi::bookmakers()->find($id, ?$params);

Coaches

Get coach by id

Documentation here

FootballApi::coaches()->find($id, ?$params);

Continents

Get all continents

Documentation here

FootballApi::continents()->all(?$params);

Get continent by id

Documentation here

FootballApi::continents()->find($id, ?$params);

Countries

Get all countries

Documentation here

FootballApi::countries()->all(?$params);

Get country by id

Documentation here

FootballApi::countries()->find($id, ?$params);

Get leagues by country id

Documentation here

FootballApi::countries($id)->leagues(?$params);

Get players by country id

Documentation here

FootballApi::countries($id)->players(?$params);

Get teams by country id

Documentation here

FootballApi::countries($id)->teams(?$params);

Fixtures

Get fixture by id

Documentation here

FootballApi::fixtures()->find($id, ?$params);

Get last updated fixtures

Documentation here

FootballApi::fixtures()->lastUpdated(?$params);

Get fixtures by date

Documentation here

FootballApi::fixtures()->byDate($date, ?$params);

Get fixtures by date range

Documentation here

FootballApi::fixtures()->byDateRange($startDate, $endDate, ?$params);

Get fixtures by multiple id's

Documentation here

FootballApi::fixtures()->multiple($list, ?$params);

The $list could be an array [1, 2] or a comma separated string 1,2

Get deleted fixtures

Documentation here

FootballApi::fixtures()->deleted(?$params);

Get bookmakers by fixture id

Documentation here

FootballApi::fixtures($id)->bookmakers(?$params);

Get commentaries by fixture id

Documentation here

FootballApi::fixtures($id)->commentaries(?$params);

Get video highlights by fixture id

Documentation here

FootballApi::fixtures($id)->highlights(?$params);

Get tv stations by fixture id

Documentation here

FootballApi::fixtures($id)->tvStations(?$params);

Leagues

Get all leagues

Documentation here

FootballApi::leagues()->all(?$params);

Get league by id

Documentation here

FootballApi::leagues()->find($id, ?$params);

Search leagues by name

Documentation here

FootballApi::leagues()->search($name, ?$params);

Livescores

Get all livescores

Documentation here

FootballApi::livescores()->all(?$params);

Get all in play livescores

Documentation here

FootballApi::livescores()->playing(?$params);

Markets

Get all markets

Documentation here

FootballApi::markets()->all(?$params);

Get market by id

Documentation here

FootballApi::markets()->find($id, ?$params);

Get all fixtures by market id

Documentation here

FootballApi::markets($id)->fixtures(?$params);

News

Get all news

Documentation here

FootballApi::news()->all(?$params);

Get news for upcoming fixtures

Documentation here

FootballApi::news()->upcoming(?$params);

Players

Get player by id

Documentation here

FootballApi::players()->find($id, ?$params);

Search players by name

Documentation here

FootballApi::players()->search($name, ?$params);

Rounds

Get round by id

Documentation here

FootballApi::rounds()->find($id, ?$params);

Get standings by season id and round id

Documentation here

FootballApi::rounds($id)->standings($seasonId, ?$params);

Seasons

Get all seasons

Documentation here

FootballApi::seasons()->all(?$params);

Get season by id

Documentation here

FootballApi::seasons()->find($id, ?$params);

Get news by season id

Documentation here

FootballApi::seasons($id)->news(?$params);

Get rounds by season id

Documentation here

FootballApi::seasons($id)->rounds(?$params);

Get team squad by team and season id

Documentation here

FootballApi::seasons($id)->squad($teamId, ?$params);

Get stages by season id

Documentation here

FootballApi::seasons($id)->stages(?$params);

Get standings by season id

Documentation here

FootballApi::seasons($id)->standings(false, ?$params);

Get live standings

Documentation here

FootballApi::seasons($id)->standings(true, ?$params);

Get standings by season and date

Documentation here

FootballApi::seasons($id)->standingsByDate($date, ?$params);

Get standings corrections by season id

Documentation here

FootballApi::seasons($id)->standingsCorrection(?$params);

Get teams by season id

Documentation here

FootballApi::seasons($id)->teams(?$params);

Get topscorers by season id

Documentation here

FootballApi::seasons($id)->topscorers(false, ?$params);

Get topscorers aggregated by season id

Documentation here

FootballApi::seasons($id)->topscorers(true, ?$params);

Get venues by season id

Documentation here

FootballApi::seasons($id)->venues(?$params);

Stages

Get stage by id

Documentation here

FootballApi::stages()->find($id, ?$params);

Teams

Get team by id

Documentation here

FootballApi::teams()->find($id, ?$params);

Search teams by name

Documentation here

FootballApi::teams()->search($name, ?$params);

Get all leagues by team id

Documentation here

FootballApi::teams($id)->leagues(true, ?$params);

Get current leagues by team id

Documentation here

FootballApi::teams($id)->leagues(false, ?$params);

Get fixtures by date range for team

Documentation here

FootballApi::teams($id)->fixturesByDateRange($startDate, $endDate, ?$params);

Get head 2 head by team id's

Documentation here

FootballApi::teams($id)->headToHead($rivalId, ?$params);

Get rivals by team id

Documentation here

FootballApi::teams($id)->rivals(?$params);

Get team squad by team and season id

Documentation here

FootballApi::teams($id)->squad($seasonId, ?$params);

Venues

Get venue by id

Documentation here

FootballApi::venues()->find($id, ?$params);