diff --git a/.styleci.yml b/.styleci.yml index c68d55d..14ffa25 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -3,15 +3,13 @@ preset: laravel risky: false enabled: -- alpha_ordered_imports - concat_with_spaces - no_empty_comment disabled: -- braces +- psr2_braces - phpdoc_no_package - concat_without_spaces -- length_ordered_imports - no_blank_lines_after_class_opening - no_blank_lines_after_throw @@ -19,4 +17,4 @@ finder: exclude: - "tests" name: - - "*.php" \ No newline at end of file + - "*.php" diff --git a/composer.json b/composer.json index dff719a..191f1b4 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ "cviebrock/discourse-php": "^0.9.3", "laravel/framework": "5.5.*", "eveseat/web": "3.0.*", - "ext-json": "*" + "ext-json": "*", + "guzzlehttp/guzzle": "^6.5" }, "autoload": { "psr-4": { diff --git a/src/Action/Discourse/Groups/Create.php b/src/Action/Discourse/Groups/Create.php index d573a95..bda67dc 100644 --- a/src/Action/Discourse/Groups/Create.php +++ b/src/Action/Discourse/Groups/Create.php @@ -20,16 +20,18 @@ class Create * @return string * @throws \Herpaderpaldent\Seat\SeatDiscourse\Exceptions\DiscourseGuzzleException */ - public function execute(String $groupname) : string + public function execute(string $groupname): string { $client = new Client(); try { $response = $client->request('POST', getenv('DISCOURSE_URL') . '/admin/groups', [ 'form_params' => [ - 'api_key' => getenv('DISCOURSE_API_KEY'), - 'api_username' => getenv('DISCOURSE_API_USERNAME'), 'group[name]' => $groupname, ], + 'headers' => [ + 'api-key' => getenv('DISCOURSE_API_KEY'), + 'api-username' => getenv('DISCOURSE_API_USERNAME'), + ], ]); if (200 === $response->getStatusCode()) { diff --git a/src/Action/Discourse/Groups/Delete.php b/src/Action/Discourse/Groups/Delete.php index bed7835..39a0dd3 100644 --- a/src/Action/Discourse/Groups/Delete.php +++ b/src/Action/Discourse/Groups/Delete.php @@ -25,9 +25,9 @@ public function execute(int $group_id) $client = new Client(); try { $response = $client->request('DELETE', getenv('DISCOURSE_URL') . '/admin/groups/' . $group_id . '.json', [ - 'form_params' => [ - 'api_key' => getenv('DISCOURSE_API_KEY'), - 'api_username' => getenv('DISCOURSE_API_USERNAME'), + 'headers' => [ + 'api-key' => getenv('DISCOURSE_API_KEY'), + 'api-username' => getenv('DISCOURSE_API_USERNAME'), ], ]); diff --git a/src/Action/Discourse/Groups/Get.php b/src/Action/Discourse/Groups/Get.php index 66b3329..02afd96 100644 --- a/src/Action/Discourse/Groups/Get.php +++ b/src/Action/Discourse/Groups/Get.php @@ -20,19 +20,19 @@ class Get * @return \Illuminate\Support\Collection * @throws \Herpaderpaldent\Seat\SeatDiscourse\Exceptions\DiscourseGuzzleException */ - public function execute() : Collection + public function execute(): Collection { $client = new Client(); try { $response = $client->request('GET', getenv('DISCOURSE_URL') . '/groups/search.json', [ - 'query' => [ - 'api_key' => getenv('DISCOURSE_API_KEY'), - 'api_username' => getenv('DISCOURSE_API_USERNAME'), - ], + 'headers' => [ + 'api-key' => getenv('DISCOURSE_API_KEY'), + 'api-username' => getenv('DISCOURSE_API_USERNAME'), + ], ]); - if(! $response->getCode() === 200) - throw new Exception($response->getMessage(), $response->getCode()); + if(! $response->getStatusCode() === 200) + throw new Exception($response->getMessage(), $response->getStatusCode()); $body = collect(json_decode($response->getBody()))->reject(function ($item) { return $item->automatic; diff --git a/src/Action/Discourse/Users/GetUserByCharacterId.php b/src/Action/Discourse/Users/GetUserByCharacterId.php index f7f02a9..0b1065d 100644 --- a/src/Action/Discourse/Users/GetUserByCharacterId.php +++ b/src/Action/Discourse/Users/GetUserByCharacterId.php @@ -18,9 +18,9 @@ public function execute(int $id) $client = new Client(); try { $response = $client->request('GET', getenv('DISCOURSE_URL') . '/users/by-external/' . $id . '.json', [ - 'query' => [ - 'api_key' => getenv('DISCOURSE_API_KEY'), - 'api_username' => getenv('DISCOURSE_API_USERNAME'), + 'headers' => [ + 'api-key' => getenv('DISCOURSE_API_KEY'), + 'api-username' => getenv('DISCOURSE_API_USERNAME'), ], ]); diff --git a/src/Action/Discourse/Users/ListUsers.php b/src/Action/Discourse/Users/ListUsers.php index ea03e81..3b4556a 100644 --- a/src/Action/Discourse/Users/ListUsers.php +++ b/src/Action/Discourse/Users/ListUsers.php @@ -22,11 +22,13 @@ public function execute() try { $response = $client->request('GET', getenv('DISCOURSE_URL') . '/admin/users/list/active.json', [ 'query' => [ - 'api_key' => getenv('DISCOURSE_API_KEY'), - 'api_username' => getenv('DISCOURSE_API_USERNAME'), 'order' => 'topics_entered', 'show_emails' => 'true', ], + 'headers' => [ + 'api-key' => getenv('DISCOURSE_API_KEY'), + 'api-username' => getenv('DISCOURSE_API_USERNAME'), + ], ]); return collect(json_decode($response->getBody())); diff --git a/src/Jobs/Logout.php b/src/Jobs/Logout.php index 296b08a..4050e42 100644 --- a/src/Jobs/Logout.php +++ b/src/Jobs/Logout.php @@ -84,9 +84,9 @@ public function handle() try { $response = $this->client->request('POST', getenv('DISCOURSE_URL') . '/admin/users/' . $this->discourse_user_id . '/log_out', [ - 'form_params' => [ - 'api_key' => getenv('DISCOURSE_API_KEY'), - 'api_username' => getenv('DISCOURSE_API_USERNAME'), + 'headers' => [ + 'api-key' => getenv('DISCOURSE_API_KEY'), + 'api-username' => getenv('DISCOURSE_API_USERNAME'), ], ]); @@ -108,9 +108,9 @@ public function beforeStart() $uri = sprintf('%s/users/by-external/%d.json', getenv('DISCOURSE_URL'), $this->main_character->character_id); $response = $this->client->request('GET', $uri, [ - 'query' => [ - 'api_key' => getenv('DISCOURSE_API_KEY'), - 'api_username' => getenv('DISCOURSE_API_USERNAME'), + 'headers' => [ + 'api-key' => getenv('DISCOURSE_API_KEY'), + 'api-username' => getenv('DISCOURSE_API_USERNAME'), ], ]);