Skip to content

Commit

Permalink
fix: Removal URL encoding from MetarRetrievalService
Browse files Browse the repository at this point in the history
  • Loading branch information
CalumTowers committed Feb 17, 2025
1 parent 7d32fc3 commit 2ec654c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
11 changes: 10 additions & 1 deletion app/Services/Metar/MetarRetrievalService.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MetarRetrievalService
{
public function retrieveMetars(Collection $airfields): Collection
{
$metarResponse = Http::get(config('metar.vatsim_url'), ['id' => $this->getMetarQueryString($airfields)]);
$metarResponse = Http::get($this->getMetarUrl($airfields));
if (!$metarResponse->ok()) {
Log::error(
sprintf(
Expand All @@ -35,6 +35,15 @@ public function retrieveMetars(Collection $airfields): Collection
})->filter();
}

private function getMetarUrl(Collection $airfields)
{
return sprintf('%s%s%s',
config('metar.vatsim_url'),
"?id=",
$this->getMetarQueryString($airfields)
);
}

private function getMetarQueryString(Collection $airfields): string
{
return $airfields->concat([Carbon::now()->timestamp])->implode(',');
Expand Down
4 changes: 2 additions & 2 deletions tests/app/Services/Metar/MetarRetrievalServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testItThrowsExceptionOnBadResponse()
sprintf(
'%s?id=%s',
config(self::URL_CONFIG_KEY),
urlencode('EGLL,EGBB,EGKR,' . $this->expectedTimestamp)
'EGLL,EGBB,EGKR,' . $this->expectedTimestamp
) => Http::response('', 500),
]
);
Expand All @@ -54,7 +54,7 @@ public function testItReturnsMetars()
sprintf(
'%s?id=%s',
config(self::URL_CONFIG_KEY),
urlencode('EGLL,EGBB,EGKR,' . $this->expectedTimestamp)
'EGLL,EGBB,EGKR,' . $this->expectedTimestamp
) => Http::response(
implode("\n", $dataResponse)
),
Expand Down

0 comments on commit 2ec654c

Please sign in to comment.