From 0f93fd9ac4ece59b0a41356a9bac01f442ac6480 Mon Sep 17 00:00:00 2001 From: Farhan Hadi Date: Sat, 25 Apr 2020 14:24:49 +0800 Subject: [PATCH] Added api key configuration --- config/config.php | 8 -- config/opendota.php | 8 ++ src/LaravelOpendota.php | 103 +++++++++++++------------ src/LaravelOpendotaServiceProvider.php | 49 ++++++------ tests/ExampleTest.php | 12 +-- 5 files changed, 91 insertions(+), 89 deletions(-) delete mode 100644 config/config.php create mode 100644 config/opendota.php diff --git a/config/config.php b/config/config.php deleted file mode 100644 index 48d0ee9..0000000 --- a/config/config.php +++ /dev/null @@ -1,8 +0,0 @@ - null, +]; diff --git a/src/LaravelOpendota.php b/src/LaravelOpendota.php index ea39fb2..9ff176e 100644 --- a/src/LaravelOpendota.php +++ b/src/LaravelOpendota.php @@ -11,6 +11,7 @@ class LaravelOpendota public function __construct() { $this->api_url = 'https://api.opendota.com/api/'; + $this->api_key = ['api_key' => config('opendota.api_key')]; } /** @@ -19,7 +20,7 @@ public function __construct() */ public function getPlayer($player_id) { - return Http::get($this->api_url . 'players/' . $player_id); + return Http::get($this->api_url . 'players/' . $player_id , $this->api_key); } /** @@ -29,7 +30,7 @@ public function getPlayer($player_id) */ public function getPlayerWL($player_id, $params = []) { - return Http::get($this->api_url . 'players/' . $player_id . '/wl', $params); + return Http::get($this->api_url . 'players/' . $player_id . '/wl', array_merge($this->api_key, $params)); } /** @@ -38,7 +39,7 @@ public function getPlayerWL($player_id, $params = []) */ public function getPlayerRecentMatches($player_id) { - return Http::get($this->api_url . 'players/' . $player_id . '/recentMatches'); + return Http::get($this->api_url . 'players/' . $player_id . '/recentMatches', $this->api_key); } /** @@ -48,7 +49,7 @@ public function getPlayerRecentMatches($player_id) */ public function getPlayerMatches($player_id, $params = []) { - return Http::get($this->api_url . 'players/' . $player_id . '/matches', $params); + return Http::get($this->api_url . 'players/' . $player_id . '/matches', array_merge($this->api_key, $params)); } /** @@ -58,7 +59,7 @@ public function getPlayerMatches($player_id, $params = []) */ public function getPlayerHeroes($player_id, $params = []) { - return Http::get($this->api_url . 'players/' . $player_id . '/heroes', $params); + return Http::get($this->api_url . 'players/' . $player_id . '/heroes', array_merge($this->api_key, $params)); } /** @@ -68,7 +69,7 @@ public function getPlayerHeroes($player_id, $params = []) */ public function getPlayerPeers($player_id, $params = []) { - return Http::get($this->api_url . 'players/' . $player_id . '/peers', $params); + return Http::get($this->api_url . 'players/' . $player_id . '/peers', array_merge($this->api_key, $params)); } /** @@ -78,7 +79,7 @@ public function getPlayerPeers($player_id, $params = []) */ public function getPlayerPros($player_id, $params = []) { - return Http::get($this->api_url . 'players/' . $player_id . '/pros', $params); + return Http::get($this->api_url . 'players/' . $player_id . '/pros', array_merge($this->api_key, $params)); } /** @@ -88,7 +89,7 @@ public function getPlayerPros($player_id, $params = []) */ public function getPlayerTotals($player_id, $params = []) { - return Http::get($this->api_url . 'players/' . $player_id . '/totals', $params); + return Http::get($this->api_url . 'players/' . $player_id . '/totals', array_merge($this->api_key, $params)); } /** @@ -98,7 +99,7 @@ public function getPlayerTotals($player_id, $params = []) */ public function getPlayerCounts($player_id, $params = []) { - return Http::get($this->api_url . 'players/' . $player_id . '/counts', $params); + return Http::get($this->api_url . 'players/' . $player_id . '/counts', array_merge($this->api_key, $params)); } /** @@ -109,7 +110,7 @@ public function getPlayerCounts($player_id, $params = []) */ public function getPlayerHistograms($player_id, $field = "", $params = []) { - return Http::get($this->api_url . 'players/' . $player_id . '/histograms/' . $field , $params); + return Http::get($this->api_url . 'players/' . $player_id . '/histograms/' . $field , array_merge($this->api_key, $params)); } /** @@ -119,7 +120,7 @@ public function getPlayerHistograms($player_id, $field = "", $params = []) */ public function getPlayerWardmap($player_id, $params = []) { - return Http::get($this->api_url . 'players/' . $player_id . '/wardmap', $params); + return Http::get($this->api_url . 'players/' . $player_id . '/wardmap', array_merge($this->api_key, $params)); } /** @@ -129,7 +130,7 @@ public function getPlayerWardmap($player_id, $params = []) */ public function getPlayerWordcloud($player_id, $params = []) { - return Http::get($this->api_url . 'players/' . $player_id . '/wordcloud', $params); + return Http::get($this->api_url . 'players/' . $player_id . '/wordcloud', array_merge($this->api_key, $params)); } /** @@ -139,7 +140,7 @@ public function getPlayerWordcloud($player_id, $params = []) */ public function getPlayerRatings($player_id, $params = []) { - return Http::get($this->api_url . 'players/' . $player_id . '/ratings', $params); + return Http::get($this->api_url . 'players/' . $player_id . '/ratings', array_merge($this->api_key, $params)); } /** @@ -148,7 +149,7 @@ public function getPlayerRatings($player_id, $params = []) */ public function getPlayerRankings($player_id) { - return Http::get($this->api_url . 'players/' . $player_id . '/rankings'); + return Http::get($this->api_url . 'players/' . $player_id . '/rankings', $this->api_key); } /** @@ -157,7 +158,7 @@ public function getPlayerRankings($player_id) */ public function postPlayerRefresh($player_id) { - return Http::post($this->api_url . 'players/' . $player_id . '/refresh'); + return Http::post($this->api_url . 'players/' . $player_id . '/refresh', $this->api_key); } /** @@ -166,7 +167,7 @@ public function postPlayerRefresh($player_id) */ public function getMatch($match_id) { - return Http::get($this->api_url . 'matches/' . $match_id); + return Http::get($this->api_url . 'matches/' . $match_id, $this->api_key); } /** @@ -174,7 +175,7 @@ public function getMatch($match_id) */ public function getPlayersByRank() { - return Http::get($this->api_url . 'playersByRank'); + return Http::get($this->api_url . 'playersByRank', $this->api_key); } /** @@ -182,7 +183,7 @@ public function getPlayersByRank() */ public function getProPlayers() { - return Http::get($this->api_url . 'proPlayers'); + return Http::get($this->api_url . 'proPlayers', $this->api_key); } /** @@ -190,7 +191,7 @@ public function getProPlayers() */ public function getProMatches() { - return Http::get($this->api_url . 'proMatches'); + return Http::get($this->api_url . 'proMatches', $this->api_key); } /** @@ -198,7 +199,7 @@ public function getProMatches() */ public function getPublicMatches() { - return Http::get($this->api_url . 'publicMatches'); + return Http::get($this->api_url . 'publicMatches', $this->api_key); } /** @@ -206,7 +207,7 @@ public function getPublicMatches() */ public function getParsedMatches() { - return Http::get($this->api_url . 'parsedMatches'); + return Http::get($this->api_url . 'parsedMatches', $this->api_key); } /** @@ -214,7 +215,7 @@ public function getParsedMatches() */ public function getMetadata() { - return Http::get($this->api_url . 'metadata'); + return Http::get($this->api_url . 'metadata', $this->api_key); } /** @@ -222,7 +223,7 @@ public function getMetadata() */ public function getDistributions() { - return Http::get($this->api_url . 'distributions'); + return Http::get($this->api_url . 'distributions', $this->api_key); } /** @@ -231,7 +232,7 @@ public function getDistributions() */ public function searchPlayers($personaname) { - return Http::get($this->api_url . 'search', ['q' => $personaname]); + return Http::get($this->api_url . 'search', array_merge($this->api_key, ['q' => $personaname])); } /** @@ -240,7 +241,7 @@ public function searchPlayers($personaname) */ public function getRankingsByHero($hero_id) { - return Http::get($this->api_url . 'rankings', ['hero_id' => $hero_id]); + return Http::get($this->api_url . 'rankings', array_merge($this->api_key, ['hero_id' => $hero_id])); } /** @@ -249,7 +250,7 @@ public function getRankingsByHero($hero_id) */ public function getBenchmarks($hero_id) { - return Http::get($this->api_url . 'benchmarks', ['hero_id' => $hero_id]); + return Http::get($this->api_url . 'benchmarks', array_merge($this->api_key, ['hero_id' => $hero_id])); } /** @@ -257,7 +258,7 @@ public function getBenchmarks($hero_id) */ public function getStatus() { - return Http::get($this->api_url . 'status'); + return Http::get($this->api_url . 'status', $this->api_key); } /** @@ -265,7 +266,7 @@ public function getStatus() */ public function getHealth() { - return Http::get($this->api_url . 'health'); + return Http::get($this->api_url . 'health', $this->api_key); } /** @@ -274,7 +275,7 @@ public function getHealth() */ public function getRequest($job_id) { - return Http::get($this->api_url . 'request/' . $job_id); + return Http::get($this->api_url . 'request/' . $job_id, $this->api_key); } /** @@ -283,7 +284,7 @@ public function getRequest($job_id) */ public function postRequest($match_id) { - return Http::get($this->api_url . 'request/' . $match_id); + return Http::get($this->api_url . 'request/' . $match_id, $this->api_key); } /** @@ -291,7 +292,7 @@ public function postRequest($match_id) */ public function getHeroes() { - return Http::get($this->api_url . 'heroes'); + return Http::get($this->api_url . 'heroes', $this->api_key); } /** @@ -300,7 +301,7 @@ public function getHeroes() */ public function getHeroMatches($hero_id) { - return Http::get($this->api_url . 'heroes/' . $hero_id . '/matches'); + return Http::get($this->api_url . 'heroes/' . $hero_id . '/matches', $this->api_key); } /** @@ -309,7 +310,7 @@ public function getHeroMatches($hero_id) */ public function getHeroMatchups($hero_id) { - return Http::get($this->api_url . 'heroes/' . $hero_id . '/matchups'); + return Http::get($this->api_url . 'heroes/' . $hero_id . '/matchups', $this->api_key); } /** @@ -318,7 +319,7 @@ public function getHeroMatchups($hero_id) */ public function getHeroDurations($hero_id) { - return Http::get($this->api_url . 'heroes/' . $hero_id . '/durations'); + return Http::get($this->api_url . 'heroes/' . $hero_id . '/durations', $this->api_key); } /** @@ -327,7 +328,7 @@ public function getHeroDurations($hero_id) */ public function getHeroPlayers($hero_id) { - return Http::get($this->api_url . 'heroes/' . $hero_id . '/players'); + return Http::get($this->api_url . 'heroes/' . $hero_id . '/players', $this->api_key); } /** @@ -336,7 +337,7 @@ public function getHeroPlayers($hero_id) */ public function getHeroItemPopularity($hero_id) { - return Http::get($this->api_url . 'heroes/' . $hero_id . '/itemPopularity'); + return Http::get($this->api_url . 'heroes/' . $hero_id . '/itemPopularity', $this->api_key); } /** @@ -344,7 +345,7 @@ public function getHeroItemPopularity($hero_id) */ public function getHeroStats() { - return Http::get($this->api_url . 'heroStats'); + return Http::get($this->api_url . 'heroStats', $this->api_key); } /** @@ -352,7 +353,7 @@ public function getHeroStats() */ public function getLeagues() { - return Http::get($this->api_url . 'leagues'); + return Http::get($this->api_url . 'leagues', $this->api_key); } /** @@ -360,7 +361,7 @@ public function getLeagues() */ public function getTeams() { - return Http::get($this->api_url . 'teams'); + return Http::get($this->api_url . 'teams', $this->api_key); } /** @@ -369,7 +370,7 @@ public function getTeams() */ public function getTeam($team_id) { - return Http::get($this->api_url . 'teams/' . $team_id); + return Http::get($this->api_url . 'teams/' . $team_id, $this->api_key); } /** @@ -378,7 +379,7 @@ public function getTeam($team_id) */ public function getTeamMatches($team_id) { - return Http::get($this->api_url . 'teams/' . $team_id . '/matches'); + return Http::get($this->api_url . 'teams/' . $team_id . '/matches', $this->api_key); } /** @@ -387,7 +388,7 @@ public function getTeamMatches($team_id) */ public function getTeamsPlayer($team_id) { - return Http::get($this->api_url . 'teams/' . $team_id . '/players'); + return Http::get($this->api_url . 'teams/' . $team_id . '/players', $this->api_key); } /** @@ -396,7 +397,7 @@ public function getTeamsPlayer($team_id) */ public function getTeamsHeroes($team_id) { - return Http::get($this->api_url . 'teams/' . $team_id . '/heroes'); + return Http::get($this->api_url . 'teams/' . $team_id . '/heroes', $this->api_key); } /** @@ -405,7 +406,7 @@ public function getTeamsHeroes($team_id) */ public function getReplays($match_id) { - return Http::get($this->api_url . 'replays', ['match_id' => $match_id]); + return Http::get($this->api_url . 'replays', array_merge($this->api_key, ['match_id' => $match_id])); } /** @@ -414,7 +415,7 @@ public function getReplays($match_id) */ public function getRecords($field) { - return Http::get($this->api_url . 'records/' . $field); + return Http::get($this->api_url . 'records/' . $field, $this->api_key); } /** @@ -422,7 +423,7 @@ public function getRecords($field) */ public function getLive() { - return Http::get($this->api_url . 'live'); + return Http::get($this->api_url . 'live', $this->api_key); } /** @@ -431,7 +432,7 @@ public function getLive() */ public function getScenariosItemTimings($params = []) { - return Http::get($this->api_url . 'scenarios/itemTimings' , $params); + return Http::get($this->api_url . 'scenarios/itemTimings' , array_merge($this->api_key, $params)); } /** @@ -440,7 +441,7 @@ public function getScenariosItemTimings($params = []) */ public function getScenariosLaneRoles($params = []) { - return Http::get($this->api_url . 'scenarios/laneRoles' , $params); + return Http::get($this->api_url . 'scenarios/laneRoles' , array_merge($this->api_key, $params)); } /** @@ -449,7 +450,7 @@ public function getScenariosLaneRoles($params = []) */ public function getScenariosMisc($params = []) { - return Http::get($this->api_url . 'scenarios/misc' , $params); + return Http::get($this->api_url . 'scenarios/misc' , array_merge($this->api_key, $params)); } /** @@ -457,7 +458,7 @@ public function getScenariosMisc($params = []) */ public function getSchema() { - return Http::get($this->api_url . 'schema'); + return Http::get($this->api_url . 'schema', $this->api_key); } /** @@ -466,7 +467,7 @@ public function getSchema() */ public function getConstants($resource = '') { - return Http::get($this->api_url . 'constants', ['resource' => $resource]); + return Http::get($this->api_url . 'constants', array_merge($this->api_key, ['resource' => $resource])); } } diff --git a/src/LaravelOpendotaServiceProvider.php b/src/LaravelOpendotaServiceProvider.php index 7307765..05b15fe 100644 --- a/src/LaravelOpendotaServiceProvider.php +++ b/src/LaravelOpendotaServiceProvider.php @@ -19,29 +19,30 @@ public function boot() // $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); // $this->loadRoutesFrom(__DIR__.'/routes.php'); - // if ($this->app->runningInConsole()) { - // $this->publishes([ - // __DIR__ . '/../config/config.php' => config_path('laravel-opendota.php'), - // ], 'config'); - - // // Publishing the views. - // /*$this->publishes([ - // __DIR__.'/../resources/views' => resource_path('views/vendor/laravel-opendota'), - // ], 'views');*/ - - // // Publishing assets. - // /*$this->publishes([ - // __DIR__.'/../resources/assets' => public_path('vendor/laravel-opendota'), - // ], 'assets');*/ - - // // Publishing the translation files. - // /*$this->publishes([ - // __DIR__.'/../resources/lang' => resource_path('lang/vendor/laravel-opendota'), - // ], 'lang');*/ - - // // Registering package commands. - // // $this->commands([]); - // } + if ($this->app->runningInConsole()) { + + $this->publishes([ + __DIR__ . '/../config/opendota.php' => config_path('laravel-opendota.php'), + ], 'config'); + + // Publishing the views. + /*$this->publishes([ + __DIR__.'/../resources/views' => resource_path('views/vendor/laravel-opendota'), + ], 'views');*/ + + // Publishing assets. + /*$this->publishes([ + __DIR__.'/../resources/assets' => public_path('vendor/laravel-opendota'), + ], 'assets');*/ + + // Publishing the translation files. + /*$this->publishes([ + __DIR__.'/../resources/lang' => resource_path('lang/vendor/laravel-opendota'), + ], 'lang');*/ + + // Registering package commands. + // $this->commands([]); + } } /** @@ -50,7 +51,7 @@ public function boot() public function register() { // Automatically apply the package configuration - //$this->mergeConfigFrom(__DIR__ . '/../config/config.php', 'laravel-opendota'); + $this->mergeConfigFrom(__DIR__ . '/../config/opendota.php', 'laravel-opendota'); // Register the main class to use with the facade $this->app->singleton('opendota', function () { diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php index ecc6501..60cd6b0 100644 --- a/tests/ExampleTest.php +++ b/tests/ExampleTest.php @@ -42,12 +42,12 @@ public function test_laravel_http_player() // $this->assertSame(113429216, $player); // } - // public function test_get_players_by_rank_function() - // { - // $openDota = new LaravelOpendota(); + public function test_get_players_by_rank_function() + { + $openDota = new LaravelOpendota(); - // $players = $openDota->getLive(); + $players = $openDota->getLive(); - // dd($players->json()); - // } + dd($players->json()); + } }