-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactors fixer cuurrency api implementation
- Loading branch information
Showing
17 changed files
with
213 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace LaravelEnso\Currencies\APIs\FixerCurrency\Actions; | ||
|
||
use LaravelEnso\Api\Action; | ||
use LaravelEnso\Currencies\APIs\FixerCurrency\Endpoints\Convert as Endpoint; | ||
use LaravelEnso\Currencies\Models\Currency; | ||
|
||
class Convert extends Action | ||
{ | ||
public function __construct( | ||
private Currency $from, | ||
private Currency $to, | ||
private float $amount | ||
) { | ||
} | ||
|
||
protected function endpoint(): Endpoint | ||
{ | ||
return new Endpoint([ | ||
'from' => $this->from->code, | ||
'to' => $this->to->code, | ||
'amount' => $this->amount, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace LaravelEnso\Currencies\APIs\FixerCurrency\Actions; | ||
|
||
use Illuminate\Support\Collection; | ||
use LaravelEnso\Api\Action; | ||
use LaravelEnso\Currencies\Models\Currency; | ||
|
||
abstract class Exchange extends Action | ||
{ | ||
protected Currency $base; | ||
protected Collection $currencies; | ||
|
||
public function __construct(Currency $base, Collection $currencies) | ||
{ | ||
$this->base = $base; | ||
$this->currencies = $currencies; | ||
} | ||
|
||
protected function symbols() | ||
{ | ||
return $this->currencies->map->code->implode(','); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace LaravelEnso\Currencies\APIs\FixerCurrency\Actions; | ||
|
||
use LaravelEnso\Currencies\APIs\FixerCurrency\Endpoints\Rates as Endpoint; | ||
|
||
class Rates extends Exchange | ||
{ | ||
protected function endpoint(): Endpoint | ||
{ | ||
return new Endpoint([ | ||
'base' => $this->base->code, | ||
'symbols' => $this->symbols(), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace LaravelEnso\Currencies\APIs\FixerCurrency\Actions; | ||
|
||
use LaravelEnso\Api\Action; | ||
use LaravelEnso\Currencies\APIs\FixerCurrency\Endpoints\Symbols as Endpoint; | ||
|
||
class Symbols extends Action | ||
{ | ||
protected function endpoint(): Endpoint | ||
{ | ||
return new Endpoint(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace LaravelEnso\Currencies\APIs\FixerCurrency\Endpoints; | ||
|
||
class Convert extends Endpoint | ||
{ | ||
private const Endpoint = 'convert'; | ||
|
||
public function __construct(private array $params) | ||
{ | ||
} | ||
|
||
public function path(): string | ||
{ | ||
return self::Endpoint; | ||
} | ||
|
||
public function params(): array | ||
{ | ||
return $this->params; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace LaravelEnso\Currencies\APIs\FixerCurrency\Endpoints; | ||
|
||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\Config; | ||
use LaravelEnso\Api\Contracts\Endpoint as Contract; | ||
use LaravelEnso\Api\Enums\Methods; | ||
|
||
abstract class Endpoint implements Contract | ||
{ | ||
abstract public function path(): string; | ||
|
||
abstract public function params(): array; | ||
|
||
public function method(): string | ||
{ | ||
return Methods::get; | ||
} | ||
|
||
public function url(): string | ||
{ | ||
$baseUrl = Config::get('enso.currencies.fixerCurrencyApi.host'); | ||
|
||
return Collection::wrap([$baseUrl, $this->path()]) | ||
->filter() | ||
->implode('/'); | ||
} | ||
|
||
public function body(): array | ||
{ | ||
return $this->params() + | ||
['rapidapi-key' => Config::get('enso.currencies.fixerCurrencyApi.key')]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace LaravelEnso\Currencies\APIs\FixerCurrency\Endpoints; | ||
|
||
use Carbon\Carbon; | ||
|
||
class History extends Endpoint | ||
{ | ||
public function __construct( | ||
private array $params, | ||
private Carbon $date | ||
) { | ||
} | ||
|
||
public function path(): string | ||
{ | ||
return $this->date; | ||
} | ||
|
||
public function params(): array | ||
{ | ||
return $this->params; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace LaravelEnso\Currencies\APIs\FixerCurrency\Endpoints; | ||
|
||
class Rates extends Endpoint | ||
{ | ||
private const Endpoint = 'latest'; | ||
|
||
public function __construct(private array $params) | ||
{ | ||
} | ||
|
||
public function path(): string | ||
{ | ||
return self::Endpoint; | ||
} | ||
|
||
public function params(): array | ||
{ | ||
return $this->params; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace LaravelEnso\Currencies\APIs\FixerCurrency\Endpoints; | ||
|
||
class Symbols extends Endpoint | ||
{ | ||
private const Endpoint = 'symbols'; | ||
|
||
public function path(): string | ||
{ | ||
return self::Endpoint; | ||
} | ||
|
||
public function params(): array | ||
{ | ||
return []; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.