Commit a477aad2 authored by Armando Lüscher's avatar Armando Lüscher

Make a few minor adjustments to the date command

parent 96ee5e5e
...@@ -38,7 +38,7 @@ class DateCommand extends UserCommand ...@@ -38,7 +38,7 @@ class DateCommand extends UserCommand
private $client; private $client;
/** /**
* Base URL for Google Maps API * Base URI for Google Maps API
* *
* @var string * @var string
*/ */
...@@ -70,17 +70,17 @@ class DateCommand extends UserCommand ...@@ -70,17 +70,17 @@ class DateCommand extends UserCommand
$path = 'geocode/json'; $path = 'geocode/json';
$query = ['address' => urlencode($location)]; $query = ['address' => urlencode($location)];
if ($this->google_api_key !== '') { if ($this->google_api_key !== null) {
$query['key'] = $this->google_api_key; $query['key'] = $this->google_api_key;
} }
try { try {
$response = $this->client->get($path, ['query' => $query])->getBody(); $response = $this->client->get($path, ['query' => $query]);
} catch (RequestException $e) { } catch (RequestException $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
if (!($result = $this->validateResponseData($response))) { if (!($result = $this->validateResponseData($response->getBody()))) {
return false; return false;
} }
...@@ -113,17 +113,17 @@ class DateCommand extends UserCommand ...@@ -113,17 +113,17 @@ class DateCommand extends UserCommand
'timestamp' => urlencode($timestamp) 'timestamp' => urlencode($timestamp)
]; ];
if ($this->google_api_key !== '') { if ($this->google_api_key !== null) {
$query['key'] = $this->google_api_key; $query['key'] = $this->google_api_key;
} }
try { try {
$response = $this->client->get($path, ['query' => $query])->getBody(); $response = $this->client->get($path, ['query' => $query]);
} catch (RequestException $e) { } catch (RequestException $e) {
throw new TelegramException($e->getMessage()); throw new TelegramException($e->getMessage());
} }
if (!($result = $this->validateResponseData($response))) { if (!($result = $this->validateResponseData($response->getBody()))) {
return false; return false;
} }
...@@ -190,12 +190,13 @@ class DateCommand extends UserCommand ...@@ -190,12 +190,13 @@ class DateCommand extends UserCommand
{ {
//First we set up the necessary member variables. //First we set up the necessary member variables.
$this->client = new Client(['base_uri' => $this->google_api_base_uri]); $this->client = new Client(['base_uri' => $this->google_api_base_uri]);
$this->google_api_key = $this->getConfig('google_api_key'); if (($this->google_api_key = trim($this->getConfig('google_api_key'))) === '') {
$this->google_api_key = null;
}
$message = $this->getMessage(); $message = $this->getMessage();
$chat_id = $message->getChat()->getId(); $chat_id = $message->getChat()->getId();
$message_id = $message->getMessageId();
$location = $message->getText(true); $location = $message->getText(true);
if (empty($location)) { if (empty($location)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment