laravel-api-externas's People
laravel-api-externas's Issues
Duvidas sobre BaseEndpoint
Fala pia,
Estou tentando implementar essa ideia para uma API que quero consumir no projeto que estou desenvolvendo, mas fiquei com uma dúvida sobre como passar as variáveis de access_token
de um usuário para o método construtor, principalmente por que no BaseEndpoint é sempre chamado novamente o serviço.
Vou colocar meu código:
Comando:
public function handle()
{
$user = User::with(['socialProvider' => function($query) {
$query->where('provider', 'strava');
}])
->find(373);
$token = $user->socialProvider->first();
$service = new StravaService(
$token->provider_access_token,
$token->provider_refresh_token,
$token->provider_expires_at,
$user->id,
$token->provider_user_id,
);
$json = $service->activities()->get();
dd($json);
return Command::SUCCESS;
}
No StravaService
o método construtor:
public function __construct(
private string $accessToken,
private string $refreshToken,
private int $expiresAt,
private int $userId,
private int $providerUserId,
)
{
if (Carbon::now()->timestamp > $this->expiresAt) {
$this->accessToken = $this->refreshTokens();
}
$this->api = Http::withToken($this->accessToken)
->baseUrl('https://www.strava.com/api/v3');
}
Agora minha dúvida é como faço lá no BaseEndpoint, pois ele requer todas as variáveis novamente.
class BaseEndpoint
{
protected StravaService $service;
public function __construct()
{
$this->service = new StravaService(); //Expected 5 arguments
}
protected function transform(mixed $json, string $entity): Collection
{
return collect($json)
->map(fn ($data) => new $entity($data));
}
}
Se conseguir me ajudar, estou meio boiando.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.